|
|
1.1 root 1: \input texinfo @c -*-texinfo-*-
2:
3: @settitle Using and Porting GNU CC
4: @setfilename gcc.info
5:
6: @ifinfo
7: This file documents the use and the internals of the GNU compiler.
8:
9: Copyright (C) 1988 Free Software Foundation, Inc.
10:
11: Permission is granted to make and distribute verbatim copies of
12: this manual provided the copyright notice and this permission notice
13: are preserved on all copies.
14:
15: @ignore
16: Permission is granted to process this file through Tex and print the
17: results, provided the printed document carries copying permission
18: notice identical to this one except for the removal of this paragraph
19: (this paragraph not being relevant to the printed manual).
20:
21: @end ignore
22: Permission is granted to copy and distribute modified versions of this
23: manual under the conditions for verbatim copying, provided also that the
24: section entitled ``GNU CC General Public License'' is included exactly as
25: in the original, and provided that the entire resulting derived work is
26: distributed under the terms of a permission notice identical to this one.
27:
28: Permission is granted to copy and distribute translations of this manual
29: into another language, under the above conditions for modified versions,
30: except that the section entitled ``GNU CC General Public License'' and
31: this permission notice may be included in translations approved by the
32: Free Software Foundation instead of in the original English.
33: @end ifinfo
34:
35: @setchapternewpage odd
36:
37: @titlepage
38: @center @titlefont{Using and Porting GNU CC}
39: @sp 2
40: @center Richard M. Stallman
41: @sp 3
1.1.1.4 ! root 42: @center last updated 21 December 1988
1.1 root 43: @sp 1
1.1.1.4 ! root 44: @center for version 1.32
1.1 root 45: @page
46: @vskip 0pt plus 1filll
47: Copyright @copyright{} 1988 Free Software Foundation, Inc.
48:
49: Permission is granted to make and distribute verbatim copies of
50: this manual provided the copyright notice and this permission notice
51: are preserved on all copies.
52:
53: Permission is granted to copy and distribute modified versions of this
54: manual under the conditions for verbatim copying, provided also that the
55: section entitled ``GNU CC General Public License'' is included exactly as
56: in the original, and provided that the entire resulting derived work is
57: distributed under the terms of a permission notice identical to this one.
58:
59: Permission is granted to copy and distribute translations of this manual
60: into another language, under the above conditions for modified versions,
1.1.1.4 ! root 61: <except that the section entitled ``GNU CC General Public License'' and
1.1 root 62: this permission notice may be included in translations approved by the
63: Free Software Foundation instead of in the original English.
64: @end titlepage
65: @page
66:
67: @ifinfo
68: @node Top, Copying,, (DIR)
69: @ichapter Introduction
70:
71: This manual documents how to run, install and port the GNU C compiler, as
72: well as its new features and incompatibilities, and how to report bugs.
73:
74: @end ifinfo
75: @menu
76: * Copying:: GNU CC General Public License says
77: how you can copy and share GNU CC.
78: * Contributors:: People who have contributed to GNU CC.
79: * Options:: Command options supported by @samp{gcc}.
80: * Installation:: How to configure, compile and install GNU CC.
81: * Trouble:: If you have trouble installing GNU CC.
82: * Incompatibilities:: Incompatibilities of GNU CC.
83: * Extensions:: GNU extensions to the C language.
84: * Bugs:: How to report bugs (if you want to get them fixed).
85: * Portability:: Goals of GNU CC's portability features.
86: * Interface:: Function-call interface of GNU CC output.
87: * Passes:: Order of passes, what they do, and what each file is for.
88: * RTL:: The intermediate representation that most passes work on.
89: * Machine Desc:: How to write machine description instruction patterns.
90: * Machine Macros:: How to write the machine description C macros.
91: @end menu
92:
93: @node Copying, Contributors, Top, Top
94: @unnumbered GNU CC GENERAL PUBLIC LICENSE
95: @center (Clarified 11 Feb 1988)
96:
97: The license agreements of most software companies keep you at the
98: mercy of those companies. By contrast, our general public license is
99: intended to give everyone the right to share GNU CC. To make sure that
100: you get the rights we want you to have, we need to make restrictions
101: that forbid anyone to deny you these rights or to ask you to surrender
102: the rights. Hence this license agreement.
103:
104: Specifically, we want to make sure that you have the right to give
105: away copies of GNU CC, that you receive source code or else can get it
106: if you want it, that you can change GNU CC or use pieces of it in new
107: free programs, and that you know you can do these things.
108:
109: To make sure that everyone has such rights, we have to forbid you to
110: deprive anyone else of these rights. For example, if you distribute
111: copies of GNU CC, you must give the recipients all the rights that you
112: have. You must make sure that they, too, receive or can get the
113: source code. And you must tell them their rights.
114:
115: Also, for our own protection, we must make certain that everyone
116: finds out that there is no warranty for GNU CC. If GNU CC is modified by
117: someone else and passed on, we want its recipients to know that what
118: they have is not what we distributed, so that any problems introduced
119: by others will not reflect on our reputation.
120:
121: Therefore we (Richard Stallman and the Free Software Foundation,
122: Inc.) make the following terms which say what you must do to be
123: allowed to distribute or change GNU CC.
124:
125: @unnumberedsec COPYING POLICIES
126:
127: @enumerate
128: @item
129: You may copy and distribute verbatim copies of GNU CC source code as
130: you receive it, in any medium, provided that you conspicuously and
131: appropriately publish on each copy a valid copyright notice
132: ``Copyright @copyright{} 1988 Free Software Foundation, Inc.'' (or
133: with whatever year is appropriate); keep intact the notices on all
134: files that refer to this License Agreement and to the absence of any
135: warranty; and give any other recipients of the GNU CC program a copy
136: of this License Agreement along with the program. You may charge a
137: distribution fee for the physical act of transferring a copy.
138:
139: @item
140: You may modify your copy or copies of GNU CC or any portion of it,
141: and copy and distribute such modifications under the terms of
142: Paragraph 1 above, provided that you also do the following:
143:
144: @itemize @bullet
145: @item
146: cause the modified files to carry prominent notices stating
147: that you changed the files and the date of any change; and
148:
149: @item
150: cause the whole of any work that you distribute or publish, that
151: in whole or in part contains or is a derivative of GNU CC or any
152: part thereof, to be licensed at no charge to all third parties on
153: terms identical to those contained in this License Agreement
154: (except that you may choose to grant more extensive warranty
155: protection to some or all third parties, at your option).
156:
157: @item
158: You may charge a distribution fee for the physical act of
159: transferring a copy, and you may at your option offer warranty
160: protection in exchange for a fee.
161: @end itemize
162:
163: Mere aggregation of another unrelated program with this program (or its
164: derivative) on a volume of a storage or distribution medium does not bring
165: the other program under the scope of these terms.
166:
167: @item
168: You may copy and distribute GNU CC (or a portion or derivative of it,
169: under Paragraph 2) in object code or executable form under the terms
170: of Paragraphs 1 and 2 above provided that you also do one of the
171: following:
172:
173: @itemize @bullet
174: @item
175: accompany it with the complete corresponding machine-readable
176: source code, which must be distributed under the terms of
177: Paragraphs 1 and 2 above; or,
178:
179: @item
180: accompany it with a written offer, valid for at least three
181: years, to give any third party free (except for a nominal
182: shipping charge) a complete machine-readable copy of the
183: corresponding source code, to be distributed under the terms of
184: Paragraphs 1 and 2 above; or,
185:
186: @item
187: accompany it with the information you received as to where the
188: corresponding source code may be obtained. (This alternative is
189: allowed only for noncommercial distribution and only if you
190: received the program in object code or executable form alone.)
191: @end itemize
192:
193: For an executable file, complete source code means all the source code
194: for all modules it contains; but, as a special exception, it need not
195: include source code for modules which are standard libraries that
196: accompany the operating system on which the executable file runs.
197:
198: @item
199: You may not copy, sublicense, distribute or transfer GNU CC except as
200: expressly provided under this License Agreement. Any attempt
201: otherwise to copy, sublicense, distribute or transfer GNU CC is void
202: and your rights to use the program under this License agreement shall
203: be automatically terminated. However, parties who have received
204: computer software programs from you with this License Agreement will
205: not have their licenses terminated so long as such parties remain in
206: full compliance.
207:
208: @item
209: If you wish to incorporate parts of GNU CC into other free programs
210: whose distribution conditions are different, write to the Free Software
211: Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet worked
212: out a simple rule that can be stated here, but we will often permit this.
213: We will be guided by the two goals of preserving the free status of all
214: derivatives of our free software and of promoting the sharing and reuse of
215: software.
216: @end enumerate
217:
218: Your comments and suggestions about our licensing policies and our
219: software are welcome! Please contact the Free Software Foundation, Inc.,
220: 675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
221:
222: @unnumberedsec NO WARRANTY
223:
224: BECAUSE GNU CC IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO
225: WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
226: WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
227: RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE GNU CC "AS IS" WITHOUT
228: WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
229: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
230: A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
231: PERFORMANCE OF GNU CC IS WITH YOU. SHOULD GNU CC PROVE DEFECTIVE, YOU
232: ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
233:
234: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
235: STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
236: WHO MAY MODIFY AND REDISTRIBUTE GNU CC AS PERMITTED ABOVE, BE LIABLE TO
237: YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER
238: SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
239: INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
240: BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
241: FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GNU CC, EVEN
242: IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR
243: ANY CLAIM BY ANY OTHER PARTY.
244:
245: @node Contributors, Options, Copying, Top
246: @unnumbered Contributors to GNU CC
247:
248: In addition to Richard Stallman, several people have written parts
249: of GNU CC.
250:
251: @itemize @bullet
252: @item
253: The idea of using RTL and some of the optimization ideas came from the
254: U. of Arizona Portable Optimizer, written by Jack Davidson and
255: Christopher Fraser. See ``Register Allocation and Exhaustive Peephole
256: Optimization'', Software Practice and Experience 14 (9), Sept. 1984,
257: 857-866.
258:
259: @item
260: Paul Rubin wrote most of the preprocessor.
261:
262: @item
263: Leonard Tower wrote parts of the parser, RTL generator, RTL
264: definitions, and of the Vax machine description.
265:
266: @item
267: Ted Lemon wrote parts of the RTL reader and printer.
268:
269: @item
270: Jim Wilson implemented loop strength reduction and some other
271: loop optimizations.
272:
273: @item
274: Nobuyuki Hikichi of Software Research Associates, Tokyo, contributed
275: the support for the SONY NEWS machine.
276:
277: @item
278: Charles LaBrec contributed the support for the Integrated Solutions
279: 68020 system.
280:
281: @item
282: Michael Tiemann of MCC wrote most of the description of the National
283: Semiconductor 32000 series cpu. He also wrote the code for inline
284: function integration and for the SPARC cpu and Motorola 88000 cpu
285: and part of the Sun FPA support.
286:
287: @item
288: Jan Stein of the Chalmers Computer Society provided support for
289: Genix, as well as part of the 32000 machine description.
290:
291: @item
292: Randy Smith finished the Sun FPA support.
293:
294: @item
295: Robert Brown implemented the support for Encore 32000 systems.
296:
297: @item
298: David Kashtan of SRI adapted GNU CC to the Vomit-Making System.
299:
300: @item
301: Alex Crain provided changes for the 3b1.
302:
303: @item
304: Greg Satz and Chris Hanson assisted in making GNU CC work on HP-UX for
305: the 9000 series 300.
306:
307: @item
308: William Schelter did most of the work on the Intel 80386 support.
309: @end itemize
310:
311: @node Options, Installation, Contributors, Top
312: @chapter GNU CC Command Options
313:
314: The GNU C compiler uses a command syntax much like the Unix C compiler.
315: The @code{gcc} program accepts options and file names as operands.
316: Multiple single-letter options may @emph{not} be grouped: @samp{-dr} is
317: very different from @samp{-d -r}.
318:
319: When you invoke GNU CC, it normally does preprocessing, compilation,
320: assembly and linking. File names which end in @samp{.c} are taken as C
321: source to be preprocessed and compiled; compiler output files plus any
322: input files with names ending in @samp{.s} are assembled; then the
323: resulting object files, plus any other input files, are linked together to
324: produce an executable.
325:
326: Command options allow you to stop this process at an intermediate stage.
327: For example, the @samp{-c} option says not to run the linker. Then the
328: output consists of object files output by the assembler.
329:
330: Other command options are passed on to one stage. Some options control
331: the preprocessor and others the compiler itself. Yet other options
332: control the assembler and linker; these are not documented here because the
333: GNU assembler and linker are not yet released.
334:
335: Here are the options to control the overall compilation process, including
336: those that say whether to link, whether to assemble, and so on.
337:
338: @table @samp
339: @item -o @var{file}
340: Place output in file @var{file}. This applies regardless to whatever
341: sort of output is being produced, whether it be an executable file,
342: an object file, an assembler file or preprocessed C code.
343:
344: If @samp{-o} is not specified, the default is to put an executable file
345: in @file{a.out}, the object file @file{@var{source}.c} in
346: @file{@var{source}.o}, an assembler file in @file{@var{source}.s}, and
347: preprocessed C on standard output.@refill
348:
349: @item -c
350: Compile or assemble the source files, but do not link. Produce object
351: files with names made by replacing @samp{.c} or @samp{.s} with
352: @samp{.o} at the end of the input file names. Do nothing at all for
353: object files specified as input.
354:
355: @item -S
356: Compile into assembler code but do not assemble. The assembler output
357: file name is made by replacing @samp{.c} with @samp{.s} at the end of
358: the input file name. Do nothing at all for assembler source files or
359: object files specified as input.
360:
361: @item -E
362: Run only the C preprocessor. Preprocess all the C source files
363: specified and output the results to standard output.
364:
365: @item -v
366: Compiler driver program prints the commands it executes as it runs
367: the preprocessor, compiler proper, assembler and linker. Some of
368: these are directed to print their own version numbers.
369:
370: @item -B@var{prefix}
371: Compiler driver program tries @var{prefix} as a prefix for each
372: program it tries to run. These programs are @file{cpp}, @file{cc1},
373: @file{as} and @file{ld}.
374:
375: For each subprogram to be run, the compiler driver first tries the
376: @samp{-B} prefix, if any. If that name is not found, or if @samp{-B}
377: was not specified, the driver tries two standard prefixes, which are
378: @file{/usr/lib/gcc-} and @file{/usr/local/lib/gcc-}. If neither of
379: those results in a file name that is found, the unmodified program
380: name is searched for using the directories specified in your
381: @samp{PATH} environment variable.
382:
383: The run-time support file @file{gnulib} is also searched for using
384: the @samp{-B} prefix, if needed. If it is not found there, the two
385: standard prefixes above are tried, and that is all. The file is left
386: out of the link if it is not found by those means. Most of the time,
387: on most machines, you can do without it.
388: @end table
389:
390: These options control the details of C compilation itself.
391:
392: @table @samp
393: @item -ansi
394: Support all ANSI standard C programs.
395:
396: This turns off certain features of GNU C that are incompatible with
397: ANSI C, such as the @code{asm}, @code{inline} and @code{typeof}
398: keywords, and predefined macros such as @code{unix} and @code{vax}
399: that identify the type of system you are using. It also enables the
400: undesirable and rarely used ANSI trigraph feature.
401:
402: The @samp{-ansi} option does not cause non-ANSI programs to be
403: rejected gratuitously. For that, @samp{-pedantic} is required in
404: addition to @samp{-ansi}.
405:
406: The macro @code{__STRICT_ANSI__} is predefined when the @samp{-ansi}
407: option is used. Some header files may notice this macro and refrain
408: from declaring certain functions or defining certain macros that the
409: ANSI standard doesn't call for; this is to avoid interfering with
410: any programs that might use these names for other things.
411:
412: @item -traditional
413: Attempt to support some aspects of traditional C compilers.
414: Specifically:
415:
416: @itemize @bullet
417: @item
418: All @code{extern} declarations take effect globally even if they
419: are written inside of a function definition. This includes implicit
420: declarations of functions.
421:
422: @item
423: The keywords @code{typeof}, @code{inline}, @code{signed}, @code{const}
424: and @code{volatile} are not recognized.@refill
425:
426: @item
427: Comparisons between pointers and integers are always allowed.
428:
429: @item
430: Integer types @code{unsigned short} and @code{unsigned char} promote
431: to @code{unsigned int}.
432:
433: @item
434: Out-of-range floating point literals are not an error.
435:
436: @item
1.1.1.2 root 437: All automatic variables not declared @code{register} are preserved by
438: @code{longjmp}. Ordinarily, GNU C follows ANSI C: automatic variables
439: not declared @code{volatile} may be clobbered.
440:
441: @item
1.1 root 442: In the preprocessor, comments convert to nothing at all, rather than
443: to a space. This allows traditional token concatenation.
444:
445: @item
446: In the preprocessor, macro arguments are recognized within string
447: constants in a macro definition (and their values are stringified,
448: though without additional quote marks, when they appear in such a
449: context). The preprocessor always considers a string constant to end
450: at a newline.
451:
452: @item
453: The predefined macro @code{__STDC__} is not defined when you use
454: @samp{-traditional}, but @code{__GNUC__} is (since the GNU extensions
455: which @code{__GNUC__} indicates are not affected by
456: @samp{-traditional}). If you need to write header files that work
457: differently depending on whether @samp{-traditional} is in use, by
458: testing both of these predefined macros you can distinguish four
459: situations: GNU C, traditional GNU C, other ANSI C compilers, and
460: other old C compilers.
461: @end itemize
462:
463: @item -O
464: Optimize. Optimizing compilation takes somewhat more time, and a lot
465: more memory for a large function.
466:
467: Without @samp{-O}, the compiler's goal is to reduce the cost of
468: compilation and to make debugging produce the expected results.
469: Statements are independent: if you stop the program with a breakpoint
470: between statements, you can then assign a new value to any variable or
471: change the program counter to any other statement in the function and
472: get exactly the results you would expect from the source code.
473:
474: Without @samp{-O}, only variables declared @code{register} are
475: allocated in registers. The resulting compiled code is a little worse
476: than produced by PCC without @samp{-O}.
477:
478: With @samp{-O}, the compiler tries to reduce code size and execution
479: time.
480:
481: Some of the @samp{-f} options described below turn specific kinds of
482: optimization on or off.
483:
484: @item -g
485: Produce debugging information in the operating system's native format
486: (for DBX or SDB). GDB also can work with this debugging information.
487:
488: Unlike most other C compilers, GNU CC allows you to use @samp{-g} with
489: @samp{-O}. The shortcuts taken by optimized code may occasionally
490: produce surprising results: some variables you declared may not exist
491: at all; flow of control may briefly move where you did not expect it;
492: some statements may not be executed because they compute constant
493: results or their values were already at hand; some statements may
494: execute in different places because they were moved out of loops.
495: Nevertheless it proves possible to debug optimized output. This makes
496: it reasonable to use the optimizer for programs that might have bugs.
497:
498: @item -gg
499: Produce debugging information in GDB's own format. This requires the
500: GNU assembler and linker in order to work.
501:
502: This feature will probably be eliminated. It was intended to enable
503: GDB to read the symbol table faster, but it doesn't result in enough
504: of a speedup to be worth the larger object files and executables. We
1.1.1.2 root 505: are working on other ways of making GDB start even faster, which work
506: with DBX format debugging information and could be made to work with
507: SDB format.
1.1 root 508:
509: @item -w
510: Inhibit all warning messages.
511:
512: @item -W
513: Print extra warning messages for these events:
514:
515: @itemize @bullet
516: @item
517: An automatic variable is used without first being initialized.
518:
519: These warnings are possible only in optimizing compilation,
520: because they require data flow information that is computed only
521: when optimizing. They occur only for variables that are
522: candidates for register allocation. Therefore, they do not occur
523: for a variable that is declared @code{volatile}, or whose address
524: is taken, or whose size is other than 1, 2, 4 or 8 bytes. Also,
525: they do not occur for structures, unions or arrays, even when
526: they are in registers.
527:
528: Note that there may be no warning about a variable that is used
529: only to compute a value that itself is never used, because such
530: computations may be deleted by the flow analysis pass before the
531: warnings are printed.
532:
533: These warnings are made optional because GNU CC is not smart
534: enough to see all the reasons why the code might be correct
535: despite appearing to have an error. Here is one example of how
536: this can happen:
537:
538: @example
539: @{
540: int x;
541: switch (y)
542: @{
543: case 1: x = 1;
544: break;
545: case 2: x = 4;
546: break;
547: case 3: x = 5;
548: @}
549: foo (x);
550: @}
551: @end example
552:
553: @noindent
554: If the value of @code{y} is always 1, 2 or 3, then @code{x} is
555: always initialized, but GNU CC doesn't know this. Here is
556: another common case:
557:
558: @example
559: @{
560: int save_y;
561: if (change_y) save_y = y, y = new_y;
562: @dots{}
563: if (change_y) y = save_y;
564: @}
565: @end example
566:
567: @noindent
568: This has no bug because @code{save_y} is used only if it is set.
569:
570: @item
571: A nonvolatile automatic variable might be changed by a call to
572: @code{longjmp}. These warnings as well are possible only in
573: optimizing compilation.
574:
575: The compiler sees only the calls to @code{setjmp}. It cannot know
576: where @code{longjmp} will be called; in fact, a signal handler could
577: call it at any point in the code. As a result, you may get a warning
578: even when there is in fact no problem because @code{longjmp} cannot
579: in fact be called at the place which would cause a problem.
580:
581: @item
582: A function can return either with or without a value. (Falling
583: off the end of the function body is considered returning without
584: a value.) For example, this function would inspire such a
585: warning:
586:
587: @example
588: foo (a)
589: @{
590: if (a > 0)
591: return a;
592: @}
593: @end example
594:
595: Spurious warnings can occur because GNU CC does not realize that
596: certain functions (including @code{abort} and @code{longjmp})
597: will never return.
1.1.1.4 ! root 598:
! 599: @item
! 600: An expression-statement contains no side effects.
1.1 root 601: @end itemize
602:
603: In the future, other useful warnings may also be enabled by this
604: option.
605:
606: @item -Wimplicit
607: Warn whenever a function is implicitly declared.
608:
609: @item -Wreturn-type
610: Warn whenever a function is defined with a return-type that defaults
611: to @code{int}. Also warn about any @code{return} statement with no
612: return-value in a function whose return-type is not @code{void}.
613:
614: @item -Wunused
615: Warn whenever a local variable is unused aside from its declaration.
616:
617: @item -Wcomment
618: Warn whenever a comment-start sequence @samp{/*} appears in a comment.
619:
620: @item -Wall
621: All of the above @samp{-W} options combined.
622:
623: @item -Wwrite-strings
624: Give string constants the type @code{const char[@var{length}]} so that
625: copying the address of one into a non-@code{const} @code{char *}
626: pointer will get a warning. These warnings will help you find at
627: compile time code that can try to write into a string constant, but
628: only if you have been very careful about using @code{const} in
629: declarations and prototypes. Otherwise, it will just be a nuisance;
630: this is why we did not make @samp{-Wall} request these warnings.
631:
632: @item -p
633: Generate extra code to write profile information suitable for the
634: analysis program @code{prof}.
635:
636: @item -pg
637: Generate extra code to write profile information suitable for the
638: analysis program @code{gprof}.
639:
640: @item -l@var{library}
641: Search a standard list of directories for a library named
642: @var{library}, which is actually a file named
643: @file{lib@var{library}.a}. The linker uses this file as if it
644: had been specified precisely by name.
645:
646: The directories searched include several standard system directories
647: plus any that you specify with @samp{-L}.
648:
649: Normally the files found this way are library files---archive files
650: whose members are object files. The linker handles an archive file by
651: scanning through it for members which define symbols that have so far
652: been referenced but not defined. But if the file that is found is an
653: ordinary object file, it is linked in the usual fashion. The only
654: difference between using an @samp{-l} option and specifying a file name
655: is that @samp{-l} searches several directories.
656:
657: @item -L@var{dir}
658: Add directory @var{dir} to the list of directories to be searched
659: for @samp{-l}.
660:
661: @item -nostdlib
662: Don't use the standard system libraries and startup files when
663: linking. Only the files you specify (plus @file{gnulib}) will be
664: passed to the linker.
665:
666: @item -m@var{machinespec}
667: Machine-dependent option specifying something about the type of target
668: machine. These options are defined by the macro
669: @code{TARGET_SWITCHES} in the machine description. The default for
670: the options is also defined by that macro, which enables you to change
671: the defaults.@refill
672:
673: These are the @samp{-m} options defined in the 68000 machine
674: description:
675:
676: @table @samp
677: @item -m68020
678: @itemx -mc68020
679: Generate output for a 68020 (rather than a 68000). This is the
680: default if you use the unmodified sources.
681:
682: @item -m68000
683: @item -mc68000
684: Generate output for a 68000 (rather than a 68020).
685:
686: @item -m68881
687: Generate output containing 68881 instructions for floating point.
688: This is the default if you use the unmodified sources.
689:
690: @item -mfpa
691: Generate output containing Sun FPA instructions for floating point.
692:
693: @item -msoft-float
694: Generate output containing library calls for floating point.
695:
696: @item -mshort
697: Consider type @code{int} to be 16 bits wide, like @code{short int}.
698:
699: @item -mnobitfield
700: Do not use the bit-field instructions. @samp{-m68000} implies
701: @samp{-mnobitfield}.
702:
703: @item -mbitfield
704: Do use the bit-field instructions. @samp{-m68020} implies
705: @samp{-mbitfield}. This is the default if you use the unmodified
706: sources.
707:
708: @item -mrtd
709: Use a different function-calling convention, in which functions
710: that take a fixed number of arguments return with the @code{rtd}
711: instruction, which pops their arguments while returning. This
712: saves one instruction in the caller since there is no need to pop
713: the arguments there.
714:
715: This calling convention is incompatible with the one normally
716: used on Unix, so you cannot use it if you need to call libraries
717: compiled with the Unix compiler.
718:
719: Also, you must provide function prototypes for all functions that
720: take variable numbers of arguments (including @code{printf});
721: otherwise incorrect code will be generated for calls to those
722: functions.
723:
724: In addition, seriously incorrect code will result if you call a
725: function with too many arguments. (Normally, extra arguments are
726: harmlessly ignored.)
727:
728: The @code{rtd} instruction is supported by the 68010 and 68020
729: processors, but not by the 68000.
730: @end table
731:
732: These @samp{-m} options are defined in the Vax machine description:
733:
734: @table @samp
735: @item -munix
736: Do not output certain jump instructions (@code{aobleq} and so on)
737: that the Unix assembler for the Vax cannot handle across long
738: ranges.
739:
740: @item -mgnu
741: Do output those jump instructions, on the assumption that you
742: will assemble with the GNU assembler.
743:
744: @item -mg
745: Output code for g-format floating point numbers instead of d-format.
746: @end table
747:
748: @item -f@var{flag}
1.1.1.4 ! root 749: Specify machine-independent flags. Most flags have both positive and
! 750: negative forms; the negative form of @samp{-ffoo} would be
! 751: @samp{-fno-foo}. In the table below, only one of the forms is
! 752: listed---the one which is not the default. You can figure out the
! 753: other form by either removing @samp{no-} or adding it.
1.1 root 754:
755: @table @samp
756: @item -ffloat-store
757: Do not store floating-point variables in registers. This
758: prevents undesirable excess precision on machines such as the
759: 68000 where the floating registers (of the 68881) keep more
760: precision than a @code{double} is supposed to have.
761:
762: For most programs, the excess precision does only good, but a few
763: programs rely on the precise definition of IEEE floating point.
764: Use @samp{-ffloat-store} for such programs.
765:
766: @item -fno-asm
767: Do not recognize @code{asm}, @code{inline} or @code{typeof} as a
768: keyword. These words may then be used as identifiers.
769:
770: @item -fno-defer-pop
771: Always pop the arguments to each function call as soon as that
772: function returns. Normally the compiler (when optimizing) lets
773: arguments accumulate on the stack for several function calls and
774: pops them all at once.
775:
776: @item -fstrength-reduce
777: Perform the optimizations of loop strength reduction and
778: elimination of iteration variables.
779:
780: @item -fcombine-regs
781: Allow the combine pass to combine an instruction that copies one
782: register into another. This might or might not produce better
783: code when used in addition to @samp{-O}. I am interested in
784: hearing about the difference this makes.
785:
786: @item -fforce-mem
787: Force memory operands to be copied into registers before doing
788: arithmetic on them. This may produce better code by making all
789: memory references potential common subexpressions. When they are
790: not common subexpressions, instruction combination should
791: eliminate the separate register-load. I am interested in hearing
792: about the difference this makes.
793:
794: @item -fforce-addr
795: Force memory address constants to be copied into registers before
796: doing arithmetic on them. This may produce better code just as
797: @samp{-fforce-mem} may. I am interested in hearing about the
798: difference this makes.
799:
800: @item -fomit-frame-pointer
801: Don't keep the frame pointer in a register for functions that
802: don't need one. This avoids the instructions to save, set up and
803: restore frame pointers; it also makes an extra register available
804: in many functions. @strong{It also makes debugging impossible.}
805:
806: On some machines, such as the Vax, this flag has no effect,
807: because the standard calling sequence automatically handles the
808: frame pointer and nothing is saved by pretending it doesn't
809: exist. The machine-description macro
810: @code{FRAME_POINTER_REQUIRED} controls whether a target machine
811: supports this flag. @xref{Registers}.@refill
812:
813: @item -finline-functions
814: Integrate all simple functions into their callers. The compiler
815: heuristically decides which functions are simple enough to be
816: worth integrating in this way.
817:
818: If all calls to a given function are integrated, and the function
819: is declared @code{static}, then the function is normally not
820: output as assembler code in its own right.
821:
822: @item -fkeep-inline-functions
823: Even if all calls to a given function are integrated, and the
824: function is declared @code{static}, nevertheless output a
825: separate run-time callable version of the function.
826:
827: @item -fwritable-strings
828: Store string constants in the writable data segment and don't
829: uniquize them. This is for compatibility with old programs which
830: assume they can write into string constants. Writing into string
831: constants is a very bad idea; ``constants'' should be constant.
832:
1.1.1.4 ! root 833: @item -fcond-mismatch
! 834: Allow conditional expressions with mismatched types in the second and
! 835: third arguments. The value of such an expression is void.
! 836:
1.1 root 837: @item -fno-function-cse
838: Do not put function addresses in registers; make each instruction
839: that calls a constant function contain the function's address
840: explicitly.
841:
842: This option results in less efficient code, but some strange
843: hacks that alter the assembler output may be confused by the
844: optimizations performed when this option is not used.
845:
846: @item -fvolatile
847: Consider all memory references through pointers to be volatile.
848:
1.1.1.4 ! root 849: @item -fshared-data
! 850: Requests that the data and non-@code{const} variables of this
! 851: compilation be shared data rather than private data. The distinction
! 852: makes sense only on certain operating systems, where shared data is
! 853: shared between processes running the same program, while private data
! 854: exists in one copy per process.
! 855:
1.1 root 856: @item -funsigned-char
1.1.1.4 ! root 857: Let the type @code{char} be the unsigned, like @code{unsigned char}.
1.1 root 858:
859: Each kind of machine has a default for what @code{char} should
860: be. It is either like @code{unsigned char} by default or like
861: @code{signed char} by default. (Actually, at present, the
862: default is always signed.)
863:
864: The type @code{char} is always a distinct type from either
865: @code{signed char} or @code{unsigned char}, even though its
866: behavior is always just like one of those two.
867:
1.1.1.4 ! root 868: Note that this is equivalent to @samp{-fno-signed-char}, which is the
! 869: negative form of @samp{-fsigned-char}.
! 870:
1.1 root 871: @item -fsigned-char
872: Let the type @code{char} be signed, like @code{signed char}.
873:
1.1.1.4 ! root 874: Note that this is equivalent to @samp{-fno-unsigned-char}, which is
! 875: the negative form of @samp{-funsigned-char}.
! 876:
1.1 root 877: @item -ffixed-@var{reg}
878: Treat the register named @var{reg} as a fixed register; generated
879: code should never refer to it (except perhaps as a stack pointer,
880: frame pointer or in some other fixed role).
881:
882: @var{reg} must be the name of a register. The register names
883: accepted are machine-specific and are defined in the
884: @code{REGISTER_NAMES} macro in the machine description macro
885: file.
886:
1.1.1.4 ! root 887: This flag does not have a negative form, because it specifies a
! 888: three-way choice.
! 889:
1.1 root 890: @item -fcall-used-@var{reg}
891: Treat the register named @var{reg} as an allocatable register
892: that is clobbered by function calls. It may be allocated for
893: temporaries or variables that do not live across a call.
894: Functions compiled this way will not save and restore the
895: register @var{reg}.
896:
897: Use of this flag for a register that has a fixed pervasive role
898: in the machine's execution model, such as the stack pointer or
899: frame pointer, will produce disastrous results.
900:
1.1.1.4 ! root 901: This flag does not have a negative form, because it specifies a
! 902: three-way choice.
! 903:
1.1 root 904: @item -fcall-saved-@var{reg}
905: Treat the register named @var{reg} as an allocatable register
906: saved by functions. It may be allocated even for temporaries or
907: variables that live across a call. Functions compiled this way
908: will save and restore the register @var{reg} if they use it.
909:
910: Use of this flag for a register that has a fixed pervasive role
911: in the machine's execution model, such as the stack pointer or
912: frame pointer, will produce disastrous results.
913:
914: A different sort of disaster will result from the use of this
915: flag for a register in which function values may be returned.
1.1.1.4 ! root 916:
! 917: This flag does not have a negative form, because it specifies a
! 918: three-way choice.
1.1 root 919: @end table
920:
921: @item -d@var{letters}
922: Says to make debugging dumps at times specified by @var{letters}.
923: Here are the possible letters:
924:
925: @table @samp
926: @item r
927: Dump after RTL generation.
928: @item j
929: Dump after first jump optimization.
930: @item J
931: Dump after last jump optimization.
932: @item s
933: Dump after CSE (including the jump optimization that sometimes
934: follows CSE).
935: @item L
936: Dump after loop optimization.
937: @item f
938: Dump after flow analysis.
939: @item c
940: Dump after instruction combination.
941: @item l
942: Dump after local register allocation.
943: @item g
944: Dump after global register allocation.
945: @item m
946: Print statistics on memory usage, at the end of the run.
947: @end table
948:
949: @item -pedantic
950: Issue all the warnings demanded by strict ANSI standard C; reject
951: all programs that use forbidden extensions.
952:
953: Valid ANSI standard C programs should compile properly with or without
954: this option (though a rare few will require @samp{-ansi}). However,
955: without this option, certain GNU extensions and traditional C features
956: are supported as well. With this option, they are rejected. There is
957: no reason to @i{use} this option; it exists only to satisfy pedants.
958: @end table
959:
960: These options control the C preprocessor, which is run on each C source
961: file before actual compilation. If you use the @samp{-E} option, nothing
962: is done except C preprocessing. Some of these options make sense only
963: together with @samp{-E} because they request preprocessor output that is
964: not suitable for actual compilation.
965:
966: @table @samp
967: @item -C
968: Tell the preprocessor not to discard comments. Used with the
969: @samp{-E} option.
970:
971: @item -I@var{dir}
972: Search directory @var{dir} for include files.
973:
974: @item -I-
975: Any directories specified with @samp{-I} options before the @samp{-I-}
976: option are searched only for the case of @samp{#include "@var{file}"};
977: they are not searched for @samp{#include <@var{file}>}.
978:
979: If additional directories are specified with @samp{-I} options after
980: the @samp{-I-}, these directories are searched for all @samp{#include}
981: directives. (Ordinarily @emph{all} @samp{-I} directories are used
982: this way.)
983:
984: In addition, the @samp{-I-} option inhibits the use of the current
985: directory as the first search directory for @samp{#include
986: "@var{file}"}. Therefore, the current directory is searched only if
987: it is requested explicitly with @samp{-I.}. Specifying both
988: @samp{-I-} and @samp{-I.} allows you to control precisely which
989: directories are searched before the current one and which are searched
990: after.
991:
992: @item -nostdinc
993: Do not search the standard system directories for header files. Only
994: the directories you have specified with @samp{-I} options (and the
995: current directory, if appropriate) are searched.
996:
997: Between @samp{-nostdinc} and @samp{-I-}, you can eliminate all
998: directories from the search path except those you specify.
999:
1000: @item -M
1001: Tell the preprocessor to output a rule suitable for @code{make}
1002: describing the dependencies of each source file. For each source
1003: file, the preprocessor outputs one @code{make}-rule whose target is
1004: the object file name for that source file and whose dependencies are
1005: all the files @samp{#include}d in it. This rule may be a single line
1006: or may be continued with @samp{\}-newline if it is long.
1007:
1008: @samp{-M} implies @samp{-E}.
1009:
1010: @item -MM
1011: Like @samp{-M} but the output mentions only the user-header files
1012: included with @samp{#include "@var{file}"}. System header files
1013: included with @samp{#include <@var{file}>} are omitted.
1014:
1015: @samp{-MM} implies @samp{-E}.
1016:
1017: @item -D@var{macro}
1018: Define macro @var{macro} with the empty string as its definition.
1019:
1020: @item -D@var{macro}=@var{defn}
1021: Define macro @var{macro} as @var{defn}.
1022:
1023: @item -U@var{macro}
1024: Undefine macro @var{macro}.
1025:
1026: @item -T
1027: Support ANSI C trigraphs. You don't want to know about this
1028: brain-damage. The @samp{-ansi} option also has this effect.
1029: @end table
1030:
1031: @node Installation, Trouble, Options, Top
1032: @chapter Installing GNU CC
1033:
1034: Here is the procedure for installing GNU CC on a Unix system.
1035: @menu
1036: * VMS Install:: See below for installation on VMS.
1037: @end menu
1038: @iftex
1039: (See below for VMS.)
1040: @end iftex
1041:
1042: @enumerate
1043: @item
1044: Edit @file{Makefile}. If you are using HPUX, or any form of system V,
1045: you must make a few changes described in comments at the beginning of
1.1.1.4 ! root 1046: the file. Genix requires changes also.
1.1 root 1047:
1048: @item
1049: On a Sequent system, go to the Berkeley universe.
1050:
1051: @item
1.1.1.2 root 1052: Choose configuration files. The easy way to do this is to run the
1053: command file @file{config.gcc} with a single argument, which is the
1.1.1.4 ! root 1054: name of the machine (and operating system, in some cases).
! 1055:
! 1056: Here is a list of the possible arguments:
! 1057:
! 1058: @table @samp
! 1059: @item vax
! 1060: Vaxes running BSD.
! 1061: @item vms
! 1062: Vaxes running VMS.
! 1063: @item vax-sysv
! 1064: Vaxes running system V.
! 1065: @item i386-sysv
! 1066: Intel 386 PCs running system V.
! 1067: @item sequent-386
! 1068: Sequent with Intel 386 processors.
! 1069: @item sun2
! 1070: Sun 2 running system version 2 or 3.
! 1071: @item sun3
! 1072: Sun 3 running system version 2 or 3.
! 1073: @item sun4
! 1074: Sun 4 running system version 2 or 3.
! 1075: @item sun2-os4
! 1076: Sun 2 running system version 4.
! 1077: @item sun3-os4
! 1078: Sun 3 running system version 4.
! 1079: @item sun4-os4
! 1080: Sun 4 running system version 4.
! 1081: @item sun386
! 1082: Sun 386 (``roadrunner'').
! 1083: @item hp9k320
! 1084: HP 9000 series 300 using HPUX assembler.
! 1085: @item kp9k320g
! 1086: HP 9000 series 300 using GNU assembler, linker and debugger.
! 1087: This requires the HP-adapt package which is or will soon be
! 1088: available in the same places as GNU CC.
! 1089: @item isi68
! 1090: ISI 68000 or 68020 system.
! 1091: @item news800
! 1092: Sony NEWS 68020 system.
! 1093: @item 3b1
! 1094: AT&T 3b1, a.k.a. 7300 PC.
! 1095: @item sequent-ns32k
! 1096: Sequent containing ns32000 processors.
! 1097: @item encore
! 1098: Encore ns32000 system.
! 1099: @item genix
! 1100: National Semiconductor ns32000 system.
! 1101: @item 88000
! 1102: Motorola 88000 processor. This port is not finished.
! 1103: @end table
1.1.1.2 root 1104:
1.1.1.4 ! root 1105: Here we spell out what files need to be set up:
1.1 root 1106:
1107: @itemize @bullet
1108: @item
1109: Make a symbolic link named @file{config.h} to the top-level
1110: config file for the machine you are using (@pxref{Config}). This
1111: file is responsible for defining information about the host
1112: machine. It includes @file{tm.h}.
1113:
1.1.1.3 root 1114: The file's name should be @file{xm-@var{machine}.h}, with these
1.1 root 1115: exceptions:
1116:
1117: @table @file
1.1.1.3 root 1118: @item xm-vms.h
1.1 root 1119: for vaxen running VMS.
1.1.1.3 root 1120: @item xm-vaxv.h
1.1 root 1121: for vaxen running system V.
1.1.1.3 root 1122: @item xm-i386v.h
1.1 root 1123: for Intel 80386's running system V.
1.1.1.3 root 1124: @item xm-sunos4.h
1.1 root 1125: for Suns (model 2, 3 or 4) running @emph{operating system} version 4.
1.1.1.3 root 1126: (Use @file{xm-m68k.h} or @file{xm-sparc.h} for version 3.)
1127: @item xm-sun386i.h
1128: for Sun roadrunner running any version of the operating system.
1129: @item xm-hp9k320.h
1.1 root 1130: for the HP 9000 series 300.
1.1.1.4 ! root 1131: @item xm-genix.h
1.1 root 1132: for the ns32000 running Genix
1133: @end table
1134:
1135: If your system does not support symbolic links, you might want to
1136: set up @file{config.h} to contain a @samp{#include} command which
1137: refers to the appropriate file.
1138:
1139: @item
1140: Make a symbolic link named @file{tm.h} to the machine-description
1141: macro file for your machine (its name should be
1142: @file{tm-@var{machine}.h}).
1143:
1144: If your system is a 68000, don't use the file @file{tm-m68k.h}
1145: directly. Instead, use one of these files:
1146:
1147: @table @file
1148: @item tm-sun3.h
1149: for Sun 3 machines.
1150: @item tm-sun2.h
1151: for Sun 2 machines.
1152: @item tm-3b1.h
1153: for AT&T 3b1 (aka 7300 Unix PC).
1154: @item tm-isi68.h
1.1.1.3 root 1155: for Integrated Solutions systems. This file assumes you
1156: use the GNU assembler.
1.1 root 1157: @item tm-news800.h
1158: for SONY News systems.
1159: @item tm-hp9k320.h
1160: for HPUX systems, if you are using GNU CC with the system's
1161: assembler and linker.
1162: @item tm-hp9k320g.h
1163: for HPUX systems, if you are using the GNU assembler, linker and
1164: other utilities. Not all of the pieces of GNU software needed
1165: for this mode of operation are as yet in distribution; full
1166: instructions will appear here in the future.@refill
1167: @end table
1168:
1169: For the vax, use @file{tm-vax.h} on BSD Unix, @file{tm-vaxv.h} on
1170: system V, or @file{tm-vms.h} on VMS.@refill
1171:
1172: For the Motorola 88000, use @file{tm-m88k.h}. The support for the
1173: 88000 has a few unfinished spots because there was no way to run the
1.1.1.2 root 1174: output. Bugs are suspected in handling of branch-tables and in the
1175: function prologue and epilogue.
1.1 root 1176:
1177: For the 80386, don't use @file{tm-i386.h} directly. Use
1178: @file{tm-i386v.h} if the target machine is running system V,
1179: @file{tm-seq386.h} for a Sequent 386 system, or @file{tm-compaq.h} for
1.1.1.3 root 1180: a Compaq, or @file{tm-sun386i.h} for a Sun 386 system.
1.1 root 1181:
1182: For the 32000, use @file{tm-sequent.h} if you are using a Sequent
1183: machine, or @file{tm-encore.h} for an Encore machine, or
1.1.1.4 ! root 1184: @file{tm-genix.h} if you are using Genix version 3; otherwise, perhaps
1.1 root 1185: @file{tm-ns32k.h} will work for you.
1186:
1187: Note that Genix has bugs in @code{alloca} and @code{malloc}; you must
1188: get the compiled versions of these from GNU Emacs and edit GNU CC's
1189: @file{Makefile} to use them.
1190:
1191: Note that Encore systems are supported only under BSD.
1192:
1193: @item
1194: Make a symbolic link named @file{md} to the machine description
1.1.1.2 root 1195: pattern file. Its name should be @file{@var{machine}.md}, but
1196: @var{machine} is often not the same as the name used in the
1197: @file{tm.h} file because the @file{md} files are more general.
1.1 root 1198:
1199: @item
1200: Make a symbolic link named @file{aux-output.c} to the output
1201: subroutine file for your machine (its name should be
1202: @file{output-@var{machine}.c}).
1203: @end itemize
1204:
1205: @item
1206: Make sure the Bison parser generator is installed. (This is
1207: unnecessary if the Bison output files @file{c-parse.tab.c} and
1208: @file{cexp.c} are more recent than @file{c-parse.y} and @file{cexp.y}
1209: and you do not plan to change the @samp{.y} files.)
1210:
1211: Bison versions older that Sept 8, 1988 will produce incorrect output
1212: for @file{c-parse.tab.c}.
1213:
1214: @item
1215: If you are using a Sun, make sure the environment variable
1216: @code{FLOAT_OPTION} is not set. If this option were set to
1217: @code{f68881} when @file{gnulib} is compiled, the resulting code would
1218: demand to be linked with a special startup file and will not link
1219: properly without special pains.
1220:
1221: @item
1222: Build the compiler. Just type @samp{make} in the compiler directory.
1223:
1.1.1.2 root 1224: Ignore any warnings you may see about ``statement not reached'' in the
1225: @file{insn-emit.c}; they are normal. Any other compilation errors may
1226: represent bugs in the port to your machine or operating system, and
1227: should be investigated and reported (@pxref{Bugs}).
1228:
1.1 root 1229: @item
1230: Move the first-stage object files and executables into a subdirectory
1231: with this command:
1232:
1233: @example
1234: make stage1
1235: @end example
1236:
1237: The files are moved into a subdirectory named @file{stage1}.
1238: Once installation is complete, you may wish to delete these files
1239: with @code{rm -r stage1}.
1240:
1241: @item
1242: Recompile the compiler with itself, with this command:
1243:
1244: @example
1245: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/"
1246: @end example
1247:
1248: On a 68000 or 68020 system lacking floating point hardware,
1249: unless you have selected a @file{tm.h} file that expects by default
1250: that there is no such hardware, do this instead:
1251:
1252: @example
1253: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/ -msoft-float"
1254: @end example
1255:
1256: @item
1257: If you wish to test the compiler by compiling it with itself one more
1258: time, do this:
1259:
1260: @example
1261: make stage2
1262: make CC=stage2/gcc CFLAGS="-g -O -Bstage2/"
1263: foreach file (*.o)
1264: cmp $file stage2/$file
1265: end
1266: @end example
1267:
1268: This will notify you if any of these stage 3 object files differs from
1269: those of stage 2. Any difference, no matter how innocuous, indicates
1270: that the stage 2 compiler has compiled GNU CC incorrectly, and is
1271: therefore a potentially serious bug which you should investigate and
1272: report (@pxref{Bugs}).
1273:
1274: Aside from the @samp{-B} option, the options should be the same as
1275: when you made stage 2.
1276:
1277: @item
1278: Install the compiler driver, the compiler's passes and run-time support.
1279: You can use the following command:
1280:
1281: @example
1282: make install
1283: @end example
1284:
1285: @noindent
1286: This copies the files @file{cc1}, @file{cpp} and @file{gnulib} to
1287: files @file{gcc-cc1}, @file{gcc-cpp} and @file{gcc-gnulib} in
1288: directory @file{/usr/local/lib}, which is where the compiler driver
1289: program looks for them. It also copies the driver program @file{gcc}
1290: into the directory @file{/usr/local}, so that it appears in typical
1291: execution search paths.@refill
1292:
1293: @strong{Warning: there is a bug in @code{alloca} in the Sun library.
1294: To avoid this bug, install the binaries of GNU CC that were compiled
1295: by GNU CC. They use @code{alloca} as a built-in function and never
1296: the one in the library.}
1297:
1298: @strong{Warning: the GNU CPP may not work for @file{ioctl.h},
1299: @file{ttychars.h} and other system header files unless the
1300: @samp{-traditional} option is used.} The bug is in the header files:
1301: at least on some machines, they rely on behavior that is incompatible
1302: with ANSI C. This behavior consists of substituting for macro
1303: argument names when they appear inside of character constants. The
1304: @samp{-traditional} option tells GNU CC to behave the way these
1305: headers expect.
1306:
1307: Because of this problem, you might prefer to configure GNU CC to use
1308: the system's own C preprocessor. To do so, make the file
1309: @file{/usr/local/lib/gcc-cpp} a link to @file{/lib/cpp}.
1310:
1311: Alternatively, on Sun systems and 4.3BSD at least, you can correct the
1312: include files by running the shell script @file{fixincludes}. This
1313: installs modified, corrected copies of the files @file{ioctl.h},
1314: @file{ttychars.h} and many others, in a special directory where only
1.1.1.2 root 1315: GNU CC will normally look for them. This script will work on various
1316: systems because it choose the files by searching all the system
1317: headers for the problem cases that we know about.
1.1 root 1318: @end enumerate
1319:
1320: If you cannot install the compiler's passes and run-time support in
1321: @file{/usr/local/lib}, you can alternatively use the @samp{-B} option to
1322: specify a prefix by which they may be found. The compiler concatenates
1323: the prefix with the names @file{cpp}, @file{cc1} and @file{gnulib}.
1324: Thus, you can put the files in a directory @file{/usr/foo/gcc} and
1325: specify @samp{-B/usr/foo/gcc/} when you run GNU CC.
1326:
1327: Also, you can specify an alternative default directory for these files
1328: by setting the Make variable @code{libdir} when you make GNU CC.
1329:
1330: @node VMS Install,, Installation, Installation
1331: @section Installing GNU CC on VMS
1332:
1.1.1.4 ! root 1333: The VMS version of GNU CC is distributed in a backup saveset containing
! 1334: both source code and precompiled binaries.
! 1335:
! 1336: Sometimes the binaries will be from an older version that the sources,
! 1337: because we don't always have time to update them. In this case, you
! 1338: should use the binaries you get to recompile the sources. If you must
1.1 root 1339: recompile, here is how:
1340:
1341: @enumerate
1342: @item
1.1.1.3 root 1343: Copy the file @file{tm-vms.h} to @file{tm.h}, @file{xm-vms.h} to
1.1 root 1344: @file{config.h}, @file{vax.md} to @file{md.} and @file{output-vax.c}
1345: to @file{aux-output.c}.@refill
1346:
1347: @item
1348: Type @samp{@@make} to do recompile everything.
1349: @end enumerate
1350:
1351: To install the @samp{GCC} command so you can use the compiler easily, in
1352: the same manner as you use the VMS C compiler, you must install the VMS CLD
1353: file for GNU CC as follows:
1354:
1355: @enumerate
1356: @item
1357: Define the VMS logical names @samp{GNU_CC} and @samp{GNU_CC_INCLUDE}
1358: to point to the directories where the GNU CC executables
1359: (@samp{gcc-cpp}, @samp{gcc-cc1}, etc.) and the C include files are
1360: kept. This should be done with the commands:@refill
1361:
1362: @example
1363: $ assign /super /system disk:[gcc] gnu_cc
1364: $ assign /super /system disk:[gcc.include] gnu_cc_include
1365: @end example
1366:
1367: @noindent
1368: with the appropriate disk and directory names. These commands can be
1369: placed in your system startup file so they will be executed whenever
1370: the machine is rebooted.
1371:
1372: @item
1373: Install the @samp{GCC} command with the command line:
1374:
1375: @example
1376: $ set command /table=sys$library:dcltables gnu_cc:gcc
1377: @end example
1378:
1379: @noindent
1380: Now you can invoke the compiler with a command like @samp{gcc /verbose
1381: file.c}, which is equivalent to the command @samp{gcc -v -c file.c} in
1382: Unix.
1383: @end enumerate
1384:
1385: @node Trouble, Incompatibilities, Installation, Top
1386: @chapter Known Causes of Trouble with GNU CC.
1387:
1388: Here are some of the things that have caused trouble for people installing
1389: or using GNU CC.
1390:
1391: @itemize @bullet
1392: @item
1393: On certain systems, defining certain environment variables such as
1394: @samp{CC} can interfere with the functioning of @code{make}.
1395:
1396: @item
1397: Cross compilation can run into trouble for certain machines because
1398: some target machines' assemblers require floating point numbers to be
1399: written as @emph{integer} constants in certain contexts.
1400:
1401: The compiler writes these integer constants by examining the floating
1402: point value as an integer and printing that integer, because this is
1403: simple to write and independent of the details of the floating point
1404: representation. But this does not work if the compiler is running on
1405: a different machine with an incompatible floating point format, or
1406: even a different byte-ordering.
1407:
1408: It is possible to fix this by writing machine-independent code which
1409: understands the floating point representation of the target machine.
1410: I am not interested in doing that much work to compensate for bugs
1411: in assemblers.
1412:
1413: @item
1414: DBX rejects some files produced by GNU CC, though it accepts similar
1415: constructs in output from PCC. Until someone can supply a coherent
1416: description of what is valid DBX input and what is not, there is
1417: nothing I can do about these problems. You are on your own.
1.1.1.2 root 1418:
1419: @item
1420: Users often think it is a bug when GNU CC reports an error for code
1421: like this:
1422:
1423: @example
1424: int foo (short);
1425:
1426: int foo (x)
1427: short x;
1428: @{@dots{}@}
1429: @end example
1430:
1.1.1.4 ! root 1431: The error message is correct: this code really is erroneous, because the
! 1432: old-style non-prototype definition passes subword integers in their
! 1433: promoted types. In other words, the argument is really an @code{int},
! 1434: not a @code{short}. The correct prototype is this:
1.1.1.2 root 1435:
1436: @example
1437: int foo (int);
1438: @end example
1439:
1440: @item
1441: Users often think it is a bug when GNU CC reports an error for code
1442: like this:
1443:
1444: @example
1445: int foo (struct mumble *);
1446:
1447: struct mumble @{ @dots{} @};
1448:
1449: int foo (struct mumble *x)
1450: @{ @dots{} @}
1451: @end example
1452:
1453: This code really is erroneous, because the scope of @code{struct
1454: mumble} the prototype is limited to the argument list containing it.
1455: It does not refer to the @code{struct mumble} defined with file scope
1456: immediately below---they are two unrelated types with similar names in
1457: different scopes.
1458:
1459: But in the definition of @code{foo}, the file-scope type is used
1460: because that is available to be inherited. Thus, the definition and
1461: the prototype do not match, and you get an error.
1462:
1463: This behavior may seem silly, but it's what the ANSI standard
1464: specifies. It is easy enough for you to make your code work by moving
1465: the definition of @code{struct mumble} above the prototype. I don't
1466: think it's worth being incompatible for.
1.1 root 1467: @end itemize
1468:
1469: @node Incompatibilities, Extensions, Trouble, Top
1470: @chapter Incompatibilities of GNU CC
1471:
1472: There are several noteworthy incompatibilities between GNU C and most
1473: existing (non-ANSI) versions of C.
1474:
1475: Ultimately our intention is that the @samp{-traditional} option will
1476: eliminate most of these incompatibilities by telling GNU C to behave
1477: like the other C compilers.
1478:
1479: @itemize @bullet
1480: @item
1481: GNU CC normally makes string constants read-only. If several
1482: identical-looking string constants are used, GNU CC stores only one
1483: copy of the string.
1484:
1485: One consequence is that you cannot call @code{mktemp} with a string
1486: constant argument. The function @code{mktemp} always alters the
1487: string its argument points to.
1488:
1489: Another consequence is that @code{sscanf} does not work on some
1490: systems when passed a string constant as its format control string.
1491: This is because @code{sscanf} incorrectly tries to write into the
1.1.1.4 ! root 1492: string constant. Likewise @code{fscanf} and @code{scanf}.
1.1 root 1493:
1494: The best solution to these problems is to change the program to use
1495: @code{char}-array variables with initialization strings for these
1496: purposes instead of string constants. But if this is not possible,
1497: you can use the @samp{-fwritable-strings} flag, which directs GNU CC
1498: to handle string constants the same way most C compilers do.
1499:
1500: @item
1501: GNU CC does not substitute macro arguments when they appear inside of
1502: string constants. For example, the following macro in GNU CC
1503:
1504: @example
1505: #define foo(a) "a"
1506: @end example
1507:
1508: @noindent
1509: will produce output @samp{"a"} regardless of what the argument @var{a} is.
1510:
1511: The @samp{-traditional} option directs GNU CC to handle such cases
1512: (among others) in the old-fashioned (non-ANSI) fashion.
1513:
1514: @item
1515: When you use @code{setjmp} and @code{longjmp}, the only automatic
1516: variables guaranteed to remain valid are those declared
1517: @code{volatile}. This is a consequence of automatic register
1518: allocation. Consider this function:
1519:
1520: @example
1521: jmp_buf j;
1522:
1523: foo ()
1524: @{
1525: int a, b;
1526:
1527: a = fun1 ();
1528: if (setjmp (j))
1529: return a;
1530:
1531: a = fun2 ();
1532: /* @r{@code{longjmp (j)} may be occur in @code{fun3}.} */
1533: return a + fun3 ();
1534: @}
1535: @end example
1536:
1537: Here @code{a} may or may not be restored to its first value when the
1538: @code{longjmp} occurs. If @code{a} is allocated in a register, then
1539: its first value is restored; otherwise, it keeps the last value stored
1540: in it.
1541:
1542: If you use the @samp{-W} option with the @samp{-O} option, you will
1543: get a warning when GNU CC thinks such a problem might be possible.
1544:
1.1.1.2 root 1545: The @samp{-traditional} option directs GNU C to put variables in
1546: the stack by default, rather than in registers, in functions that
1547: call @code{setjmp}. This results in the behavior found in
1548: traditional C compilers.
1549:
1.1 root 1550: @item
1551: Declarations of external variables and functions within a block apply
1552: only to the block containing the declaration. In other words, they
1553: have the same scope as any other declaration in the same place.
1554:
1555: In some other C compilers, a @code{extern} declaration affects all the
1556: rest of the file even if it happens within a block.
1557:
1558: The @samp{-traditional} option directs GNU C to treat all @code{extern}
1559: declarations as global, like traditional compilers.
1560:
1561: @item
1562: In traditional C, you can combine @code{long}, etc., with a typedef name,
1563: as shown here:
1564:
1565: @example
1566: typedef int foo;
1567: typedef long foo bar;
1568: @end example
1569:
1570: In ANSI C, this is not allowed: @code{long} and other type modifiers
1571: require an explicit @code{int}. Because this criterion is expressed
1572: by Bison grammar rules rather than C code, the @samp{-traditional}
1573: flag cannot alter it.
1574:
1575: @item
1576: PCC allows typedef names to be used as function parameters. The
1577: difficulty described immediately above applies here too.
1578:
1579: @item
1580: PCC allows whitespace in the middle of compound assignment operators
1581: such as @samp{+=}. GNU CC, following the ANSI standard, does not
1582: allow this. The difficulty described immediately above applies here
1583: too.
1584:
1585: @item
1586: GNU CC will flag unterminated character constants inside of preprocessor
1587: conditionals that fail. Some programs have English comments enclosed in
1588: conditionals that are guaranteed to fail; if these comments contain
1589: apostrophes, GNU CC will probably report an error. For example,
1590: this code would produce an error:
1591:
1592: @example
1593: #if 0
1594: You can't expect this to work.
1595: #endif
1596: @end example
1597:
1598: The best solution to such a problem is to put the text into an actual
1599: C comment delimited by @samp{/*@dots{}*/}. However,
1600: @samp{-traditional} suppresses these error messages.
1601:
1602: @item
1603: When compiling functions that return @code{float}, PCC converts it to
1604: a double. GNU CC actually returns a @code{float}. If you are concerned
1605: with PCC compatibility, you should declare your functions to return
1606: @code{double}; you might as well say what you mean.
1607:
1608: @item
1609: When compiling functions that return structures or unions, GNU CC
1610: output code uses a method different from that used on most versions of
1611: Unix. As a result, code compiled with GNU CC cannot call a
1612: structure-returning function compiled with PCC, and vice versa.
1613:
1614: The method used by GCC is as follows: a structure or union which is 1,
1615: 2, 4 or 8 bytes long is returned like a scalar. A structure or union
1616: with any other size is stored into an address supplied by the caller
1617: in a special, fixed register.
1618:
1619: PCC usually handles all sizes of structures and unions by returning
1620: the address of a block of static storage containing the value. This
1621: method is not used in GCC because it is slower and nonreentrant.
1622:
1623: On systems where PCC works this way, you may be able to make GCC-compiled
1624: code call such functions that were compiled with PCC by declaring them
1625: to return a pointer to the structure or union instead of the structure
1626: or union itself. For example, instead of this:
1627:
1628: @example
1629: struct foo nextfoo ();
1630: @end example
1631:
1632: @noindent
1633: write this:
1634:
1635: @example
1636: struct foo *nextfoo ();
1637: #define nextfoo *nextfoo
1638: @end example
1639:
1640: @noindent
1641: (Note that this assumes you are using the GNU preprocessor and not
1642: @samp{-traditional}, so that the ANSI antirecursion rules for macro
1643: expansions are effective.)
1644: @end itemize
1645:
1646: @node Extensions, Bugs, Incompatibilities, Top
1647: @chapter GNU Extensions to the C Language
1648:
1649: GNU C provides several language features not found in ANSI standard C.
1650: (The @samp{-pedantic} option directs GNU CC to print a warning message if
1651: any of these features is used.) To test for the availability of these
1652: features in conditional compilation, check for a predefined macro
1653: @code{__GNUC__}, which is always defined under GNU CC.
1654:
1655: @menu
1656: * Statement Exprs:: Putting statements and declarations inside expressions.
1657: * Naming Types:: Giving a name to the type of some expression.
1658: * Typeof:: @code{typeof}: referring to the type of an expression.
1659: * Lvalues:: Using @samp{?:}, @samp{,} and casts in lvalues.
1660: * Conditionals:: Omitting the middle operand of a @samp{?:} expression.
1661: * Zero-Length:: Zero-length arrays.
1662: * Variable-Length:: Arrays whose length is computed at run time.
1663: * Subscripting:: Any array can be subscripted, even if not an lvalue.
1664: * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers.
1665: * Constructors:: Constructor expressions give structures, unions
1666: or arrays as values.
1667: * Dollar Signs:: Dollar sign is allowed in identifiers.
1668: * Alignment:: Inquiring about the alignment of a type or variable.
1669: * Inline:: Defining inline functions (as fast as macros).
1670: * Extended Asm:: Assembler instructions with C expressions as operands.
1671: (With them you can define ``built-in'' functions.)
1672: * Asm Labels:: Specifying the assembler name to use for a C symbol.
1673: @end menu
1674:
1675: @node Statement Exprs, Naming Types, Extensions, Extensions
1676: @section Statements and Declarations inside of Expressions
1677:
1678: A compound statement in parentheses may appear inside an expression in GNU
1679: C. This allows you to declare variables within an expression. For
1680: example:
1681:
1682: @example
1683: (@{ int y = foo (); int z;
1684: if (y > 0) z = y;
1685: else z = - y;
1686: z; @})
1687: @end example
1688:
1689: @noindent
1690: is a valid (though slightly more complex than necessary) expression
1691: for the absolute value of @code{foo ()}.
1692:
1693: This feature is especially useful in making macro definitions ``safe'' (so
1694: that they evaluate each operand exactly once). For example, the
1695: ``maximum'' function is commonly defined as a macro in standard C as
1696: follows:
1697:
1698: @example
1699: #define max(a,b) ((a) > (b) ? (a) : (b))
1700: @end example
1701:
1702: @noindent
1703: But this definition computes either @var{a} or @var{b} twice, with bad
1704: results if the operand has side effects. In GNU C, if you know the
1705: type of the operands (here let's assume @code{int}), you can define
1706: the macro safely as follows:
1707:
1708: @example
1709: #define maxint(a,b) \
1710: (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
1711: @end example
1712:
1713: Embedded statements are not allowed in constant expressions, such as
1714: the value of an enumeration constant, the width of a bit field, or
1715: the initial value of a static variable.
1716:
1717: If you don't know the type of the operand, you can still do this, but you
1718: must use @code{typeof} (@pxref{Typeof}) or type naming (@pxref{Naming
1719: Types}).
1720:
1721: @node Naming Types, Typeof, Statement Exprs, Extensions
1722: @section Naming an Expression's Type
1723:
1724: You can give a name to the type of an expression using a @code{typedef}
1725: declaration with an initializer. Here is how to define @var{name} as a
1726: type name for the type of @var{exp}:
1727:
1728: @example
1729: typedef @var{name} = @var{exp};
1730: @end example
1731:
1732: This is useful in conjunction with the statements-within-expressions
1733: feature. Here is how the two together can be used to define a safe
1734: ``maximum'' macro that operates on any arithmetic type:
1735:
1736: @example
1737: #define max(a,b) \
1738: (@{typedef _ta = (a), _tb = (b); \
1739: _ta _a = (a); _tb _b = (b); \
1740: _a > _b ? _a : _b; @})
1741: @end example
1742:
1743: The reason for using names that start with underscores for the local
1744: variables is to avoid conflicts with variable names that occur within the
1745: expressions that are substituted for @code{a} and @code{b}. Eventually we
1746: hope to design a new form of declaration syntax that allows you to declare
1747: variables whose scopes start only after their initializers; this will be a
1748: more reliable way to prevent such conflicts.
1749:
1750: @node Typeof, Lvalues, Naming Types, Extensions
1751: @section Referring to a Type with @code{typeof}
1752:
1753: Another way to refer to the type of an expression is with @code{typeof}.
1754: The syntax of using of this keyword looks like @code{sizeof}, but the
1755: construct acts semantically like a type name defined with @code{typedef}.
1756:
1757: There are two ways of writing the argument to @code{typeof}: with an
1758: expression or with a type. Here is an example with an expression:
1759:
1760: @example
1761: typeof (x[0](1))
1762: @end example
1763:
1764: @noindent
1765: This assumes that @code{x} is an array of functions; the type described
1766: is that of the values of the functions.
1767:
1768: Here is an example with a typename as the argument:
1769:
1770: @example
1771: typeof (int *)
1772: @end example
1773:
1774: @noindent
1775: Here the type described is that of pointers to @code{int}.
1776:
1777: A @code{typeof}-construct can be used anywhere a typedef name could be
1778: used. For example, you can use it in a declaration, in a cast, or inside
1779: of @code{sizeof} or @code{typeof}.
1780:
1781: @itemize @bullet
1782: @item
1783: This declares @code{y} with the type of what @code{x} points to.
1784:
1785: @example
1786: typeof (*x) y;
1787: @end example
1788:
1789: @item
1790: This declares @code{y} as an array of such values.
1791:
1792: @example
1793: typeof (*x) y[4];
1794: @end example
1795:
1796: @item
1797: This declares @code{y} as an array of pointers to characters:
1798:
1799: @example
1800: typeof (typeof (char *)[4]) y;
1801: @end example
1802:
1803: @noindent
1804: It is equivalent to the following traditional C declaration:
1805:
1806: @example
1807: char *y[4];
1808: @end example
1809:
1810: To see the meaning of the declaration using @code{typeof}, and why it
1811: might be a useful way to write, let's rewrite it with these macros:
1812:
1813: @example
1814: #define pointer(T) typeof(T *)
1815: #define array(T, N) typeof(T [N])
1816: @end example
1817:
1818: @noindent
1819: Now the declaration can be rewritten this way:
1820:
1821: @example
1822: array (pointer (char), 4) y;
1823: @end example
1824:
1825: @noindent
1826: Thus, @samp{array (pointer (char), 4)} is the type of arrays of 4
1827: pointers to @code{char}.
1828: @end itemize
1829:
1830: @node Lvalues, Conditionals, Typeof, Extensions
1831: @section Generalized Lvalues
1832:
1833: Compound expressions, conditional expressions and casts are allowed as
1834: lvalues provided their operands are lvalues. This means that you can take
1835: their addresses or store values into them.
1836:
1837: For example, a compound expression can be assigned, provided the last
1838: expression in the sequence is an lvalue. These two expressions are
1839: equivalent:
1840:
1841: @example
1842: (a, b) += 5
1843: a, (b += 5)
1844: @end example
1845:
1846: Similarly, the address of the compound expression can be taken. These two
1847: expressions are equivalent:
1848:
1849: @example
1850: &(a, b)
1851: a, &b
1852: @end example
1853:
1854: A conditional expression is a valid lvalue if its type is not void and the
1855: true and false branches are both valid lvalues. For example, these two
1856: expressions are equivalent:
1857:
1858: @example
1859: (a ? b : c) = 5
1860: (a ? b = 5 : (c = 5))
1861: @end example
1862:
1863: A cast is a valid lvalue if its operand is valid. Taking the address of
1864: the cast is the same as taking the address without a cast, except for the
1865: type of the result. For example, these two expressions are equivalent (but
1866: the second may be valid when the type of @samp{a} does not permit a cast to
1867: @samp{int *}).
1868:
1869: @example
1870: &(int *)a
1871: (int **)&a
1872: @end example
1873:
1874: A simple assignment whose left-hand side is a cast works by converting the
1875: right-hand side first to the specified type, then to the type of the inner
1876: left-hand side expression. After this is stored, the value is converter
1877: back to the specified type to become the value of the assignment. Thus, if
1878: @samp{a} has type @samp{char *}, the following two expressions are
1879: equivalent:
1880:
1881: @example
1882: (int)a = 5
1883: (int)(a = (char *)5)
1884: @end example
1885:
1886: An assignment-with-arithmetic operation such as @samp{+=} applied to a cast
1887: performs the arithmetic using the type resulting from the cast, and then
1888: continues as in the previous case. Therefore, these two expressions are
1889: equivalent:
1890:
1891: @example
1892: (int)a += 5
1893: (int)(a = (char *) ((int)a + 5))
1894: @end example
1895:
1896: @node Conditionals, Zero-Length, Lvalues, Extensions
1897: @section Conditional Expressions with Omitted Middle-Operands
1898:
1899: The middle operand in a conditional expression may be omitted. Then
1900: if the first operand is nonzero, its value is the value of the conditional
1901: expression.
1902:
1903: Therefore, the expression
1904:
1905: @example
1906: x ? : y
1907: @end example
1908:
1909: @noindent
1910: has the value of @code{x} if that is nonzero; otherwise, the value of
1911: @code{y}.
1912:
1913: This example is perfectly equivalent to
1914:
1915: @example
1916: x ? x : y
1917: @end example
1918:
1919: @noindent
1920: In this simple case, the ability to omit the middle operand is not
1921: especially useful. When it becomes useful is when the first operand does,
1922: or may (if it is a macro argument), contain a side effect. Then repeating
1923: the operand in the middle would perform the side effect twice. Omitting
1924: the middle operand uses the value already computed without the undesirable
1925: effects of recomputing it.
1926:
1927: @node Zero-Length, Variable-Length, Conditionals, Extensions
1928: @section Arrays of Length Zero
1929:
1930: Zero-length arrays are allowed in GNU C. They are very useful as the last
1931: element of a structure which is really a header for a variable-length
1932: object:
1933:
1934: @example
1935: struct line @{
1936: int length;
1937: char contents[0];
1938: @};
1939:
1940: @{
1941: struct line *thisline
1942: = (struct line *) malloc (sizeof (struct line) + this_length);
1943: thisline->length = this_length;
1944: @}
1945: @end example
1946:
1947: In standard C, you would have to give @code{contents} a length of 1, which
1948: means either you waste space or complicate the argument to @code{malloc}.
1949:
1950: @node Variable-Length, Subscripting, Zero-Length, Extensions
1951: @section Arrays of Variable Length
1952:
1953: Variable-length automatic arrays are allowed in GNU C. These arrays are
1954: declared like any other automatic arrays, but with a length that is not a
1955: constant expression. The storage is allocated at that time and
1956: deallocated when the brace-level is exited. For example:
1957:
1958: @example
1959: FILE *concat_fopen (char *s1, char *s2, char *mode)
1960: @{
1961: char str[strlen (s1) + strlen (s2) + 1];
1962: strcpy (str, s1);
1963: strcat (str, s2);
1964: return fopen (str, mode);
1965: @}
1966: @end example
1967:
1968: You can also define structure types containing variable-length arrays, and
1969: use them even for arguments or function values, as shown here:
1970:
1971: @example
1972: int foo;
1973:
1974: struct entry
1975: @{
1976: char data[foo];
1977: @};
1978:
1979: struct entry
1980: tester (struct entry arg)
1981: @{
1982: struct entry new;
1983: int i;
1984: for (i = 0; i < foo; i++)
1985: new.data[i] = arg.data[i] + 1;
1986: return new;
1987: @}
1988: @end example
1989:
1990: @noindent
1991: (Eventually there will be a way to say that the size of the array is
1992: another member of the same structure.)
1993:
1994: The length of an array is computed on entry to the brace-level where the
1995: array is declared and is remembered for the scope of the array in case you
1996: access it with @code{sizeof}.
1997:
1998: Jumping or breaking out of the scope of the array name will also deallocate
1999: the storage. Jumping into the scope is not allowed; you will get an error
2000: message for it.
2001:
2002: You can use the function @code{alloca} to get an effect much like
2003: variable-length arrays. The function @code{alloca} is available in
2004: many other C implementations (but not in all). On the other hand,
2005: variable-length arrays are more elegant.
2006:
2007: There are other differences between these two methods. Space allocated
2008: with @code{alloca} exists until the containing @emph{function} returns.
2009: The space for a variable-length array is deallocated as soon as the array
2010: name's scope ends. (If you use both variable-length arrays and
2011: @code{alloca} in the same function, deallocation of a variable-length array
2012: will also deallocate anything more recently allocated with @code{alloca}.)
2013:
2014: @node Subscripting, Pointer Arith, Variable-Length, Extensions
2015: @section Non-Lvalue Arrays May Have Subscripts
2016:
2017: Subscripting is allowed on arrays that are not lvalues, even though the
2018: unary @samp{&} operator is not. For example, this is valid in GNU C though
2019: not valid in other C dialects:
2020:
2021: @example
2022: struct foo @{int a[4];@};
2023:
2024: struct foo f();
2025:
2026: bar (int index)
2027: @{
2028: return f().a[index];
2029: @}
2030: @end example
2031:
2032: @node Pointer Arith, Initializers, Subscripting, Extensions
2033: @section Arithmetic on @code{void}-Pointers and Function Pointers
2034:
2035: In GNU C, addition and subtraction operations are supported on pointers to
2036: @code{void} and on pointers to functions. This is done by treating the
2037: size of a @code{void} or of a function as 1.
2038:
2039: A consequence of this is that @code{sizeof} is also allowed on @code{void}
2040: and on function types, and returns 1.
2041:
2042: @node Initializers, Constructors, Pointer Arith, Extensions
2043: @section Non-Constant Initializers
2044:
2045: The elements of an aggregate initializer are not required to be constant
2046: expressions in GNU C. Here is an example of an initializer with run-time
2047: varying elements:
2048:
2049: @example
2050: foo (float f, float g)
2051: @{
2052: float beat_freqs[2] = @{ f-g, f+g @};
2053: @dots{}
2054: @}
2055: @end example
2056:
2057: @node Constructors, Dollar Signs, Initializers, Extensions
2058: @section Constructor Expressions
2059:
2060: GNU C supports constructor expressions. A constructor looks like a cast
2061: containing an initializer. Its value is an object of the type specified in
2062: the cast, containing the elements specified in the initializer. The type
2063: must be a structure, union or array type.
2064:
2065: Assume that @code{struct foo} and @code{structure} are declared as shown:
2066:
2067: @example
2068: struct foo @{int a; char b[2];@} structure;
2069: @end example
2070:
2071: @noindent
2072: Here is an example of constructing a @samp{struct foo} with a constructor:
2073:
2074: @example
2075: structure = ((struct foo) @{x + y, 'a', 0@});
2076: @end example
2077:
2078: @noindent
2079: This is equivalent to writing the following:
2080:
2081: @example
2082: @{
2083: struct foo temp = @{x + y, 'a', 0@};
2084: structure = temp;
2085: @}
2086: @end example
2087:
2088: You can also construct an array. If all the elements of the constructor
2089: are (made up of) simple constant expressions, suitable for use in
2090: initializers, then the constructor is an lvalue and can be coerced to a
2091: pointer to its first element, as shown here:
2092:
2093: @example
2094: char **foo = (char *[]) @{ "x", "y", "z" @};
2095: @end example
2096:
2097: Array constructors whose elements are not simple constants are not very
2098: useful, because the constructor is not an lvalue. There are only two valid
2099: ways to use it: to subscript it, or initialize an array variable with it.
2100: The former is probably slower than a @code{switch} statement, while the
2101: latter does the same thing an ordinary C initializer would do.
2102:
2103: @example
2104: output = ((int[]) @{ 2, x, 28 @}) [input];
2105: @end example
2106:
2107: @node Dollar Signs, Alignment, Constructors, Extensions
2108: @section Dollar Signs in Identifier Names
2109:
2110: In GNU C, you may use dollar signs in identifier names. This is because
2111: many traditional C implementations allow such identifiers.
2112:
2113: @node Alignment, Inline, Dollar Signs, Extensions
2114: @section Inquiring about the Alignment of a Type or Variable
2115:
2116: The keyword @code{__alignof} allows you to inquire about how an object
2117: is aligned, or the minimum alignment usually required by a type. Its
2118: syntax is just like @code{sizeof}.
2119:
2120: For example, if the target machine requires a @code{double} value to be
2121: aligned on an 8-byte boundary, then @code{__alignof (double)} is 8. This
2122: is true on many RISC machines. On more traditional machine designs,
2123: @code{__alignof (double)} is 4 or even 2.
2124:
2125: Some machines never actually require alignment; they allow reference to any
2126: data type even at an odd addresses. For these machines, @code{__alignof}
2127: reports the @emph{recommended} alignment of a type.
2128:
2129: When the operand of @code{__alignof} is an lvalue rather than a type, the
2130: value is the largest alignment that the lvalue is known to have. It may
2131: have this alignment as a result of its data type, or because it is part of
2132: a structure and inherits alignment from that structure. For example, after
2133: this declaration:
2134:
2135: @example
2136: struct foo @{ int x; char y; @} foo1;
2137: @end example
2138:
2139: @noindent
2140: the value of @code{__alignof (foo1.y)} is probably 2 or 4, the same as
2141: @code{__alignof (int)}, even though the data type of @code{foo1.y} does not
2142: itself demand any alignment.@refill
2143:
2144: @node Inline, Extended Asm, Alignment, Extensions
2145: @section An Inline Function is As Fast As a Macro
2146:
2147: By declaring a function @code{inline}, you can direct GNU CC to integrate
2148: that function's code into the code for its callers. This makes execution
2149: faster by eliminating the function-call overhead; in addition, if any of
2150: the actual argument values are constant, their known values may permit
2151: simplifications at compile time so that not all of the inline function's
2152: code needs to be included.
2153:
2154: To declare a function inline, use the @code{inline} keyword in its
2155: declaration, like this:
2156:
2157: @example
2158: inline int
2159: inc (int *a)
2160: @{
2161: (*a)++;
2162: @}
2163: @end example
2164:
2165: You can also make all ``simple enough'' functions inline with the
2166: option @samp{-finline-functions}. Note that certain usages in a
2167: function definition can make it unsuitable for inline substitution.
2168:
2169: When a function is both inline and @code{static}, if all calls to the
2170: function are integrated into the caller, then the function's own assembler
2171: code is never referenced. In this case, GNU CC does not actually output
2172: assembler code for the function, unless you specify the option
2173: @samp{-fkeep-inline-functions}. Some calls cannot be integrated for
2174: various reasons (in particular, calls that precede the function's
2175: definition cannot be integrated, and neither can recursive calls within the
2176: definition). If there is a nonintegrated call, then the function is
2177: compiled to assembler code as usual.
2178:
2179: When an inline function is not @code{static}, then the compiler must assume
2180: that there may be calls from other source files; since a global symbol can
2181: be defined only once in any program, the function must not be defined in
2182: the other source files, so the calls therein cannot be integrated.
2183: Therefore, a non-@code{static} inline function is always compiled on its
2184: own in the usual fashion.
2185:
2186: @node Extended Asm, Asm Labels, Inline, Extensions
2187: @section Assembler Instructions with C Expression Operands
2188:
2189: In an assembler instruction using @code{asm}, you can now specify the
2190: operands of the instruction using C expressions. This means no more
2191: guessing which registers or memory locations will contain the data you want
2192: to use.
2193:
2194: You must specify an assembler instruction template much like what appears
2195: in a machine description, plus an operand constraint string for each
2196: operand.
2197:
2198: For example, here is how to use the 68881's @code{fsinx} instruction:
2199:
2200: @example
2201: asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
2202: @end example
2203:
2204: @noindent
2205: Here @code{angle} is the C expression for the input operand while
2206: @code{result} is that of the output operand. Each has @samp{"f"} as its
2207: operand constraint, saying that a floating-point register is required. The
1.1.1.4 ! root 2208: @samp{=} in @samp{=r} indicates that the operand is an output; all output
! 2209: operands' constraints must use @samp{=}. The constraints use the same
! 2210: language used in the machine description (@pxref{Constraints}).
1.1 root 2211:
2212: Each operand is described by an operand-constraint string followed by the C
2213: expression in parentheses. A colon separates the assembler template from
2214: the first output operand, and another separates the last output operand
2215: from the first input, if any. Commas separate output operands and separate
1.1.1.4 ! root 2216: inputs. The total number of operands is limited to the maximum number of
1.1 root 2217: operands in any instruction pattern in the machine description.
2218:
1.1.1.4 ! root 2219: If there are no output operands, and there are input operands, then there
! 2220: must be two consecutive colons surrounding the place where the output
! 2221: operands would go.
! 2222:
1.1 root 2223: Output operand expressions must be lvalues; the compiler can check this.
2224: The input operands need not be lvalues. The compiler cannot check whether
2225: the operands have data types that are reasonable for the instruction being
2226: executed. It does not parse the assembler instruction template and does
2227: not know what it means, or whether it is valid assembler input. The
2228: extended @code{asm} feature is most often used for machine instructions
2229: that the compiler itself does not know exist.
2230:
2231: The output operands must be write-only; GNU CC will assume that the values
2232: in these operands before the instruction are dead and need not be
2233: generated. For an operand that is read-write, or in which not all bits are
2234: written and the other bits contain useful information, you must logically
2235: split its function into two separate operands, one input operand and one
2236: write-only output operand. The connection between them is expressed by
2237: constraints which say they need to be in the same location when the
2238: instruction executes. You can use the same C expression for both operands,
2239: or different expressions. For example, here we write the (fictitious)
2240: @samp{combine} instruction with @code{bar} as its read-only source operand
2241: and @code{foo} as its read-write destination:
2242:
2243: @example
2244: asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
2245: @end example
2246:
2247: @noindent
2248: The constraint @samp{"0"} for operand 1 says that it must occupy the same
2249: location as operand 0.
2250:
2251: Only a digit in the constraint can guarantee that one operand will be in
2252: the same place as another. The mere fact that @code{foo} is the value of
2253: both operands is not enough to guarantee that they will be in the same
2254: place in the generated assembler code. The following would not work:
2255:
2256: @example
2257: asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
2258: @end example
2259:
2260: Various optimizations or reloading could cause operands 0 and 1 to be in
2261: different registers; GNU CC knows no reason not to do so. For example, the
2262: compiler might find a copy of the value of @code{foo} in one register and
2263: use it for operand 1, but generate the output operand 0 in a different
2264: register (copying it afterward to @code{foo}'s own address). Of course,
2265: since the register for operand 1 is not even mentioned in the assembler
2266: code, the result will not work, but GNU CC can't tell that.
2267:
2268: Unless an output operand has the @samp{&} constraint modifier, GNU CC may
2269: allocate it in the same register as an unrelated input operand, on the
2270: assumption that the inputs are consumed before the outputs are produced.
2271: This assumption may be false if the assembler code actually consists of
2272: more than one instruction. In such a case, use @samp{&} for each output
2273: operand that may not overlap an input. @xref{Modifiers}.
2274:
1.1.1.4 ! root 2275: Some instructions clobber specific hard registers. To describe this, write
! 2276: a third colon after the input operands, followed by the names of the
! 2277: clobbered hard registers (given as strings). Here is a realistic example
! 2278: for the vax:
1.1 root 2279:
2280: @example
2281: asm volatile ("movc3 %0,%1,%2"
2282: : /* no outputs */
2283: : "g" (from), "g" (to), "g" (count)
2284: : "r0", "r1", "r2", "r3", "r4", "r5");
2285: @end example
2286:
1.1.1.4 ! root 2287: You can put multiple assembler instructions together in a single @code{asm}
! 2288: template, separated with semicolons. The input operands are guaranteed not
! 2289: to use any of the clobbered registers, and neither will the output
! 2290: operands' addresses, so you can read and write the clobbered registers as
! 2291: many times as you like. Here is an example of multiple instructions in a
! 2292: template; it assumes that the subroutine @code{_foo} accepts arguments in
! 2293: registers 9 and 10:
! 2294:
! 2295: @example
! 2296: asm ("movl %0,r9;movl %1,r10;call _foo"
! 2297: : /* no outputs */
! 2298: : "g" (from), "g" (to)
! 2299: : "r9", "r10");
! 2300: @end example
! 2301:
1.1 root 2302: Usually the most convenient way to use these @code{asm} instructions is to
2303: encapsulate them in macros that look like functions. For example,
2304:
2305: @example
2306: #define sin(x) \
2307: (@{ double __value, __arg = (x); \
2308: asm ("fsinx %1,%0": "=f" (__value): "f" (__arg)); \
2309: __value; @})
2310: @end example
2311:
2312: @noindent
2313: Here the variable @code{__arg} is used to make sure that the instruction
2314: operates on a proper @code{double} value, and to accept only those
2315: arguments @code{x} which can convert automatically to a @code{double}.
2316:
2317: Another way to make sure the instruction operates on the correct data type
2318: is to use a cast in the @code{asm}. This is different from using a
2319: variable @code{__arg} in that it converts more different types. For
2320: example, if the desired type were @code{int}, casting the argument to
2321: @code{int} would accept a pointer with no complaint, while assigning the
2322: argument to an @code{int} variable named @code{__arg} would warn about
2323: using a pointer unless the caller explicitly casts it.
2324:
1.1.1.4 ! root 2325: If an @code{asm} has output operands, GNU CC assumes for optimization
! 2326: purposes that the instruction has no side effects except to change the
! 2327: output operands. This does not mean that instructions with a side effect
! 2328: cannot be used, but you must be careful, because the compiler may eliminate
! 2329: them if the output operands aren't used, or move them out of loops, or
! 2330: replace two with one if they constitute a common subexpression. Also, if
! 2331: your instruction does have a side effect on a variable that otherwise
! 2332: appears not to change, the old value of the variable may be reused later if
! 2333: it happens to be found in a register.
1.1 root 2334:
2335: You can prevent an @code{asm} instruction from being deleted, moved or
2336: combined by writing the keyword @code{volatile} after the @code{asm}. For
2337: example:
2338:
2339: @example
2340: #define set_priority(x) \
2341: asm volatile ("set_priority %0": /* no outputs */ : "g" (x))
2342: @end example
2343:
1.1.1.4 ! root 2344: If there are no output operands, the instruction will not be deleted or
! 2345: moved.
! 2346:
1.1 root 2347: It is a natural idea to look for a way to give access to the condition
2348: code left by the assembler instruction. However, when we attempted to
2349: implement this, we found no way to make it work reliably. The problem
2350: is that output operands might need reloading, which would result in
2351: additional following ``store'' instructions. On most machines, these
2352: instructions would alter the condition code before there was time to
2353: test it. This problem doesn't arise for ordinary ``test'' and
2354: ``compare'' instructions because they don't have any output operands.
2355:
2356: @node Asm Labels,,Extended Asm, Extensions
2357: @section Controlling Names Used in Assembler Code
2358:
2359: You can specify the name to be used in the assembler code for a C function
2360: or variable by writing the @code{asm} keyword after the declarator as
2361: follows:
2362:
2363: @example
2364: int foo asm ("myfoo") = 2;
2365: @end example
2366:
2367: @noindent
2368: This specifies that the name to be used for the variable @code{foo} in
2369: the assembler code should be @samp{myfoo} rather than the usual
2370: @samp{_foo}.
2371:
2372: On systems where an underscore is normally prepended to the name of a C
2373: function or variable, this feature allows you to define names for the
2374: linker that do not start with an underscore.
2375:
2376: You cannot use @code{asm} in this way in a function @emph{definition}; but
2377: you can get the same effect by writing a declaration for the function
2378: before its definition and putting @code{asm} there, like this:
2379:
2380: @example
2381: extern func () asm ("FUNC");
2382:
2383: func (x, y)
2384: int x, y;
2385: @dots{}
2386: @end example
2387:
2388: It is up to you to make sure that the assembler names you choose do not
2389: conflict with any other assembler symbols. Also, you must not use a
2390: register name; that would produce completely invalid assembler code. GNU
2391: CC does not as yet have the ability to store static variables in registers.
2392: Perhaps that will be added.
2393:
2394: @node Bugs, Portability, Extensions, Top
2395: @chapter Reporting Bugs
2396:
2397: Your bug reports play an essential role in making GNU CC reliable.
2398:
2399: Reporting a bug may help you by bringing a solution to your problem, or it
2400: may not. But in any case the important function of a bug report is to help
2401: the entire community by making the next version of GNU CC work better. Bug
2402: reports are your contribution to the maintenance of GNU CC.
2403:
2404: In order for a bug report to serve its purpose, you must include the
2405: information that makes for fixing the bug.
2406:
2407: @menu
2408: * Criteria: Bug Criteria. Have you really found a bug?
2409: * Reporting: Bug Reporting. How to report a bug effectively.
2410: @end menu
2411:
2412: @node Bug Criteria, Bug Reporting, Bugs, Bugs
2413: @section Have You Found a Bug?
2414:
2415: If you are not sure whether you have found a bug, here are some guidelines:
2416:
2417: @itemize @bullet
2418: @item
2419: If the compiler gets a fatal signal, for any input whatever, that is a
2420: compiler bug. Reliable compilers never crash.
2421:
2422: @item
2423: If the compiler produces invalid assembly code, for any input whatever
2424: (except an @code{asm} statement), that is a compiler bug, unless the
2425: compiler reports errors (not just warnings) which would ordinarily
2426: prevent the assembler from being run.
2427:
2428: @item
2429: If the compiler produces valid assembly code that does not correctly
2430: execute the input source code, that is a compiler bug.
2431:
2432: However, you must double-check to make sure, because you may have run
2433: into an incompatibility between GNU C and traditional C
2434: (@pxref{Incompatibilities}). These incompatibilities might be considered
2435: bugs, but they are inescapable consequences of valuable features.
2436:
2437: Or you may have a program whose behavior is undefined, which happened
2438: by chance to give the desired results with another C compiler.
2439:
2440: For example, in many nonoptimizing compilers, you can write @samp{x;}
2441: at the end of a function instead of @samp{return x;}, with the same
2442: results. But the value of the function is undefined if @samp{return}
2443: is omitted; it is not a bug when GNU CC produces different results.
2444:
2445: Problems often result from expressions with two increment operators,
2446: as in @samp{f (*p++, *p++)}. Your previous compiler might have
2447: interpreted that expression the way you intended; GNU CC might
2448: interpret it another way; neither compiler is wrong.
2449:
2450: After you have localized the error to a single source line, it should
2451: be easy to check for these things. If your program is correct and
2452: well defined, you have found a compiler bug.
2453:
2454: @item
2455: If the compiler produces an error message for valid input, that is a
2456: compiler bug.
2457:
2458: Note that the following is not valid input, and the error message for
2459: it is not a bug:
2460:
2461: @example
2462: int foo (char);
2463:
2464: int
2465: foo (x)
2466: char x;
2467: @{ @dots{} @}
2468: @end example
2469:
2470: @noindent
2471: The prototype says to pass a @code{char}, while the definition says to
2472: pass an @code{int} and treat the value as a @code{char}. This is what
2473: the ANSI standard says, and it makes sense.
2474:
2475: @item
2476: If the compiler does not produce an error message for invalid input,
2477: that is a compiler bug. However, you should note that your idea of
2478: ``invalid input'' might be my idea of ``an extension'' or ``support
2479: for traditional practice''.
2480:
2481: @item
2482: If you are an experienced user of C compilers, your suggestions
2483: for improvement of GNU CC are welcome in any case.
2484: @end itemize
2485:
2486: @node Bug Reporting,, Bug Criteria, Bugs
2487: @section How to Report Bugs
2488:
2489: Send bug reports for GNU C to one of these addresses:
2490:
2491: @example
2492: bug-gcc@@prep.ai.mit.edu
2493: @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gcc
2494: @end example
2495:
2496: As a last resort, snail them to:
2497:
2498: @example
2499: GNU Compiler Bugs
2500: 545 Tech Sq
2501: Cambridge, MA 02139
2502: @end example
2503:
2504: The fundamental principle of reporting bugs usefully is this:
2505: @strong{report all the facts}. If you are not sure whether to mention a
2506: fact or leave it out, mention it!
2507:
2508: Often people omit facts because they think they know what causes the
2509: problem and they conclude that some details don't matter. Thus, you might
2510: assume that the name of the variable you use in an example does not matter.
2511: Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a
2512: stray memory reference which happens to fetch from the location where that
2513: name is stored in memory; perhaps, if the name were different, the contents
2514: of that location would fool the compiler into doing the right thing despite
2515: the bug. Play it safe and give an exact example.
2516:
2517: If you want to enable me to fix the bug, you should include all these
2518: things:
2519:
2520: @itemize @bullet
2521: @item
2522: The version of GNU CC. You can get this by running it with the
2523: @samp{-v} option.
2524:
2525: Without this, I won't know whether there is any point in looking for
2526: the bug in the current version of GNU CC.
2527:
2528: @item
2529: A complete input file that will reproduce the bug. If the bug is in
2530: the C preprocessor, send me a source file and any header files that it
2531: requires. If the bug is in the compiler proper (@file{cc1}), run your
2532: source file through the C preprocessor by doing @samp{gcc -E
2533: @var{sourcefile} > @var{outfile}}, then include the contents of
2534: @var{outfile} in the bug report. (Any @samp{-I}, @samp{-D} or
2535: @samp{-U} options that you used in actual compilation should also be
2536: used when doing this.)
2537:
2538: A single statement is not enough of an example. In order to compile
2539: it, it must be embedded in a function definition; and the bug might
2540: depend on the details of how this is done.
2541:
2542: Without a real example I can compile, all I can do about your bug
2543: report is wish you luck. It would be futile to try to guess how to
2544: provoke the bug. For example, bugs in register allocation and
2545: reloading frequently depend on every little detail of the function
2546: they happen in.
2547:
2548: @item
2549: The command arguments you gave GNU CC to compile that example and
2550: observe the bug. For example, did you use @samp{-O}? To guarantee
2551: you won't omit something important, list them all.
2552:
2553: If I were to try to guess the arguments, I would probably guess wrong
2554: and then I would not encounter the bug.
2555:
2556: @item
2557: The names of the files that you used for @file{tm.h} and @file{md}
2558: when you installed the compiler.
2559:
2560: @item
2561: The type of machine you are using, and the operating system name and
2562: version number.
2563:
2564: @item
2565: A description of what behavior you observe that you believe is
2566: incorrect. For example, ``It gets a fatal signal,'' or, ``There is an
2567: incorrect assembler instruction in the output.''
2568:
2569: Of course, if the bug is that the compiler gets a fatal signal, then I
2570: will certainly notice it. But if the bug is incorrect output, I might
2571: not notice unless it is glaringly wrong. I won't study all the
2572: assembler code from a 50-line C program just on the off chance that it
2573: might be wrong.
2574:
2575: Even if the problem you experience is a fatal signal, you should still
2576: say so explicitly. Suppose something strange is going on, such as,
2577: your copy of the compiler is out of synch, or you have encountered a
2578: bug in the C library on your system. (This has happened!) Your copy
2579: might crash and mine would not. If you @i{told} me to expect a crash,
2580: then when mine fails to crash, I would know that the bug was not
2581: happening for me. If you had not told me to expect a crash, then I
2582: would not be able to draw any conclusion from my observations.
2583:
2584: In cases where GNU CC generates incorrect code, if you send me a small
2585: complete sample program I will find the error myself by running the
2586: program under a debugger. If you send me a large example or a part of
2587: a larger program, I cannot do this; you must debug the compiled
2588: program and narrow the problem down to one source line. Tell me which
2589: source line it is, and what you believe is incorrect about the code
2590: generated for that line.
2591:
2592: @item
2593: If you send me examples of output from GNU CC, please use @samp{-g}
2594: when you make them. The debugging information includes source line
2595: numbers which are essential for correlating the output with the input.
2596:
2597: @item
2598: If you wish to suggest changes to the GNU CC source, send me context
2599: diffs. If you even discuss something in the GNU CC source, refer to
2600: it by context, not by line number.
2601:
2602: The line numbers in my development sources don't match those in your
2603: sources. Your line numbers would convey no useful information to me.
2604:
2605: @item
2606: Additional information from a debugger might enable me to find
2607: a problem on a machine which I do not have available myself.
2608: However, you need to think when you collect this information if
2609: you want it to have any chance of being useful.
2610:
2611: For example, many people send just a backtrace, but that is never
2612: useful by itself. A simple backtrace with arguments conveys little
2613: about GNU CC because the compiler is largely data-driven; the same
2614: functions are called over and over for different RTL insns, doing
2615: different things depending on the details of the insn.
2616:
2617: Most of the arguments listed in the backtrace are useless because they
2618: are pointers to RTL list structure. The numeric values of the
2619: pointers, which the debugger prints in the backtrace, have no
2620: significance whatever; all that matters is the contents of the objects
2621: they point to (and most of the contents are other such pointers).
2622:
2623: In addition, most compiler passes consist of one or more loops that
2624: scan the RTL insn sequence. The most vital piece of information about
2625: such a loop--which insn it has reached--is usually in a local variable,
2626: not in an argument.
2627:
2628: What you need to provide in addition to a backtrace are the values of
2629: the local variables for several stack frames up. When a local
2630: variable or an argument is an RTX, first print its value and then use
2631: the GDB command @code{pr} to print the RTL expression that it points
2632: to. (If GDB doesn't run on your machine, use your debugger to call
2633: the function @code{debug_rtx} with the RTX as an argument.) In
2634: general, whenever a variable is a pointer, its value is no use
2635: without the data it points to.
2636:
2637: In addition, include a debugging dump from just before the pass
2638: in which the crash happens. Most bugs involve a series of insns,
2639: not just one.
2640: @end itemize
2641:
2642: Here are some things that are not necessary:
2643:
2644: @itemize @bullet
2645: @item
2646: A description of the envelope of the bug.
2647:
2648: Often people who encounter a bug spend a lot of time investigating
2649: which changes to the input file will make the bug go away and which
2650: changes will not affect it.
2651:
2652: This is often time consuming and not very useful, because the way I
2653: will find the bug is by running a single example under the debugger
2654: with breakpoints, not by pure deduction from a series of examples.
2655:
2656: Of course, if you can find a simpler example to report @emph{instead}
2657: of the original one, that is a convenience for me. Errors in the
2658: output will be easier to spot, running under the debugger will take
2659: less time, etc. Most GNU CC bugs involve just one function, so the
2660: most straightforward way to simplify an example is to delete all the
2661: function definitions except the one where the bug occurs. Those
2662: earlier in the file may be replaced by external declarations if the
2663: crucial function depends on them.
2664:
2665: However, simplification is not vital; if you don't want to do this,
2666: report the bug anyway.
2667:
2668: @item
2669: A patch for the bug.
2670:
2671: A patch for the bug does help me if it is a good one. But don't omit
2672: the necessary information, such as the test case, because I might see
2673: problems with your patch and decide to fix the problem another way.
2674:
2675: Sometimes with a program as complicated as GNU CC it is very hard to
2676: construct an example that will make the program follow a certain path
2677: through the code. If you don't send me the example, I won't be able
2678: to construct one, so I won't be able to verify that the bug is fixed.
2679:
2680: @item
2681: A guess about what the bug is or what it depends on.
2682:
2683: Such guesses are usually wrong. Even I can't guess right about such
2684: things without using the debugger to find the facts.
2685: @end itemize
2686:
2687: @node Portability, Interface, Bugs, Top
2688: @chapter GNU CC and Portability
2689:
2690: The main goal of GNU CC was to make a good, fast compiler for machines in
2691: the class that the GNU system aims to run on: 32-bit machines that address
2692: 8-bit bytes and have several general registers. Elegance, theoretical
2693: power and simplicity are only secondary.
2694:
2695: GNU CC gets most of the information about the target machine from a machine
2696: description which gives an algebraic formula for each of the machine's
2697: instructions. This is a very clean way to describe the target. But when
2698: the compiler needs information that is difficult to express in this
2699: fashion, I have not hesitated to define an ad-hoc parameter to the machine
2700: description. The purpose of portability is to reduce the total work needed
2701: on the compiler; it was not of interest for its own sake.
2702:
2703: GNU CC does not contain machine dependent code, but it does contain code
2704: that depends on machine parameters such as endianness (whether the most
2705: significant byte has the highest or lowest address of the bytes in a word)
2706: and the availability of autoincrement addressing. In the RTL-generation
2707: pass, it is often necessary to have multiple strategies for generating code
2708: for a particular kind of syntax tree, strategies that are usable for different
2709: combinations of parameters. Often I have not tried to address all possible
2710: cases, but only the common ones or only the ones that I have encountered.
2711: As a result, a new target may require additional strategies. You will know
2712: if this happens because the compiler will call @code{abort}. Fortunately,
2713: the new strategies can be added in a machine-independent fashion, and will
2714: affect only the target machines that need them.
2715:
2716: @node Interface, Passes, Portability, Top
2717: @chapter Interfacing to GNU CC Output
2718:
2719: GNU CC is normally configured to use the same function calling convention
2720: normally in use on the target system. This is done with the
2721: machine-description macros described (@pxref{Machine Macros}).
2722:
2723: However, returning of structure and union values is done differently on
2724: some target machines. As a result, functions compiled with PCC
2725: returning such types cannot be called from code compiled with GNU CC,
2726: and vice versa. This does not cause trouble often because few Unix
2727: library routines return structures or unions.
2728:
2729: GNU CC code returns structures and unions that are 1, 2, 4 or 8 bytes
2730: long in the same registers used for @code{int} or @code{double} return
2731: values. (GNU CC typically allocates variables of such types in
2732: registers also.) Structures and unions of other sizes are returned by
2733: storing them into an address passed by the caller (usually in a
2734: register). The machine-description macros @code{STRUCT_VALUE} and
2735: @code{STRUCT_INCOMING_VALUE} tell GNU CC where to pass this address.
2736:
2737: By contrast, PCC on most target machines returns structures and unions
2738: of any size by copying the data into an area of static storage, and then
2739: returning the address of that storage as if it were a pointer value.
2740: The caller must copy the data from that memory area to the place where
2741: the value is wanted. This is slower than the method used by GNU CC, and
2742: fails to be reentrant.
2743:
2744: On some target machines, such as RISC machines and the 80386, the
2745: standard system convention is to pass to the subroutine the address of
2746: where to return the value. On these machines, GNU CC has been
2747: configured to be compatible with the standard compiler, when this method
2748: is used. It may not be compatible for structures of 1, 2, 4 or 8 bytes.
2749:
2750: GNU CC uses the system's standard convention for passing arguments. On
2751: some machines, the first few arguments are passed in registers; in
2752: others, all are passed on the stack. It would be possible to use
2753: registers for argument passing on any machine, and this would probably
2754: result in a significant speedup. But the result would be complete
2755: incompatibility with code that follows the standard convention. So this
2756: change is practical only if you are switching to GNU CC as the sole C
2757: compiler for the system. We may implement register argument passing on
2758: certain machines once we have a complete GNU system so that we can
2759: compile the libraries with GNU CC.
2760:
2761: If you use @code{longjmp}, beware of automatic variables. ANSI C says that
2762: automatic variables that are not declared @code{volatile} have undefined
2763: values after a @code{longjmp}. And this is all GNU CC promises to do,
2764: because it is very difficult to restore register variables correctly, and
2765: one of GNU CC's features is that it can put variables in registers without
2766: your asking it to.
2767:
2768: If you want a variable to be unaltered by @code{longjmp}, and you don't
2769: want to write @code{volatile} because old C compilers don't accept it,
2770: just take the address of the variable. If a variable's address is ever
2771: taken, even if just to compute it and ignore it, then the variable cannot
2772: go in a register:
2773:
2774: @example
2775: @{
2776: int careful;
2777: &careful;
2778: @dots{}
2779: @}
2780: @end example
2781:
2782: Code compiled with GNU CC may call certain library routines. Most of
2783: them handle arithmetic for which there are no instructions. This
2784: includes multiply and divide on some machines, and floating point
2785: operations on any machine for which floating point support is disabled
2786: with @samp{-msoft-float}. Some standard parts of the C library, such as
2787: @code{bcopy} or @code{memcpy}, are also called automatically. The usual
2788: function call interface is used for calling the library routines.
2789:
2790: These library routines should be defined in the library @file{gnulib},
2791: which GNU CC automatically searches whenever it links a program. On
2792: machines that have multiply and divide instructions, if hardware
2793: floating point is in use, normally @file{gnulib} is not needed, but it
2794: is searched just in case.
2795:
2796: Each arithmetic function is defined in @file{gnulib.c} to use the
2797: corresponding C arithmetic operator. As long as the file is compiled
2798: with another C compiler, which supports all the C arithmetic operators,
2799: this file will work portably. However, @file{gnulib.c} does not work if
2800: compiled with GNU CC, because each arithmetic function would compile
2801: into a call to itself!
2802:
2803: @node Passes, RTL, Interface, Top
2804: @chapter Passes and Files of the Compiler
2805:
2806: The overall control structure of the compiler is in @file{toplev.c}. This
2807: file is responsible for initialization, decoding arguments, opening and
2808: closing files, and sequencing the passes.
2809:
2810: The parsing pass is invoked only once, to parse the entire input. The RTL
2811: intermediate code for a function is generated as the function is parsed, a
2812: statement at a time. Each statement is read in as a syntax tree and then
2813: converted to RTL; then the storage for the tree for the statement is
2814: reclaimed. Storage for types (and the expressions for their sizes),
2815: declarations, and a representation of the binding contours and how they nest,
2816: remains until the function is finished being compiled; these are all needed
2817: to output the debugging information.
2818:
2819: Each time the parsing pass reads a complete function definition or
2820: top-level declaration, it calls the function
2821: @code{rest_of_compilation} or @code{rest_of_decl_compilation} in
2822: @file{toplev.c}, which are responsible for all further processing
2823: necessary, ending with output of the assembler language. All other
2824: compiler passes run, in sequence, within @code{rest_of_compilation}.
2825: When that function returns from compiling a function definition, the
2826: storage used for that function definition's compilation is entirely
2827: freed, unless it is an inline function (@pxref{Inline}).
2828:
2829: Here is a list of all the passes of the compiler and their source files.
2830: Also included is a description of where debugging dumps can be requested
2831: with @samp{-d} options.
2832:
2833: @itemize @bullet
2834: @item
2835: Parsing. This pass reads the entire text of a function definition,
2836: constructing partial syntax trees. This and RTL generation are no longer
2837: truly separate passes (formerly they were), but it is easier to think
2838: of them as separate.
2839:
2840: The tree representation does not entirely follow C syntax, because it is
2841: intended to support other languages as well.
2842:
2843: C data type analysis is also done in this pass, and every tree node
2844: that represents an expression has a data type attached. Variables are
2845: represented as declaration nodes.
2846:
2847: Constant folding and associative-law simplifications are also done
2848: during this pass.
2849:
2850: The source files for parsing are @file{c-parse.y}, @file{c-decl.c},
2851: @file{c-typeck.c}, @file{c-convert.c}, @file{stor-layout.c},
2852: @file{fold-const.c}, and @file{tree.c}. The last three files are
2853: intended to be language-independent. There are also header files
2854: @file{c-parse.h}, @file{c-tree.h}, @file{tree.h} and @file{tree.def}.
2855: The last two define the format of the tree representation.@refill
2856:
2857: @item
2858: RTL generation. This is the conversion of syntax tree into RTL code.
2859: It is actually done statement-by-statement during parsing, but for
2860: most purposes it can be thought of as a separate pass.
2861:
2862: This is where the bulk of target-parameter-dependent code is found,
2863: since often it is necessary for strategies to apply only when certain
2864: standard kinds of instructions are available. The purpose of named
2865: instruction patterns is to provide this information to the RTL
2866: generation pass.
2867:
2868: Optimization is done in this pass for @code{if}-conditions that are
2869: comparisons, boolean operations or conditional expressions. Tail
2870: recursion is detected at this time also. Decisions are made about how
2871: best to arrange loops and how to output @code{switch} statements.
2872:
2873: The source files for RTL generation are @file{stmt.c}, @file{expr.c},
2874: @file{explow.c}, @file{expmed.c}, @file{optabs.c} and @file{emit-rtl.c}.
2875: Also, the file @file{insn-emit.c}, generated from the machine description
2876: by the program @code{genemit}, is used in this pass. The header files
2877: @file{expr.h} is used for communication within this pass.@refill
2878:
2879: The header files @file{insn-flags.h} and @file{insn-codes.h},
2880: generated from the machine description by the programs @code{genflags}
2881: and @code{gencodes}, tell this pass which standard names are available
2882: for use and which patterns correspond to them.@refill
2883:
2884: Aside from debugging information output, none of the following passes
2885: refers to the tree structure representation of the function (only
2886: part of which is saved).
2887:
2888: The decision of whether the function can and should be expanded inline
2889: in its subsequent callers is made at the end of rtl generation. The
2890: function must meet certain criteria, currently related to the size of
2891: the function and the types and number of parameters it has. Note that
2892: this function may contain loops, recursive calls to itself
2893: (tail-recursive functions can be inlined!), gotos, in short, all
2894: constructs supported by GNU CC.
2895:
2896: The option @samp{-dr} causes a debugging dump of the RTL code after
2897: this pass. This dump file's name is made by appending @samp{.rtl} to
2898: the input file name.
2899:
2900: @item
2901: Jump optimization. This pass simplifies jumps to the following
2902: instruction, jumps across jumps, and jumps to jumps. It deletes
2903: unreferenced labels and unreachable code, except that unreachable code
2904: that contains a loop is not recognized as unreachable in this pass.
2905: (Such loops are deleted later in the basic block analysis.)
2906:
2907: Jump optimization is performed two or three times. The first time is
2908: immediately following RTL generation. The second time is after CSE,
2909: but only if CSE says repeated jump optimization is needed. The
2910: last time is right before the final pass. That time, cross-jumping
2911: and deletion of no-op move instructions are done together with the
2912: optimizations described above.
2913:
2914: The source file of this pass is @file{jump.c}.
2915:
2916: The option @samp{-dj} causes a debugging dump of the RTL code after
2917: this pass is run for the first time. This dump file's name is made by
2918: appending @samp{.jump} to the input file name.
2919:
2920: @item
2921: Register scan. This pass finds the first and last use of each
2922: register, as a guide for common subexpression elimination. Its source
2923: is in @file{regclass.c}.
2924:
2925: @item
2926: Common subexpression elimination. This pass also does constant
2927: propagation. Its source file is @file{cse.c}. If constant
2928: propagation causes conditional jumps to become unconditional or to
2929: become no-ops, jump optimization is run again when CSE is finished.
2930:
2931: The option @samp{-ds} causes a debugging dump of the RTL code after
2932: this pass. This dump file's name is made by appending @samp{.cse} to
2933: the input file name.
2934:
2935: @item
2936: Loop optimization. This pass moves constant expressions out of loops.
2937: Its source file is @file{loop.c}.
2938:
2939: The option @samp{-dL} causes a debugging dump of the RTL code after
2940: this pass. This dump file's name is made by appending @samp{.loop} to
2941: the input file name.
2942:
2943: @item
2944: Stupid register allocation is performed at this point in a
2945: nonoptimizing compilation. It does a little data flow analysis as
2946: well. When stupid register allocation is in use, the next pass
2947: executed is the reloading pass; the others in between are skipped.
2948: The source file is @file{stupid.c}.
2949:
2950: @item
2951: Data flow analysis (@file{flow.c}). This pass divides the program
2952: into basic blocks (and in the process deletes unreachable loops); then
2953: it computes which pseudo-registers are live at each point in the
2954: program, and makes the first instruction that uses a value point at
2955: the instruction that computed the value.
2956:
2957: This pass also deletes computations whose results are never used, and
2958: combines memory references with add or subtract instructions to make
2959: autoincrement or autodecrement addressing.
2960:
2961: The option @samp{-df} causes a debugging dump of the RTL code after
2962: this pass. This dump file's name is made by appending @samp{.flow} to
2963: the input file name. If stupid register allocation is in use, this
2964: dump file reflects the full results of such allocation.
2965:
2966: @item
2967: Instruction combination (@file{combine.c}). This pass attempts to
2968: combine groups of two or three instructions that are related by data
2969: flow into single instructions. It combines the RTL expressions for
2970: the instructions by substitution, simplifies the result using algebra,
2971: and then attempts to match the result against the machine description.
2972:
2973: The option @samp{-dc} causes a debugging dump of the RTL code after
2974: this pass. This dump file's name is made by appending @samp{.combine}
2975: to the input file name.
2976:
2977: @item
2978: Register class preferencing. The RTL code is scanned to find out
2979: which register class is best for each pseudo register. The source
2980: file is @file{regclass.c}.
2981:
2982: @item
2983: Local register allocation (@file{local-alloc.c}). This pass allocates
2984: hard registers to pseudo registers that are used only within one basic
2985: block. Because the basic block is linear, it can use fast and
2986: powerful techniques to do a very good job.
2987:
2988: The option @samp{-dl} causes a debugging dump of the RTL code after
2989: this pass. This dump file's name is made by appending @samp{.lreg} to
2990: the input file name.
2991:
2992: @item
2993: Global register allocation (@file{global-alloc.c}). This pass
2994: allocates hard registers for the remaining pseudo registers (those
2995: whose life spans are not contained in one basic block).
2996:
2997: @item
2998: Reloading. This pass renumbers pseudo registers with the hardware
2999: registers numbers they were allocated. Pseudo registers that did not
3000: get hard registers are replaced with stack slots. Then it finds
3001: instructions that are invalid because a value has failed to end up in
3002: a register, or has ended up in a register of the wrong kind. It fixes
3003: up these instructions by reloading the problematical values
3004: temporarily into registers. Additional instructions are generated to
3005: do the copying.
3006:
3007: Source files are @file{reload.c} and @file{reload1.c}, plus the header
3008: @file{reload.h} used for communication between them.
3009:
3010: The option @samp{-dg} causes a debugging dump of the RTL code after
3011: this pass. This dump file's name is made by appending @samp{.greg} to
3012: the input file name.
3013:
3014: @item
3015: Jump optimization is repeated, this time including cross-jumping
3016: and deletion of no-op move instructions. Machine-specific peephole
3017: optimizations are performed at the same time.
3018:
3019: The option @samp{-dJ} causes a debugging dump of the RTL code after
3020: this pass. This dump file's name is made by appending @samp{.jump2}
3021: to the input file name.
3022:
3023: @item
3024: Final. This pass outputs the assembler code for the function. It is
3025: also responsible for identifying spurious test and compare
3026: instructions. The function entry and exit sequences are generated
3027: directly as assembler code in this pass; they never exist as RTL.
3028:
3029: The source files are @file{final.c} plus @file{insn-output.c}; the
3030: latter is generated automatically from the machine description by the
3031: tool @file{genoutput}. The header file @file{conditions.h} is used
3032: for communication between these files.
3033:
3034: @item
3035: Debugging information output. This is run after final because it must
3036: output the stack slot offsets for pseudo registers that did not get
3037: hard registers. Source files are @file{dbxout.c} for DBX symbol table
3038: format and @file{symout.c} for GDB's own symbol table format.
3039: @end itemize
3040:
3041: Some additional files are used by all or many passes:
3042:
3043: @itemize @bullet
3044: @item
3045: Every pass uses @file{machmode.def}, which defines the machine modes.
3046:
3047: @item
3048: All the passes that work with RTL use the header files @file{rtl.h}
3049: and @file{rtl.def}, and subroutines in file @file{rtl.c}. The tools
3050: @code{gen*} also use these files to read and work with the machine
3051: description RTL.
3052:
3053: @item
3054: Several passes refer to the header file @file{insn-config.h} which
3055: contains a few parameters (C macro definitions) generated
3056: automatically from the machine description RTL by the tool
3057: @code{genconfig}.
3058:
3059: @item
3060: Several passes use the instruction recognizer, which consists of
3061: @file{recog.c} and @file{recog.h}, plus the files @file{insn-recog.c}
3062: and @file{insn-extract.c} that are generated automatically from the
3063: machine description by the tools @file{genrecog} and
3064: @file{genextract}.@refill
3065:
3066: @item
3067: Several passes use the header files @file{regs.h} which defines the
3068: information recorded about pseudo register usage, and @file{basic-block.h}
3069: which defines the information recorded about basic blocks.
3070:
3071: @item
3072: @file{hard-reg-set.h} defines the type @code{HARD_REG_SET}, a bit-vector
3073: with a bit for each hard register, and some macros to manipulate it.
3074: This type is just @code{int} if the machine has few enough hard registers;
3075: otherwise it is an array of @code{int} and some of the macros expand
3076: into loops.
3077: @end itemize
3078:
3079: @node RTL, Machine Desc, Passes, Top
3080: @chapter RTL Representation
3081:
3082: Most of the work of the compiler is done on an intermediate representation
3083: called register transfer language. In this language, the instructions to be
3084: output are described, pretty much one by one, in an algebraic form that
3085: describes what the instruction does.
3086:
3087: RTL is inspired by Lisp lists. It has both an internal form, made up of
3088: structures that point at other structures, and a textual form that is used
3089: in the machine description and in printed debugging dumps. The textual
3090: form uses nested parentheses to indicate the pointers in the internal form.
3091:
3092: @menu
3093: * RTL Objects:: Expressions vs vectors vs strings vs integers.
3094: * Accessors:: Macros to access expression operands or vector elts.
3095: * Flags:: Other flags in an RTL expression.
3096: * Machine Modes:: Describing the size and format of a datum.
3097: * Constants:: Expressions with constant values.
3098: * Regs and Memory:: Expressions representing register contents or memory.
3099: * Arithmetic:: Expressions representing arithmetic on other expressions.
3100: * Comparisons:: Expressions representing comparison of expressions.
3101: * Bit Fields:: Expressions representing bit-fields in memory or reg.
3102: * Conversions:: Extending, truncating, floating or fixing.
3103: * RTL Declarations:: Declaring volatility, constancy, etc.
3104: * Side Effects:: Expressions for storing in registers, etc.
3105: * Incdec:: Embedded side-effects for autoincrement addressing.
3106: * Assembler:: Representing @code{asm} with operands.
3107: * Insns:: Expression types for entire insns.
3108: * Calls:: RTL representation of function call insns.
3109: * Sharing:: Some expressions are unique; others *must* be copied.
3110: @end menu
3111:
3112: @node RTL Objects, Accessors, RTL, RTL
3113: @section RTL Object Types
3114:
3115: RTL uses four kinds of objects: expressions, integers, strings and vectors.
3116: Expressions are the most important ones. An RTL expression (``RTX'', for
3117: short) is a C structure, but it is usually referred to with a pointer; a
3118: type that is given the typedef name @code{rtx}.
3119:
3120: An integer is simply an @code{int}, and a string is a @code{char *}.
3121: Within RTL code, strings appear only inside @samp{symbol_ref} expressions,
3122: but they appear in other contexts in the RTL expressions that make up
3123: machine descriptions. Their written form uses decimal digits.
3124:
3125: A string is a sequence of characters. In core it is represented as a
3126: @code{char *} in usual C fashion, and it is written in C syntax as well.
3127: However, strings in RTL may never be null. If you write an empty string in
3128: a machine description, it is represented in core as a null pointer rather
3129: than as a pointer to a null character. In certain contexts, these null
3130: pointers instead of strings are valid.
3131:
3132: A vector contains an arbitrary, specified number of pointers to
3133: expressions. The number of elements in the vector is explicitly present in
3134: the vector. The written form of a vector consists of square brackets
3135: (@samp{[@dots{}]}) surrounding the elements, in sequence and with
3136: whitespace separating them. Vectors of length zero are not created; null
3137: pointers are used instead.
3138:
3139: Expressions are classified by @dfn{expression codes} (also called RTX
3140: codes). The expression code is a name defined in @file{rtl.def}, which is
3141: also (in upper case) a C enumeration constant. The possible expression
3142: codes and their meanings are machine-independent. The code of an RTX can
3143: be extracted with the macro @code{GET_CODE (@var{x})} and altered with
3144: @code{PUT_CODE (@var{x}, @var{newcode})}.
3145:
3146: The expression code determines how many operands the expression contains,
3147: and what kinds of objects they are. In RTL, unlike Lisp, you cannot tell
3148: by looking at an operand what kind of object it is. Instead, you must know
3149: from its context---from the expression code of the containing expression.
3150: For example, in an expression of code @samp{subreg}, the first operand is
3151: to be regarded as an expression and the second operand as an integer. In
3152: an expression of code @samp{plus}, there are two operands, both of which
3153: are to be regarded as expressions. In a @samp{symbol_ref} expression,
3154: there is one operand, which is to be regarded as a string.
3155:
3156: Expressions are written as parentheses containing the name of the
3157: expression type, its flags and machine mode if any, and then the operands
3158: of the expression (separated by spaces).
3159:
3160: Expression code names in the @samp{md} file are written in lower case,
3161: but when they appear in C code they are written in upper case. In this
3162: manual, they are shown as follows: @samp{const_int}.
3163:
3164: In a few contexts a null pointer is valid where an expression is normally
1.1.1.4 ! root 3165: wanted. The written form of this is @code{(nil)}.
1.1 root 3166:
3167: @node Accessors, Flags, RTL Objects, RTL
3168: @section Access to Operands
3169:
3170: For each expression type @file{rtl.def} specifies the number of contained
3171: objects and their kinds, with four possibilities: @samp{e} for expression
3172: (actually a pointer to an expression), @samp{i} for integer, @samp{s} for
3173: string, and @samp{E} for vector of expressions. The sequence of letters
3174: for an expression code is called its @dfn{format}. Thus, the format of
3175: @samp{subreg} is @samp{ei}.@refill
3176:
3177: Two other format characters are used occasionally: @samp{u} and @samp{0}.
3178: @samp{u} is equivalent to @samp{e} except that it is printed differently in
3179: debugging dumps, and @samp{0} means a slot whose contents do not fit any
3180: normal category. @samp{0} slots are not printed at all in dumps, and are
3181: often used in special ways by small parts of the compiler.@refill
3182:
3183: There are macros to get the number of operands and the format of an
3184: expression code:
3185:
3186: @table @code
3187: @item GET_RTX_LENGTH (@var{code})
3188: Number of operands of an RTX of code @var{code}.
3189:
3190: @item GET_RTX_FORMAT (@var{code})
3191: The format of an RTX of code @var{code}, as a C string.
3192: @end table
3193:
3194: Operands of expressions are accessed using the macros @code{XEXP},
3195: @code{XINT} and @code{XSTR}. Each of these macros takes two arguments: an
3196: expression-pointer (RTX) and an operand number (counting from zero).
3197: Thus,@refill
3198:
3199: @example
3200: XEXP (@var{x}, 2)
3201: @end example
3202:
3203: @noindent
3204: accesses operand 2 of expression @var{x}, as an expression.
3205:
3206: @example
3207: XINT (@var{x}, 2)
3208: @end example
3209:
3210: @noindent
3211: accesses the same operand as an integer. @code{XSTR}, used in the same
3212: fashion, would access it as a string.
3213:
3214: Any operand can be accessed as an integer, as an expression or as a string.
3215: You must choose the correct method of access for the kind of value actually
3216: stored in the operand. You would do this based on the expression code of
3217: the containing expression. That is also how you would know how many
3218: operands there are.
3219:
3220: For example, if @var{x} is a @samp{subreg} expression, you know that it has
3221: two operands which can be correctly accessed as @code{XEXP (@var{x}, 0)}
3222: and @code{XINT (@var{x}, 1)}. If you did @code{XINT (@var{x}, 0)}, you
3223: would get the address of the expression operand but cast as an integer;
3224: that might occasionally be useful, but it would be cleaner to write
3225: @code{(int) XEXP (@var{x}, 0)}. @code{XEXP (@var{x}, 1)} would also
3226: compile without error, and would return the second, integer operand cast as
3227: an expression pointer, which would probably result in a crash when
3228: accessed. Nothing stops you from writing @code{XEXP (@var{x}, 28)} either,
3229: but this will access memory past the end of the expression with
3230: unpredictable results.@refill
3231:
3232: Access to operands which are vectors is more complicated. You can use the
3233: macro @code{XVEC} to get the vector-pointer itself, or the macros
3234: @code{XVECEXP} and @code{XVECLEN} to access the elements and length of a
3235: vector.
3236:
3237: @table @code
3238: @item XVEC (@var{exp}, @var{idx})
3239: Access the vector-pointer which is operand number @var{idx} in @var{exp}.
3240:
3241: @item XVECLEN (@var{exp}, @var{idx})
3242: Access the length (number of elements) in the vector which is
3243: in operand number @var{idx} in @var{exp}. This value is an @code{int}.
3244:
3245: @item XVECEXP (@var{exp}, @var{idx}, @var{eltnum})
3246: Access element number @var{eltnum} in the vector which is
3247: in operand number @var{idx} in @var{exp}. This value is an RTX.
3248:
3249: It is up to you to make sure that @var{eltnum} is not negative
3250: and is less than @code{XVECLEN (@var{exp}, @var{idx})}.
3251: @end table
3252:
3253: All the macros defined in this section expand into lvalues and therefore
3254: can be used to assign the operands, lengths and vector elements as well as
3255: to access them.
3256:
3257: @node Flags, Machine Modes, Accessors, RTL
3258: @section Flags in an RTL Expression
3259:
3260: RTL expressions contain several flags (one-bit bit-fields) that are used
3261: in certain types of expression. Most often they are accessed with the
3262: following macros:
3263:
3264: @table @code
3265: @item MEM_VOLATILE_P (@var{x})
3266: In @samp{mem} expressions, nonzero for volatile memory references.
3267: Stored in the @code{volatil} field and printed as @samp{/v}.
3268:
3269: @item MEM_IN_STRUCT_P (@var{x})
3270: In @samp{mem} expressions, nonzero for reference to an entire
3271: structure, union or array, or to a component of one. Zero for
3272: references to a scalar variable or through a pointer to a scalar.
3273: Stored in the @code{in_struct} field and printed as @samp{/s}.
3274:
3275: @item REG_USER_VAR_P (@var{x})
3276: In a @samp{reg}, nonzero if it corresponds to a variable present in
3277: the user's source code. Zero for temporaries generated internally by
3278: the compiler. Stored in the @code{volatil} field and printed as
3279: @samp{/v}.
3280:
3281: @item REG_FUNCTION_VALUE_P (@var{x})
3282: Nonzero in a @samp{reg} if it is the place in which this function's
3283: value is going to be returned. (This happens only in a hard
3284: register.) Stored in the @code{integrated} field and printed as
3285: @samp{/i}.
3286:
3287: The same hard register may be used also for collecting the values of
3288: functions called by this one, but @code{REG_FUNCTION_VALUE_P} is zero
3289: in this kind of use.
3290:
3291: @item RTX_UNCHANGING_P (@var{x})
3292: Nonzero in a @samp{reg} or @samp{mem} if the value is not changed
3293: explicitly by the current function. (If it is a memory reference then
3294: it may be changed by other functions or by aliasing.) Stored in the
3295: @code{unchanging} field and printed as @samp{/u}.
3296:
3297: @item RTX_INTEGRATED_P (@var{insn})
3298: Nonzero in an insn if it resulted from an in-line function call.
3299: Stored in the @code{integrated} field and printed as @samp{/i}. This
3300: may be deleted; nothing currently depends on it.
3301:
3302: @item INSN_DELETED_P (@var{insn})
3303: In an insn, nonzero if the insn has been deleted. Stored in the
3304: @code{volatil} field and printed as @samp{/v}.
3305:
3306: @item CONSTANT_POOL_ADDRESS_P (@var{x})
3307: Nonzero in a @samp{symbol_ref} if it refers to part of the current
3308: function's ``constants pool''. These are addresses close to the
3309: beginning of the function, and GNU CC assumes they can be addressed
3310: directly (perhaps with the help of base registers). Stored in the
3311: @code{unchanging} field and printed as @samp{/u}.
3312: @end table
3313:
3314: These are the fields which the above macros refer to:
3315:
3316: @table @code
3317: @item used
3318: This flag is used only momentarily, at the end of RTL generation for a
3319: function, to count the number of times an expression appears in insns.
3320: Expressions that appear more than once are copied, according to the
3321: rules for shared structure (@pxref{Sharing}).
3322:
3323: @item volatil
3324: This flag is used in @samp{mem} and @samp{reg} expressions and in insns.
3325: In RTL dump files, it is printed as @samp{/v}.
3326:
3327: In a @samp{mem} expression, it is 1 if the memory reference is volatile.
3328: Volatile memory references may not be deleted, reordered or combined.
3329:
3330: In a @samp{reg} expression, it is 1 if the value is a user-level variable.
3331: 0 indicates an internal compiler temporary.
3332:
3333: In an insn, 1 means the insn has been deleted.
3334:
3335: @item in_struct
3336: This flag is used in @samp{mem} expressions. It is 1 if the memory
3337: datum referred to is all or part of a structure or array; 0 if it is (or
3338: might be) a scalar variable. A reference through a C pointer has 0
3339: because the pointer might point to a scalar variable.
3340:
3341: This information allows the compiler to determine something about possible
3342: cases of aliasing.
3343:
3344: In an RTL dump, this flag is represented as @samp{/s}.
3345:
3346: @item unchanging
3347: This flag is used in @samp{reg} and @samp{mem} expressions. 1 means
3348: that the value of the expression never changes (at least within the
3349: current function).
3350:
3351: In an RTL dump, this flag is represented as @samp{/u}.
3352:
3353: @item integrated
3354: In some kinds of expressions, including insns, this flag means the
3355: rtl was produced by procedure integration.
3356:
3357: In a @samp{reg} expression, this flag indicates the register
3358: containing the value to be returned by the current function. On
3359: machines that pass parameters in registers, the same register number
3360: may be used for parameters as well, but this flag is not set on such
3361: uses.
3362: @end table
3363:
3364: @node Machine Modes, Constants, Flags, RTL
3365: @section Machine Modes
3366:
3367: A machine mode describes a size of data object and the representation used
3368: for it. In the C code, machine modes are represented by an enumeration
3369: type, @code{enum machine_mode}, defined in @file{machmode.def}. Each RTL
3370: expression has room for a machine mode and so do certain kinds of tree
3371: expressions (declarations and types, to be precise).
3372:
3373: In debugging dumps and machine descriptions, the machine mode of an RTL
3374: expression is written after the expression code with a colon to separate
3375: them. The letters @samp{mode} which appear at the end of each machine mode
3376: name are omitted. For example, @code{(reg:SI 38)} is a @samp{reg}
3377: expression with machine mode @code{SImode}. If the mode is
3378: @code{VOIDmode}, it is not written at all.
3379:
3380: Here is a table of machine modes.
3381:
3382: @table @code
3383: @item QImode
3384: ``Quarter-Integer'' mode represents a single byte treated as an integer.
3385:
3386: @item HImode
3387: ``Half-Integer'' mode represents a two-byte integer.
3388:
3389: @item SImode
3390: ``Single Integer'' mode represents a four-byte integer.
3391:
3392: @item DImode
3393: ``Double Integer'' mode represents an eight-byte integer.
3394:
3395: @item TImode
3396: ``Tetra Integer'' (?) mode represents a sixteen-byte integer.
3397:
3398: @item SFmode
3399: ``Single Floating'' mode represents a single-precision (four byte) floating
3400: point number.
3401:
3402: @item DFmode
3403: ``Double Floating'' mode represents a double-precision (eight byte) floating
3404: point number.
3405:
3406: @item TFmode
3407: ``Tetra Floating'' mode represents a quadruple-precision (sixteen byte)
3408: floating point number.
3409:
3410: @item BLKmode
3411: ``Block'' mode represents values that are aggregates to which none of
3412: the other modes apply. In RTL, only memory references can have this mode,
3413: and only if they appear in string-move or vector instructions. On machines
3414: which have no such instructions, @code{BLKmode} will not appear in RTL.
3415:
3416: @item VOIDmode
3417: Void mode means the absence of a mode or an unspecified mode.
3418: For example, RTL expressions of code @samp{const_int} have mode
3419: @code{VOIDmode} because they can be taken to have whatever mode the context
3420: requires. In debugging dumps of RTL, @code{VOIDmode} is expressed by
3421: the absence of any mode.
3422:
3423: @item EPmode
3424: ``Entry Pointer'' mode is intended to be used for function variables in
3425: Pascal and other block structured languages. Such values contain
3426: both a function address and a static chain pointer for access to
3427: automatic variables of outer levels. This mode is only partially
3428: implemented since C does not use it.
3429:
3430: @item CSImode@r{, @dots{}}
3431: ``Complex Single Integer'' mode stands for a complex number represented
3432: as a pair of @code{SImode} integers. Any of the integer and floating modes
3433: may have @samp{C} prefixed to its name to obtain a complex number mode.
3434: For example, there are @code{CQImode}, @code{CSFmode}, and @code{CDFmode}.
3435: Since C does not support complex numbers, these machine modes are only
3436: partially implemented.
3437:
3438: @item BImode
3439: This is the machine mode of a bit-field in a structure. It is used
3440: only in the syntax tree, never in RTL, and in the syntax tree it appears
3441: only in declaration nodes. In C, it appears only in @code{FIELD_DECL}
3442: nodes for structure fields defined with a bit size.
3443: @end table
3444:
3445: The machine description defines @code{Pmode} as a C macro which expands
3446: into the machine mode used for addresses. Normally this is @code{SImode}.
3447:
3448: The only modes which a machine description @i{must} support are
3449: @code{QImode}, @code{SImode}, @code{SFmode} and @code{DFmode}. The
3450: compiler will attempt to use @code{DImode} for two-word structures and
3451: unions, but it would not be hard to program it to avoid this. Likewise,
3452: you can arrange for the C type @code{short int} to avoid using
3453: @code{HImode}. In the long term it would be desirable to make the set of
3454: available machine modes machine-dependent and eliminate all assumptions
3455: about specific machine modes or their uses from the machine-independent
3456: code of the compiler.
3457:
1.1.1.4 ! root 3458: To help begin this process, the machine modes are divided into mode
! 3459: classes. These are represented by the enumeration type @code{enum
! 3460: mode_class} defined in @file{rtl.h}. The possible mode classes are:
! 3461:
! 3462: @table @code
! 3463: @item MODE_INT
! 3464: Integer modes. By default these are @code{QImode}, @code{HImode},
! 3465: @code{SImode}, @code{DImode}, @code{TImode}, and also @code{BImode}.
! 3466:
! 3467: @item MODE_FLOAT
! 3468: Floating-point modes. By default these are @code{QFmode},
! 3469: @code{HFmode}, @code{SFmode}, @code{DFmode} and @code{TFmode}, but the
! 3470: MC68881 also defines @code{XFmode} to be an 80-bit extended-precision
! 3471: floating-point mode.
! 3472:
! 3473: @item MODE_COMPLEX_INT
! 3474: Complex integer modes. By default these are @code{CQImode},
! 3475: @code{CHImode}, @code{CSImode}, @code{CDImode} and @code{CTImode}.
! 3476:
! 3477: @item MODE_COMPLEX_FLOAT
! 3478: Complex floating-point modes. By default these are @code{CQFmode},
! 3479: @code{CHFmode}, @code{CSFmode}, @code{CDFmode} and @code{CTFmode},
! 3480:
! 3481: @item MODE_FUNCTION
! 3482: Algol or Pascal function variables including a static chain.
! 3483: (These are not currently implemented).
! 3484:
! 3485: @item MODE_RANDOM
! 3486: This is a catchall mode class for modes which don't fit into the above
! 3487: classes. Currently @code{VOIDmode}, @code{BLKmode} and @code{EPmode}
! 3488: are in @code{MODE_RANDOM}.
! 3489: @end table
! 3490:
1.1 root 3491: Here are some C macros that relate to machine modes:
3492:
3493: @table @code
3494: @item GET_MODE (@var{x})
3495: Returns the machine mode of the RTX @var{x}.
3496:
3497: @item PUT_MODE (@var{x}, @var{newmode})
3498: Alters the machine mode of the RTX @var{x} to be @var{newmode}.
3499:
1.1.1.4 ! root 3500: @item NUM_MACHINE_MODES
! 3501: Stands for the number of machine modes available on the target
! 3502: machine. This is one greater than the largest numeric value of any
! 3503: machine mode.
! 3504:
! 3505: @item GET_MODE_NAME (@var{m})
! 3506: Returns the name of mode @var{m} as a string.
! 3507:
! 3508: @item GET_MODE_CLASS (@var{m})
! 3509: Returns the mode class of mode @var{m}.
! 3510:
1.1 root 3511: @item GET_MODE_SIZE (@var{m})
3512: Returns the size in bytes of a datum of mode @var{m}.
3513:
3514: @item GET_MODE_BITSIZE (@var{m})
3515: Returns the size in bits of a datum of mode @var{m}.
3516:
3517: @item GET_MODE_UNIT_SIZE (@var{m})
3518: Returns the size in bits of the subunits of a datum of mode @var{m}.
3519: This is the same as @code{GET_MODE_SIZE} except in the case of
3520: complex modes and @code{EPmode}. For them, the unit size is the
3521: size of the real or imaginary part, or the size of the function
3522: pointer or the context pointer.
3523: @end table
3524:
3525: @node Constants, Regs and Memory, Machine Modes, RTL
3526: @section Constant Expression Types
3527:
3528: The simplest RTL expressions are those that represent constant values.
3529:
3530: @table @code
3531: @item (const_int @var{i})
3532: This type of expression represents the integer value @var{i}. @var{i}
3533: is customarily accessed with the macro @code{INTVAL} as in
3534: @code{INTVAL (@var{exp})}, which is equivalent to @code{XINT (@var{exp}, 0)}.
3535:
3536: There is only one expression object for the integer value zero;
3537: it is the value of the variable @code{const0_rtx}. Likewise, the
3538: only expression for integer value one is found in @code{const1_rtx}.
3539: Any attempt to create an expression of code @samp{const_int} and
3540: value zero or one will return @code{const0_rtx} or @code{const1_rtx}
3541: as appropriate.
3542:
3543: @item (const_double:@var{m} @var{i0} @var{i1})
3544: Represents a 64-bit constant or mode @var{m}. All floating point
3545: constants are represented in this way, and so are 64-bit @code{DImode}
3546: integer constants.
3547:
3548: The two integers @var{i0} and @var{i1} together contain the bits of
3549: the value. If the constant is floating point (either single or double
3550: precision), then they represent a @code{double}. To convert them to a
3551: @code{double}, do
3552:
3553: @example
3554: union @{ double d; int i[2];@} u;
3555: u.i[0] = XINT (x, 0);
3556: u.i[1] = XINT (x, 1);
3557: @end example
3558:
3559: @noindent
3560: and then refer to @code{u.d}.
3561:
3562: The global variables @code{dconst0_rtx} and @code{fconst0_rtx} hold
3563: @samp{const_double} expressions with value 0, in modes @code{DFmode} and
3564: @code{SFmode}, respectively.
3565:
3566: @item (symbol_ref @var{symbol})
3567: Represents the value of an assembler label for data. @var{symbol} is
3568: a string that describes the name of the assembler label. If it starts
3569: with a @samp{*}, the label is the rest of @var{symbol} not including
3570: the @samp{*}. Otherwise, the label is @var{symbol}, prefixed with
3571: @samp{_}.
3572:
3573: @item (label_ref @var{label})
3574: Represents the value of an assembler label for code. It contains one
3575: operand, an expression, which must be a @samp{code_label} that appears
3576: in the instruction sequence to identify the place where the label
3577: should go.
3578:
3579: The reason for using a distinct expression type for code label
3580: references is so that jump optimization can distinguish them.
3581:
3582: @item (const @var{exp})
3583: Represents a constant that is the result of an assembly-time
3584: arithmetic computation. The operand, @var{exp}, is an expression that
3585: contains only constants (@samp{const_int}, @samp{symbol_ref} and
3586: @samp{label_ref} expressions) combined with @samp{plus} and
3587: @samp{minus}. However, not all combinations are valid, since the
3588: assembler cannot do arbitrary arithmetic on relocatable symbols.
3589: @end table
3590:
3591: @node Regs and Memory, Arithmetic, Constants, RTL
3592: @section Registers and Memory
3593:
3594: Here are the RTL expression types for describing access to machine
3595: registers and to main memory.
3596:
3597: @table @code
3598: @item (reg:@var{m} @var{n})
3599: For small values of the integer @var{n} (less than
3600: @code{FIRST_PSEUDO_REGISTER}), this stands for a reference to machine
3601: register number @var{n}: a @dfn{hard register}. For larger values of
3602: @var{n}, it stands for a temporary value or @dfn{pseudo register}.
3603: The compiler's strategy is to generate code assuming an unlimited
3604: number of such pseudo registers, and later convert them into hard
3605: registers or into memory references.
3606:
3607: The symbol @code{FIRST_PSEUDO_REGISTER} is defined by the machine
3608: description, since the number of hard registers on the machine is an
3609: invariant characteristic of the machine. Note, however, that not
3610: all of the machine registers must be general registers. All the
3611: machine registers that can be used for storage of data are given
3612: hard register numbers, even those that can be used only in certain
3613: instructions or can hold only certain types of data.
3614:
3615: Each pseudo register number used in a function's RTL code is
3616: represented by a unique @samp{reg} expression.
3617:
3618: @var{m} is the machine mode of the reference. It is necessary because
3619: machines can generally refer to each register in more than one mode.
3620: For example, a register may contain a full word but there may be
3621: instructions to refer to it as a half word or as a single byte, as
3622: well as instructions to refer to it as a floating point number of
3623: various precisions.
3624:
3625: Even for a register that the machine can access in only one mode,
3626: the mode must always be specified.
3627:
3628: A hard register may be accessed in various modes throughout one
3629: function, but each pseudo register is given a natural mode
3630: and is accessed only in that mode. When it is necessary to describe
3631: an access to a pseudo register using a nonnatural mode, a @samp{subreg}
3632: expression is used.
3633:
3634: A @samp{reg} expression with a machine mode that specifies more than
3635: one word of data may actually stand for several consecutive registers.
3636: If in addition the register number specifies a hardware register, then
3637: it actually represents several consecutive hardware registers starting
3638: with the specified one.
3639:
3640: Such multi-word hardware register @samp{reg} expressions may not be live
3641: across the boundary of a basic block. The lifetime analysis pass does not
3642: know how to record properly that several consecutive registers are
3643: actually live there, and therefore register allocation would be confused.
3644: The CSE pass must go out of its way to make sure the situation does
3645: not arise.
3646:
3647: @item (subreg:@var{m} @var{reg} @var{wordnum})
3648: @samp{subreg} expressions are used to refer to a register in a machine
3649: mode other than its natural one, or to refer to one register of
3650: a multi-word @samp{reg} that actually refers to several registers.
3651:
3652: Each pseudo-register has a natural mode. If it is necessary to
3653: operate on it in a different mode---for example, to perform a fullword
3654: move instruction on a pseudo-register that contains a single byte---
3655: the pseudo-register must be enclosed in a @samp{subreg}. In such
3656: a case, @var{wordnum} is zero.
3657:
3658: The other use of @samp{subreg} is to extract the individual registers
3659: of a multi-register value. Machine modes such as @code{DImode} and
3660: @code{EPmode} indicate values longer than a word, values which usually
3661: require two consecutive registers. To access one of the registers,
3662: use a @samp{subreg} with mode @code{SImode} and a @var{wordnum} that
3663: says which register.
3664:
3665: The compilation parameter @code{WORDS_BIG_ENDIAN}, if defined, says
3666: that word number zero is the most significant part; otherwise, it is
3667: the least significant part.
3668:
3669: Between the combiner pass and the reload pass, it is possible to have
3670: a @samp{subreg} which contains a @samp{mem} instead of a @samp{reg} as
3671: its first operand. The reload pass eliminates these cases by
3672: reloading the @samp{mem} into a suitable register.
3673:
3674: Note that it is not valid to access a @code{DFmode} value in @code{SFmode}
3675: using a @samp{subreg}. On some machines the most significant part of a
3676: @code{DFmode} value does not have the same format as a single-precision
3677: floating value.
3678:
3679: @item (cc0)
3680: This refers to the machine's condition code register. It has no
3681: operands and may not have a machine mode. It may be validly used in
3682: only two contexts: as the destination of an assignment (in test and
3683: compare instructions) and in comparison operators comparing against
3684: zero (@samp{const_int} with value zero; that is to say,
3685: @code{const0_rtx}).
3686:
3687: There is only one expression object of code @samp{cc0}; it is the
3688: value of the variable @code{cc0_rtx}. Any attempt to create an
3689: expression of code @samp{cc0} will return @code{cc0_rtx}.
3690:
3691: One special thing about the condition code register is that
3692: instructions can set it implicitly. On many machines, nearly all
3693: instructions set the condition code based on the value that they
3694: compute or store. It is not necessary to record these actions
3695: explicitly in the RTL because the machine description includes a
3696: prescription for recognizing the instructions that do so (by means of
3697: the macro @code{NOTICE_UPDATE_CC}). Only instructions whose sole
3698: purpose is to set the condition code, and instructions that use the
3699: condition code, need mention @code{(cc0)}.
3700:
3701: @item (pc)
3702: This represents the machine's program counter. It has no operands and
3703: may not have a machine mode. @code{(pc)} may be validly used only in
3704: certain specific contexts in jump instructions.
3705:
3706: There is only one expression object of code @samp{pc}; it is the value
3707: of the variable @code{pc_rtx}. Any attempt to create an expression of
3708: code @samp{pc} will return @code{pc_rtx}.
3709:
3710: All instructions that do not jump alter the program counter implicitly
3711: by incrementing it, but there is no need to mention this in the RTL.
3712:
3713: @item (mem:@var{m} @var{addr})
3714: This RTX represents a reference to main memory at an address
3715: represented by the expression @var{addr}. @var{m} specifies how large
3716: a unit of memory is accessed.
3717: @end table
3718:
3719: @node Arithmetic, Comparisons, Regs and Memory, RTL
3720: @section RTL Expressions for Arithmetic
3721:
3722: @table @code
3723: @item (plus:@var{m} @var{x} @var{y})
3724: Represents the sum of the values represented by @var{x} and @var{y}
3725: carried out in machine mode @var{m}. This is valid only if
3726: @var{x} and @var{y} both are valid for mode @var{m}.
3727:
3728: @item (minus:@var{m} @var{x} @var{y})
3729: Like @samp{plus} but represents subtraction.
3730:
3731: @item (minus @var{x} @var{y})
3732: Represents the result of subtracting @var{y} from @var{x}
3733: for purposes of comparison. The absence of a machine mode
3734: in the @samp{minus} expression indicates that the result is
3735: computed without overflow, as if with infinite precision.
3736:
3737: Of course, machines can't really subtract with infinite precision.
3738: However, they can pretend to do so when only the sign of the
3739: result will be used, which is the case when the result is stored
3740: in @code{(cc0)}. And that is the only way this kind of expression
3741: may validly be used: as a value to be stored in the condition codes.
3742:
3743: @item (neg:@var{m} @var{x})
3744: Represents the negation (subtraction from zero) of the value
3745: represented by @var{x}, carried out in mode @var{m}. @var{x} must be
3746: valid for mode @var{m}.
3747:
3748: @item (mult:@var{m} @var{x} @var{y})
3749: Represents the signed product of the values represented by @var{x} and
3750: @var{y} carried out in machine mode @var{m}. If
3751: @var{x} and @var{y} are both valid for mode @var{m}, this is ordinary
3752: size-preserving multiplication. Alternatively, both @var{x} and @var{y}
3753: may be valid for a different, narrower mode. This represents the
3754: kind of multiplication that generates a product wider than the operands.
3755: Widening multiplication and same-size multiplication are completely
3756: distinct and supported by different machine instructions; machines may
3757: support one but not the other.@refill
3758:
3759: @samp{mult} may be used for floating point division as well.
3760: Then @var{m} is a floating point machine mode.
3761:
3762: @item (umult:@var{m} @var{x} @var{y})
3763: Like @samp{mult} but represents unsigned multiplication. It may be
3764: used in both same-size and widening forms, like @samp{mult}.
3765: @samp{umult} is used only for fixed-point multiplication.
3766:
3767: @item (div:@var{m} @var{x} @var{y})
3768: Represents the quotient in signed division of @var{x} by @var{y},
3769: carried out in machine mode @var{m}. If @var{m} is a floating-point
3770: mode, it represents the exact quotient; otherwise, the integerized
3771: quotient. If @var{x} and @var{y} are both valid for mode @var{m},
3772: this is ordinary size-preserving division. Some machines have
3773: division instructions in which the operands and quotient widths are
3774: not all the same; such instructions are represented by @samp{div}
3775: expressions in which the machine modes are not all the same.
3776:
3777: @item (udiv:@var{m} @var{x} @var{y})
3778: Like @samp{div} but represents unsigned division.
3779:
3780: @item (mod:@var{m} @var{x} @var{y})
3781: @itemx (umod:@var{m} @var{x} @var{y})
3782: Like @samp{div} and @samp{udiv} but represent the remainder instead of
3783: the quotient.
3784:
3785: @item (not:@var{m} @var{x})
3786: Represents the bitwise complement of the value represented by @var{x},
3787: carried out in mode @var{m}, which must be a fixed-point machine mode.
3788: @var{x} must be valid for mode @var{m}, which must be a fixed-point mode.
3789:
3790: @item (and:@var{m} @var{x} @var{y})
3791: Represents the bitwise logical-and of the values represented by
3792: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
3793: valid only if @var{x} and @var{y} both are valid for mode @var{m},
3794: which must be a fixed-point mode.
3795:
3796: @item (ior:@var{m} @var{x} @var{y})
3797: Represents the bitwise inclusive-or of the values represented by
3798: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
3799: valid only if @var{x} and @var{y} both are valid for mode @var{m},
3800: which must be a fixed-point mode.
3801:
3802: @item (xor:@var{m} @var{x} @var{y})
3803: Represents the bitwise exclusive-or of the values represented by
3804: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
3805: valid only if @var{x} and @var{y} both are valid for mode @var{m},
3806: which must be a fixed-point mode.
3807:
3808: @item (lshift:@var{m} @var{x} @var{c})
3809: Represents the result of logically shifting @var{x} left by @var{c}
3810: places. @var{x} must be valid for the mode @var{m}, a fixed-point
3811: machine mode. @var{c} must be valid for a fixed-point mode;
3812: which mode is determined by the mode called for in the machine
3813: description entry for the left-shift instruction. For example,
3814: on the Vax, the mode of @var{c} is @code{QImode} regardless of @var{m}.
3815:
3816: On some machines, negative values of @var{c} may be meaningful; this
3817: is why logical left shift and arithmetic left shift are distinguished.
3818: For example, Vaxes have no right-shift instructions, and right shifts
3819: are represented as left-shift instructions whose counts happen
3820: to be negative constants or else computed (in a previous instruction)
3821: by negation.
3822:
3823: @item (ashift:@var{m} @var{x} @var{c})
3824: Like @samp{lshift} but for arithmetic left shift.
3825:
3826: @item (lshiftrt:@var{m} @var{x} @var{c})
3827: @itemx (ashiftrt:@var{m} @var{x} @var{c})
3828: Like @samp{lshift} and @samp{ashift} but for right shift.
3829:
3830: @item (rotate:@var{m} @var{x} @var{c})
3831: @itemx (rotatert:@var{m} @var{x} @var{c})
3832: Similar but represent left and right rotate.
3833:
3834: @item (abs:@var{m} @var{x})
3835: Represents the absolute value of @var{x}, computed in mode @var{m}.
3836: @var{x} must be valid for @var{m}.
3837:
3838: @item (sqrt:@var{m} @var{x})
3839: Represents the square root of @var{x}, computed in mode @var{m}.
3840: @var{x} must be valid for @var{m}. Most often @var{m} will be
3841: a floating point mode.
3842:
3843: @item (ffs:@var{m} @var{x})
3844: Represents the one plus the index of the least significant 1-bit in
3845: @var{x}, represented as an integer of mode @var{m}. (The value is
3846: zero if @var{x} is zero.) The mode of @var{x} need not be @var{m};
3847: depending on the target machine, various mode combinations may be
3848: valid.
3849: @end table
3850:
3851: @node Comparisons, Bit Fields, Arithmetic, RTL
3852: @section Comparison Operations
3853:
3854: Comparison operators test a relation on two operands and are considered to
3855: represent the value 1 if the relation holds, or zero if it does not. The
3856: mode of the comparison is determined by the operands; they must both be
3857: valid for a common machine mode. A comparison with both operands constant
3858: would be invalid as the machine mode could not be deduced from it, but such
3859: a comparison should never exist in RTL due to constant folding.
3860:
3861: Inequality comparisons come in two flavors, signed and unsigned. Thus,
3862: there are distinct expression codes @samp{gt} and @samp{gtu} for signed and
3863: unsigned greater-than. These can produce different results for the same
3864: pair of integer values: for example, 1 is signed greater-than -1 but not
3865: unsigned greater-than, because -1 when regarded as unsigned is actually
3866: @code{0xffffffff} which is greater than 1.
3867:
3868: The signed comparisons are also used for floating point values. Floating
3869: point comparisons are distinguished by the machine modes of the operands.
3870:
3871: The comparison operators may be used to compare the condition codes
3872: @code{(cc0)} against zero, as in @code{(eq (cc0) (const_int 0))}. Such a
3873: construct actually refers to the result of the preceding instruction in
3874: which the condition codes were set. The above example stands for 1 if the
3875: condition codes were set to say ``zero'' or ``equal'', 0 otherwise.
3876: Although the same comparison operators are used for this as may be used in
3877: other contexts on actual data, no confusion can result since the machine
3878: description would never allow both kinds of uses in the same context.
3879:
3880: @table @code
3881: @item (eq @var{x} @var{y})
3882: 1 if the values represented by @var{x} and @var{y} are equal,
3883: otherwise 0.
3884:
3885: @item (ne @var{x} @var{y})
3886: 1 if the values represented by @var{x} and @var{y} are not equal,
3887: otherwise 0.
3888:
3889: @item (gt @var{x} @var{y})
3890: 1 if the @var{x} is greater than @var{y}. If they are fixed-point,
3891: the comparison is done in a signed sense.
3892:
3893: @item (gtu @var{x} @var{y})
3894: Like @samp{gt} but does unsigned comparison, on fixed-point numbers only.
3895:
3896: @item (lt @var{x} @var{y})
3897: @item (ltu @var{x} @var{y})
3898: Like @samp{gt} and @samp{gtu} but test for ``less than''.
3899:
3900: @item (ge @var{x} @var{y})
3901: @item (geu @var{x} @var{y})
3902: Like @samp{gt} and @samp{gtu} but test for ``greater than or equal''.
3903:
3904: @item (le @var{x} @var{y})
3905: @item (leu @var{x} @var{y})
3906: Like @samp{gt} and @samp{gtu} but test for ``less than or equal''.
3907:
3908: @item (if_then_else @var{cond} @var{then} @var{else})
3909: This is not a comparison operation but is listed here because it is
3910: always used in conjunction with a comparison operation. To be
3911: precise, @var{cond} is a comparison expression. This expression
3912: represents a choice, according to @var{cond}, between the value
3913: represented by @var{then} and the one represented by @var{else}.
3914:
3915: On most machines, @samp{if_then_else} expressions are valid only
3916: to express conditional jumps.
3917: @end table
3918:
3919: @node Bit Fields, Conversions, Comparisons, RTL
3920: @section Bit-fields
3921:
3922: Special expression codes exist to represent bit-field instructions.
3923: These types of expressions are lvalues in RTL; they may appear
3924: on the left side of a assignment, indicating insertion of a value
3925: into the specified bit field.
3926:
3927: @table @code
3928: @item (sign_extract:SI @var{loc} @var{size} @var{pos})
3929: This represents a reference to a sign-extended bit-field contained or
3930: starting in @var{loc} (a memory or register reference). The bit field
3931: is @var{size} bits wide and starts at bit @var{pos}. The compilation
3932: option @code{BITS_BIG_ENDIAN} says which end of the memory unit
3933: @var{pos} counts from.
3934:
3935: Which machine modes are valid for @var{loc} depends on the machine,
3936: but typically @var{loc} should be a single byte when in memory
3937: or a full word in a register.
3938:
3939: @item (zero_extract:SI @var{loc} @var{size} @var{pos})
3940: Like @samp{sign_extract} but refers to an unsigned or zero-extended
3941: bit field. The same sequence of bits are extracted, but they
3942: are filled to an entire word with zeros instead of by sign-extension.
3943: @end table
3944:
3945: @node Conversions, RTL Declarations, Bit Fields, RTL
3946: @section Conversions
3947:
3948: All conversions between machine modes must be represented by
3949: explicit conversion operations. For example, an expression
3950: which is the sum of a byte and a full word cannot be written as
3951: @code{(plus:SI (reg:QI 34) (reg:SI 80))} because the @samp{plus}
3952: operation requires two operands of the same machine mode.
3953: Therefore, the byte-sized operand is enclosed in a conversion
3954: operation, as in
3955:
3956: @example
3957: (plus:SI (sign_extend:SI (reg:QI 34)) (reg:SI 80))
3958: @end example
3959:
3960: The conversion operation is not a mere placeholder, because there
3961: may be more than one way of converting from a given starting mode
3962: to the desired final mode. The conversion operation code says how
3963: to do it.
3964:
3965: @table @code
3966: @item (sign_extend:@var{m} @var{x})
3967: Represents the result of sign-extending the value @var{x}
3968: to machine mode @var{m}. @var{m} must be a fixed-point mode
3969: and @var{x} a fixed-point value of a mode narrower than @var{m}.
3970:
3971: @item (zero_extend:@var{m} @var{x})
3972: Represents the result of zero-extending the value @var{x}
3973: to machine mode @var{m}. @var{m} must be a fixed-point mode
3974: and @var{x} a fixed-point value of a mode narrower than @var{m}.
3975:
3976: @item (float_extend:@var{m} @var{x})
3977: Represents the result of extending the value @var{x}
3978: to machine mode @var{m}. @var{m} must be a floating point mode
3979: and @var{x} a floating point value of a mode narrower than @var{m}.
3980:
3981: @item (truncate:@var{m} @var{x})
3982: Represents the result of truncating the value @var{x}
3983: to machine mode @var{m}. @var{m} must be a fixed-point mode
3984: and @var{x} a fixed-point value of a mode wider than @var{m}.
3985:
3986: @item (float_truncate:@var{m} @var{x})
3987: Represents the result of truncating the value @var{x}
3988: to machine mode @var{m}. @var{m} must be a floating point mode
3989: and @var{x} a floating point value of a mode wider than @var{m}.
3990:
3991: @item (float:@var{m} @var{x})
3992: Represents the result of converting fixed point value @var{x},
3993: regarded as signed, to floating point mode @var{m}.
3994:
3995: @item (unsigned_float:@var{m} @var{x})
3996: Represents the result of converting fixed point value @var{x},
3997: regarded as unsigned, to floating point mode @var{m}.
3998:
3999: @item (fix:@var{m} @var{x})
4000: When @var{m} is a fixed point mode, represents the result of
4001: converting floating point value @var{x} to mode @var{m}, regarded as
4002: signed. How rounding is done is not specified, so this operation may
4003: be used validly in compiling C code only for integer-valued operands.
4004:
4005: @item (unsigned_fix:@var{m} @var{x})
4006: Represents the result of converting floating point value @var{x} to
4007: fixed point mode @var{m}, regarded as unsigned. How rounding is done
4008: is not specified.
4009:
4010: @item (fix:@var{m} @var{x})
4011: When @var{m} is a floating point mode, represents the result of
4012: converting floating point value @var{x} (valid for mode @var{m}) to an
4013: integer, still represented in floating point mode @var{m}, by rounding
4014: towards zero.
4015: @end table
4016:
4017: @node RTL Declarations, Side Effects, Conversions, RTL
4018: @section Declarations
4019:
4020: Declaration expression codes do not represent arithmetic operations
4021: but rather state assertions about their operands.
4022:
4023: @table @code
4024: @item (strict_low_part (subreg:@var{m} (reg:@var{n} @var{r}) 0))
4025: This expression code is used in only one context: operand 0 of a
4026: @samp{set} expression. In addition, the operand of this expression
4027: must be a @samp{subreg} expression.
4028:
4029: The presence of @samp{strict_low_part} says that the part of the
4030: register which is meaningful in mode @var{n}, but is not part of
4031: mode @var{m}, is not to be altered. Normally, an assignment to such
4032: a subreg is allowed to have undefined effects on the rest of the
4033: register when @var{m} is less than a word.
4034: @end table
4035:
4036: @node Side Effects, Incdec, RTL Declarations, RTL
4037: @section Side Effect Expressions
4038:
4039: The expression codes described so far represent values, not actions.
4040: But machine instructions never produce values; they are meaningful
4041: only for their side effects on the state of the machine. Special
4042: expression codes are used to represent side effects.
4043:
4044: The body of an instruction is always one of these side effect codes;
4045: the codes described above, which represent values, appear only as
4046: the operands of these.
4047:
4048: @table @code
4049: @item (set @var{lval} @var{x})
4050: Represents the action of storing the value of @var{x} into the place
4051: represented by @var{lval}. @var{lval} must be an expression
4052: representing a place that can be stored in: @samp{reg} (or
4053: @samp{subreg} or @samp{strict_low_part}), @samp{mem}, @samp{pc} or
4054: @samp{cc0}.@refill
4055:
4056: If @var{lval} is a @samp{reg}, @samp{subreg} or @samp{mem}, it has a
4057: machine mode; then @var{x} must be valid for that mode.@refill
4058:
4059: If @var{lval} is a @samp{reg} whose machine mode is less than the full
4060: width of the register, then it means that the part of the register
4061: specified by the machine mode is given the specified value and the
4062: rest of the register receives an undefined value. Likewise, if
4063: @var{lval} is a @samp{subreg} whose machine mode is narrower than
4064: @code{SImode}, the rest of the register can be changed in an undefined way.
4065:
4066: If @var{lval} is a @samp{strict_low_part} of a @samp{subreg}, then the
4067: part of the register specified by the machine mode of the
4068: @samp{subreg} is given the value @var{x} and the rest of the register
4069: is not changed.@refill
4070:
4071: If @var{lval} is @code{(cc0)}, it has no machine mode, and @var{x} may
4072: have any mode. This represents a ``test'' or ``compare'' instruction.@refill
4073:
4074: If @var{lval} is @code{(pc)}, we have a jump instruction, and the
4075: possibilities for @var{x} are very limited. It may be a
4076: @samp{label_ref} expression (unconditional jump). It may be an
4077: @samp{if_then_else} (conditional jump), in which case either the
4078: second or the third operand must be @code{(pc)} (for the case which
4079: does not jump) and the other of the two must be a @samp{label_ref}
4080: (for the case which does jump). @var{x} may also be a @samp{mem} or
4081: @code{(plus:SI (pc) @var{y})}, where @var{y} may be a @samp{reg} or a
4082: @samp{mem}; these unusual patterns are used to represent jumps through
4083: branch tables.@refill
4084:
4085: @item (return)
4086: Represents a return from the current function, on machines where this
4087: can be done with one instruction, such as Vaxes. On machines where a
4088: multi-instruction ``epilogue'' must be executed in order to return
4089: from the function, returning is done by jumping to a label which
4090: precedes the epilogue, and the @samp{return} expression code is never
4091: used.
4092:
4093: @item (call @var{function} @var{nargs})
4094: Represents a function call. @var{function} is a @samp{mem} expression
4095: whose address is the address of the function to be called.
4096: @var{nargs} is an expression which can be used for two purposes: on
4097: some machines it represents the number of bytes of stack argument; on
4098: others, it represents the number of argument registers.
4099:
4100: Each machine has a standard machine mode which @var{function} must
4101: have. The machine description defines macro @code{FUNCTION_MODE} to
4102: expand into the requisite mode name. The purpose of this mode is to
4103: specify what kind of addressing is allowed, on machines where the
4104: allowed kinds of addressing depend on the machine mode being
4105: addressed.
4106:
4107: @item (clobber @var{x})
4108: Represents the storing or possible storing of an unpredictable,
4109: undescribed value into @var{x}, which must be a @samp{reg} or
4110: @samp{mem} expression.
4111:
4112: One place this is used is in string instructions that store standard
4113: values into particular hard registers. It may not be worth the
4114: trouble to describe the values that are stored, but it is essential to
4115: inform the compiler that the registers will be altered, lest it
4116: attempt to keep data in them across the string instruction.
4117:
4118: @var{x} may also be null---a null C pointer, no expression at all.
4119: Such a @code{(clobber (null))} expression means that all memory
4120: locations must be presumed clobbered.
4121:
4122: Note that the machine description classifies certain hard registers as
4123: ``call-clobbered''. All function call instructions are assumed by
4124: default to clobber these registers, so there is no need to use
4125: @samp{clobber} expressions to indicate this fact. Also, each function
4126: call is assumed to have the potential to alter any memory location.
4127:
1.1.1.4 ! root 4128: When a @samp{clobber} expression for a register appears inside a
! 4129: @samp{parallel} with other side effects, GNU CC guarantees that the
! 4130: register is unoccupied both before and after that insn. Therefore, it
! 4131: is safe for the assembler code produced by the insn to use the
! 4132: register as a temporary. You can clobber either a specific hard
! 4133: register or a pseudo register; in the latter case, GNU CC will
! 4134: allocate a hard register that is available there for use as a
! 4135: temporary.
! 4136:
1.1 root 4137: @item (use @var{x})
4138: Represents the use of the value of @var{x}. It indicates that the
4139: value in @var{x} at this point in the program is needed, even though
4140: it may not be apparent why this is so. Therefore, the compiler will
1.1.1.4 ! root 4141: not attempt to delete previous instructions whose only effect is to
! 4142: store a value in @var{x}. @var{x} must be a @samp{reg} expression.
1.1 root 4143:
4144: @item (parallel [@var{x0} @var{x1} @dots{}])
4145: Represents several side effects performed in parallel. The square
4146: brackets stand for a vector; the operand of @samp{parallel} is a
4147: vector of expressions. @var{x0}, @var{x1} and so on are individual
1.1.1.4 ! root 4148: side effect expressions---expressions of code @samp{set}, @samp{call},
1.1 root 4149: @samp{return}, @samp{clobber} or @samp{use}.@refill
4150:
4151: ``In parallel'' means that first all the values used in the individual
4152: side-effects are computed, and second all the actual side-effects are
4153: performed. For example,
4154:
4155: @example
4156: (parallel [(set (reg:SI 1) (mem:SI (reg:SI 1)))
4157: (set (mem:SI (reg:SI 1)) (reg:SI 1))])
4158: @end example
4159:
4160: @noindent
4161: says unambiguously that the values of hard register 1 and the memory
4162: location addressed by it are interchanged. In both places where
4163: @code{(reg:SI 1)} appears as a memory address it refers to the value
1.1.1.4 ! root 4164: in register 1 @emph{before} the execution of the insn.
! 4165:
! 4166: It follows that it is @emph{incorrect} to use @samp{parallel} and
! 4167: expect the result of one @samp{set} to be available for the next one.
! 4168: For example, people sometimes attempt to represent a jump-if-zero
! 4169: instruction this way:
! 4170:
! 4171: @example
! 4172: (parallel [(set (cc0) (reg:SI 34))
! 4173: (set (pc) (if_then_else
! 4174: (eq (cc0) (const_int 0))
! 4175: (label_ref @dots{})
! 4176: (pc)))])
! 4177: @end example
! 4178:
! 4179: @noindent
! 4180: But this is incorrect, because it says that the jump condition depends
! 4181: on the condition code value @emph{before} this instruction, not on the
! 4182: new value that is set by this instruction.
1.1 root 4183:
4184: Peephole optimization, which takes place in the last jump-optimization
4185: pass, can produce insns whose patterns consist of a @samp{parallel}
4186: whose elements are the operands needed to output the resulting
4187: assembler code--often @samp{reg}, @samp{mem} or constant expressions.
4188: This would not be well-formed RTL at any other stage in compilation,
4189: but it is ok then because no further optimization remains to be done.
1.1.1.4 ! root 4190: However, the definition of the macro @code{NOTICE_UPDATE_CC} must
! 4191: deal with such insns if you define any peephole optimizations.
1.1 root 4192:
4193: @item (sequence [@var{insns} @dots{}])
4194: Represents a sequence of insns. Each of the @var{insns} that appears
4195: in the vector is suitable for appearing in the chain of insns, so it
4196: must be an @samp{insn}, @samp{jump_insn}, @samp{call_insn},
4197: @samp{code_label}, @samp{barrier} or @samp{note}.
4198:
4199: A @samp{sequence} RTX never appears in an actual insn. It represents
4200: the sequence of insns that result from a @samp{define_expand}
4201: @emph{before} those insns are passed to @code{emit_insn} to insert
4202: them in the chain of insns. When actually inserted, the individual
4203: sub-insns are separated out and the @samp{sequence} is forgotten.
4204: @end table
4205:
4206: Three expression codes appear in place of a side effect, as the body of an
4207: insn, though strictly speaking they do not describe side effects as such:
4208:
4209: @table @code
4210: @item (asm_input @var{s})
4211: Represents literal assembler code as described by the string @var{s}.
4212:
4213: @item (addr_vec:@var{m} [@var{lr0} @var{lr1} @dots{}])
4214: Represents a table of jump addresses. The vector elements @var{lr0},
4215: etc., are @samp{label_ref} expressions. The mode @var{m} specifies
4216: how much space is given to each address; normally @var{m} would be
4217: @code{Pmode}.
4218:
4219: @item (addr_diff_vec:@var{m} @var{base} [@var{lr0} @var{lr1} @dots{}])
4220: Represents a table of jump addresses expressed as offsets from
4221: @var{base}. The vector elements @var{lr0}, etc., are @samp{label_ref}
4222: expressions and so is @var{base}. The mode @var{m} specifies how much
4223: space is given to each address-difference.@refill
4224: @end table
4225:
4226: @node Incdec, Assembler, Side Effects, RTL
4227: @section Embedded Side-Effects on Addresses
4228:
4229: Four special side-effect expression codes appear as memory addresses.
4230:
4231: @table @code
4232: @item (pre_dec:@var{m} @var{x})
4233: Represents the side effect of decrementing @var{x} by a standard
4234: amount and represents also the value that @var{x} has after being
4235: decremented. @var{x} must be a @samp{reg} or @samp{mem}, but most
4236: machines allow only a @samp{reg}. @var{m} must be the machine mode
4237: for pointers on the machine in use. The amount @var{x} is decremented
4238: by is the length in bytes of the machine mode of the containing memory
4239: reference of which this expression serves as the address. Here is an
4240: example of its use:@refill
4241:
4242: @example
4243: (mem:DF (pre_dec:SI (reg:SI 39)))
4244: @end example
4245:
4246: @noindent
4247: This says to decrement pseudo register 39 by the length of a @code{DFmode}
4248: value and use the result to address a @code{DFmode} value.
4249:
4250: @item (pre_inc:@var{m} @var{x})
4251: Similar, but specifies incrementing @var{x} instead of decrementing it.
4252:
4253: @item (post_dec:@var{m} @var{x})
4254: Represents the same side effect as @samp{pre_decrement} but a different
4255: value. The value represented here is the value @var{x} has @i{before}
4256: being decremented.
4257:
4258: @item (post_inc:@var{m} @var{x})
4259: Similar, but specifies incrementing @var{x} instead of decrementing it.
4260: @end table
4261:
4262: These embedded side effect expressions must be used with care. Instruction
4263: patterns may not use them. Until the @samp{flow} pass of the compiler,
4264: they may occur only to represent pushes onto the stack. The @samp{flow}
4265: pass finds cases where registers are incremented or decremented in one
4266: instruction and used as an address shortly before or after; these cases are
4267: then transformed to use pre- or post-increment or -decrement.
4268:
4269: Explicit popping of the stack could be represented with these embedded
4270: side effect operators, but that would not be safe; the instruction
4271: combination pass could move the popping past pushes, thus changing
4272: the meaning of the code.
4273:
4274: An instruction that can be represented with an embedded side effect
4275: could also be represented using @samp{parallel} containing an additional
4276: @samp{set} to describe how the address register is altered. This is not
4277: done because machines that allow these operations at all typically
4278: allow them wherever a memory address is called for. Describing them as
4279: additional parallel stores would require doubling the number of entries
4280: in the machine description.
4281:
4282: @node Assembler, Insns, IncDec, RTL
4283: @section Assembler Instructions as Expressions
4284:
4285: The RTX code @samp{asm_operands} represents a value produced by a
4286: user-specified assembler instruction. It is used to represent
4287: an @code{asm} statement with arguments. An @code{asm} statement with
4288: a single output operand, like this:
4289:
4290: @example
4291: asm ("foo %1,%2,%0" : "a" (outputvar) : "g" (x + y), "di" (*z));
4292: @end example
4293:
4294: @noindent
4295: is represented using a single @samp{asm_operands} RTX which represents
4296: the value that is stored in @code{outputvar}:
4297:
4298: @example
4299: (set @var{rtx-for-outputvar}
4300: (asm_operands "foo %1,%2,%0" "a" 0
4301: [@var{rtx-for-addition-result} @var{rtx-for-*z}]
4302: [(asm_input:@var{m1} "g")
4303: (asm_input:@var{m2} "di")]))
4304: @end example
4305:
4306: @noindent
4307: Here the operands of the @samp{asm_operands} RTX are the assembler
4308: template string, the output-operand's constraint, the index-number of the
4309: output operand among the output operands specified, a vector of input
4310: operand RTX's, and a vector of input-operand modes and constraints. The
4311: mode @var{m1} is the mode of the sum @code{x+y}; @var{m2} is that of
4312: @code{*z}.
4313:
4314: When an @code{asm} statement has multiple output values, its insn has
4315: several such @samp{set} RTX's inside of a @samp{parallel}. Each @samp{set}
4316: contains a @samp{asm_operands}; all of these share the same assembler
4317: template and vectors, but each contains the constraint for the respective
4318: output operand. They are also distinguished by the output-operand index
4319: number, which is 0, 1, @dots{} for successive output operands.
4320:
4321: @node Insns, Calls, Assembler, RTL
4322: @section Insns
4323:
4324: The RTL representation of the code for a function is a doubly-linked
4325: chain of objects called @dfn{insns}. Insns are expressions with
4326: special codes that are used for no other purpose. Some insns are
4327: actual instructions; others represent dispatch tables for @code{switch}
4328: statements; others represent labels to jump to or various sorts of
4329: declarative information.
4330:
4331: In addition to its own specific data, each insn must have a unique id-number
4332: that distinguishes it from all other insns in the current function, and
4333: chain pointers to the preceding and following insns. These three fields
4334: occupy the same position in every insn, independent of the expression code
4335: of the insn. They could be accessed with @code{XEXP} and @code{XINT},
4336: but instead three special macros are always used:
4337:
4338: @table @code
4339: @item INSN_UID (@var{i})
4340: Accesses the unique id of insn @var{i}.
4341:
4342: @item PREV_INSN (@var{i})
4343: Accesses the chain pointer to the insn preceding @var{i}.
4344: If @var{i} is the first insn, this is a null pointer.
4345:
4346: @item NEXT_INSN (@var{i})
4347: Accesses the chain pointer to the insn following @var{i}.
4348: If @var{i} is the last insn, this is a null pointer.
4349: @end table
4350:
4351: The @code{NEXT_INSN} and @code{PREV_INSN} pointers must always
4352: correspond: if @var{i} is not the first insn,
4353:
4354: @example
4355: NEXT_INSN (PREV_INSN (@var{insn})) == @var{insn}
4356: @end example
4357:
4358: @noindent
4359: is always true.
4360:
4361: Every insn has one of the following six expression codes:
4362:
4363: @table @samp
4364: @item insn
4365: The expression code @samp{insn} is used for instructions that do not jump
4366: and do not do function calls. Insns with code @samp{insn} have four
4367: additional fields beyond the three mandatory ones listed above.
4368: These four are described in a table below.
4369:
4370: @item jump_insn
4371: The expression code @samp{jump_insn} is used for instructions that may jump
4372: (or, more generally, may contain @samp{label_ref} expressions).
4373: @samp{jump_insn} insns have the same extra fields as @samp{insn} insns,
4374: accessed in the same way.
4375:
4376: @item call_insn
4377: The expression code @samp{call_insn} is used for instructions that may do
4378: function calls. It is important to distinguish these instructions because
4379: they imply that certain registers and memory locations may be altered
4380: unpredictably.
4381:
4382: @samp{call_insn} insns have the same extra fields as @samp{insn} insns,
4383: accessed in the same way.
4384:
4385: @item code_label
4386: A @samp{code_label} insn represents a label that a jump insn can jump to.
4387: It contains one special field of data in addition to the three standard ones.
4388: It is used to hold the @dfn{label number}, a number that identifies this
4389: label uniquely among all the labels in the compilation (not just in the
4390: current function). Ultimately, the label is represented in the assembler
4391: output as an assembler label @samp{L@var{n}} where @var{n} is the label number.
4392:
4393: @item barrier
4394: Barriers are placed in the instruction stream after unconditional
4395: jump instructions to indicate that the jumps are unconditional.
4396: They contain no information beyond the three standard fields.
4397:
4398: @item note
4399: @samp{note} insns are used to represent additional debugging and
4400: declarative information. They contain two nonstandard fields, an
4401: integer which is accessed with the macro @code{NOTE_LINE_NUMBER} and a
4402: string accessed with @code{NOTE_SOURCE_FILE}.
4403:
4404: If @code{NOTE_LINE_NUMBER} is positive, the note represents the
4405: position of a source line and @code{NOTE_SOURCE_FILE} is the source file name
4406: that the line came from. These notes control generation of line
4407: number data in the assembler output.
4408:
4409: Otherwise, @code{NOTE_LINE_NUMBER} is not really a line number but a
4410: code with one of the following values (and @code{NOTE_SOURCE_FILE}
4411: must contain a null pointer):
4412:
4413: @table @code
4414: @item NOTE_INSN_DELETED
4415: Such a note is completely ignorable. Some passes of the compiler
4416: delete insns by altering them into notes of this kind.
4417:
4418: @item NOTE_INSN_BLOCK_BEG
4419: @itemx NOTE_INSN_BLOCK_END
4420: These types of notes indicate the position of the beginning and end
4421: of a level of scoping of variable names. They control the output
4422: of debugging information.
4423:
4424: @item NOTE_INSN_LOOP_BEG
4425: @itemx NOTE_INSN_LOOP_END
4426: These types of notes indicate the position of the beginning and end
4427: of a @code{while} or @code{for} loop. They enable the loop optimizer
4428: to find loops quickly.
4429: @end table
4430: @end table
4431:
4432: Here is a table of the extra fields of @samp{insn}, @samp{jump_insn}
4433: and @samp{call_insn} insns:
4434:
4435: @table @code
4436: @item PATTERN (@var{i})
4437: An expression for the side effect performed by this insn.
4438:
4439: @item REG_NOTES (@var{i})
4440: A list (chain of @samp{expr_list} expressions) giving information
4441: about the usage of registers in this insn. This list is set up by the
4442: flow analysis pass; it is a null pointer until then.
4443:
4444: @item LOG_LINKS (@var{i})
4445: A list (chain of @samp{insn_list} expressions) of previous ``related''
4446: insns: insns which store into registers values that are used for the
4447: first time in this insn. (An additional constraint is that neither a
4448: jump nor a label may come between the related insns). This list is
4449: set up by the flow analysis pass; it is a null pointer until then.
4450:
4451: @item INSN_CODE (@var{i})
4452: An integer that says which pattern in the machine description matches
4453: this insn, or -1 if the matching has not yet been attempted.
4454:
4455: Such matching is never attempted and this field is not used on an insn
4456: whose pattern consists of a single @samp{use}, @samp{clobber},
4457: @samp{asm}, @samp{addr_vec} or @samp{addr_diff_vec} expression.
4458: @end table
4459:
4460: The @code{LOG_LINKS} field of an insn is a chain of @samp{insn_list}
4461: expressions. Each of these has two operands: the first is an insn,
4462: and the second is another @samp{insn_list} expression (the next one in
4463: the chain). The last @samp{insn_list} in the chain has a null pointer
4464: as second operand. The significant thing about the chain is which
4465: insns appear in it (as first operands of @samp{insn_list}
4466: expressions). Their order is not significant.
4467:
4468: The @code{REG_NOTES} field of an insn is a similar chain but of
4469: @samp{expr_list} expressions instead of @samp{insn_list}. There are four
4470: kinds of register notes, which are distinguished by the machine mode of the
4471: @samp{expr_list}, which a register note is really understood as being an
4472: @code{enum reg_note}. The first operand @var{op} of the @samp{expr_list}
4473: is data whose meaning depends on the kind of note. Here are the four
4474: kinds:
4475:
4476: @table @code
4477: @item REG_DEAD
4478: The register @var{op} dies in this insn; that is to say, altering the
4479: value immediately after this insn would not affect the future behavior
4480: of the program.
4481:
4482: @item REG_INC
4483: The register @var{op} is incremented (or decremented; at this level
4484: there is no distinction) by an embedded side effect inside this insn.
4485: This means it appears in a @code{POST_INC}, @code{PRE_INC},
4486: @code{POST_DEC} or @code{PRE_DEC} RTX.
4487:
4488: @item REG_EQUIV
4489: The register that is set by this insn will be equal to @var{op} at run
4490: time, and could validly be replaced in all its occurrences by
4491: @var{op}. (``Validly'' here refers to the data flow of the program;
4492: simple replacement may make some insns invalid.)
4493:
4494: The value which the insn explicitly copies into the register may look
4495: different from @var{op}, but they will be equal at run time.
4496:
4497: For example, when a constant is loaded into a register that is never
4498: assigned any other value, this kind of note is used.
4499:
4500: When a parameter is copied into a pseudo-register at entry to a function,
4501: a note of this kind records that the register is equivalent to the stack
4502: slot where the parameter was passed. Although in this case the register
4503: may be set by other insns, it is still valid to replace the register
4504: by the stack slot throughout the function.
4505:
4506: @item REG_EQUAL
4507: The register that is set by this insn will be equal to @var{op} at run
4508: time at the end of this insn (but not necessarily elsewhere in the
4509: function).
4510:
4511: The RTX @var{op} is typically an arithmetic expression. For example,
4512: when a sequence of insns such as a library call is used to perform an
4513: arithmetic operation, this kind of note is attached to the insn that
4514: produces or copies the final value. It tells the CSE pass how to
4515: think of that value.
4516:
4517: @item REG_RETVAL
4518: This insn copies the value of a library call, and @var{op} is the
4519: first insn that was generated to set up the arguments for the library
4520: call.
4521:
4522: Flow analysis uses this note to delete all of a library call whose
4523: result is dead.
4524:
4525: @item REG_WAS_0
4526: The register @var{op} contained zero before this insn. You can rely
4527: on this note if it is present; its absence implies nothing.
4528:
4529: @item REG_LIBCALL
4530: This is the inverse of @code{REG_RETVAL}: it is placed on the first
4531: insn of a library call, and it points to the last one.
4532:
4533: Loop optimization uses this note to move an entire library call out
4534: of a loop when its value is constant.
4535:
4536: @item REG_NONNEG
4537: The register @var{op} is known to have nonnegative value when this
4538: insn is reached.
4539: @end table
4540:
4541: (The only difference between the expression codes @samp{insn_list} and
4542: @samp{expr_list} is that the first operand of an @samp{insn_list} is
4543: assumed to be an insn and is printed in debugging dumps as the insn's
4544: unique id; the first operand of an @samp{expr_list} is printed in the
4545: ordinary way as an expression.)
4546:
4547: @node Calls, Sharing, Insns, RTL
4548: @section RTL Representation of Function-Call Insns
4549:
4550: Insns that call subroutines have the RTL expression code @samp{call_insn}.
4551: These insns must satisfy special rules, and their bodies must use a special
4552: RTL expression code, @samp{call}.
4553:
4554: A @samp{call} expression has two operands, as follows:
4555:
4556: @example
4557: (call @var{nbytes} (mem:@var{fm} @var{addr}))
4558: @end example
4559:
4560: @noindent
4561: Here @var{nbytes} is an operand that represents the number of bytes of
4562: argument data being passed to the subroutine, @var{fm} is a machine mode
4563: (which must equal as the definition of the @code{FUNCTION_MODE} macro in
4564: the machine description) and @var{addr} represents the address of the
4565: subroutine.
4566:
4567: For a subroutine that returns no value, the @samp{call} RTX as shown above
4568: is the entire body of the insn.
4569:
4570: For a subroutine that returns a value whose mode is not @code{BLKmode},
4571: the value is returned in a hard register. If this register's number is
4572: @var{r}, then the body of the call insn looks like this:
4573:
4574: @example
4575: (set (reg:@var{m} @var{r})
4576: (call @var{nbytes} (mem:@var{fm} @var{addr})))
4577: @end example
4578:
4579: @noindent
4580: This RTL expression makes it clear (to the optimizer passes) that the
4581: appropriate register receives a useful value in this insn.
4582:
4583: Immediately after RTL generation, if the value of the subroutine is
4584: actually used, this call insn is always followed closely by an insn which
4585: refers to the register @var{r}. This remains true through all the
4586: optimizer passes until cross jumping occurs.
4587:
4588: The following insn has one of two forms. Either it copies the value into a
4589: pseudo-register, like this:
4590:
4591: @example
4592: (set (reg:@var{m} @var{p}) (reg:@var{m} @var{r}))
4593: @end example
4594:
4595: @noindent
4596: or (in the case where the calling function will simply return whatever
4597: value the call produced, and no operation is needed to do this):
4598:
4599: @example
4600: (use (reg:@var{m} @var{r}))
4601: @end example
4602:
4603: @noindent
4604: Between the call insn and this following insn there may intervene only a
4605: stack-adjustment insn (and perhaps some @samp{note} insns).
4606:
4607: When a subroutine returns a @code{BLKmode} value, it is handled by
4608: passing to the subroutine the address of a place to store the value.
4609: So the call insn itself does not ``return'' any value, and it has the
4610: same RTL form as a call that returns nothing.
4611:
4612: @node Sharing,, Calls, RTL
4613: @section Structure Sharing Assumptions
4614:
4615: The compiler assumes that certain kinds of RTL expressions are unique;
4616: there do not exist two distinct objects representing the same value.
4617: In other cases, it makes an opposite assumption: that no RTL expression
4618: object of a certain kind appears in more than one place in the
4619: containing structure.
4620:
4621: These assumptions refer to a single function; except for the RTL
4622: objects that describe global variables and external functions,
4623: no RTL objects are common to two functions.
4624:
4625: @itemize @bullet
4626: @item
4627: Each pseudo-register has only a single @samp{reg} object to represent it,
4628: and therefore only a single machine mode.
4629:
4630: @item
4631: For any symbolic label, there is only one @samp{symbol_ref} object
4632: referring to it.
4633:
4634: @item
4635: There is only one @samp{const_int} expression with value zero,
4636: and only one with value one.
4637:
4638: @item
4639: There is only one @samp{pc} expression.
4640:
4641: @item
4642: There is only one @samp{cc0} expression.
4643:
4644: @item
4645: There is only one @samp{const_double} expression with mode
4646: @code{SFmode} and value zero, and only one with mode @code{DFmode} and
4647: value zero.
4648:
4649: @item
4650: No @samp{label_ref} appears in more than one place in the RTL
4651: structure; in other words, it is safe to do a tree-walk of all the
4652: insns in the function and assume that each time a @samp{label_ref} is
4653: seen it is distinct from all others that are seen.
4654:
4655: @item
4656: Only one @samp{mem} object is normally created for each static
4657: variable or stack slot, so these objects are frequently shared in all
4658: the places they appear. However, separate but equal objects for these
4659: variables are occasionally made.
4660:
4661: @item
4662: No RTL object appears in more than one place in the RTL structure
4663: except as described above. Many passes of the compiler rely on this
4664: by assuming that they can modify RTL objects in place without unwanted
4665: side-effects on other insns.
4666:
4667: @item
4668: During initial RTL generation, shared structure is freely introduced.
4669: After all the RTL for a function has been generated, all shared
4670: structure is copied by @code{unshare_all_rtl} in @file{emit-rtl.c},
4671: after which the above rules are guaranteed to be followed.
4672:
4673: @item
4674: During the combiner pass, shared structure with an insn can exist
4675: temporarily. However, the shared structure is copied before the
4676: combiner is finished with the insn. This is done by
4677: @code{copy_substitutions} in @samp{combine.c}.
4678: @end itemize
4679:
4680: @node Machine Desc, Machine Macros, RTL, Top
4681: @chapter Machine Descriptions
4682:
4683: A machine description has two parts: a file of instruction patterns
4684: (@file{.md} file) and a C header file of macro definitions.
4685:
4686: The @file{.md} file for a target machine contains a pattern for each
4687: instruction that the target machine supports (or at least each instruction
4688: that is worth telling the compiler about). It may also contain comments.
4689: A semicolon causes the rest of the line to be a comment, unless the semicolon
4690: is inside a quoted string.
4691:
4692: See the next chapter for information on the C header file.
4693:
4694: @menu
4695: * Patterns:: How to write instruction patterns.
4696: * Example:: An explained example of a @samp{define_insn} pattern.
4697: * RTL Template:: The RTL template defines what insns match a pattern.
4698: * Output Template:: The output template says how to make assembler code
4699: from such an insn.
4700: * Output Statement:: For more generality, write C code to output
4701: the assembler code.
4702: * Constraints:: When not all operands are general operands.
4703: * Standard Names:: Names mark patterns to use for code generation.
4704: * Pattern Ordering:: When the order of patterns makes a difference.
4705: * Dependent Patterns:: Having one pattern may make you need another.
4706: * Jump Patterns:: Special considerations for patterns for jump insns.
4707: * Peephole Definitions::Defining machine-specific peephole optimizations.
4708: * Expander Definitions::Generating a sequence of several RTL insns
4709: for a standard operation.
4710: @end menu
4711:
4712: @node Patterns, Example, Machine Desc, Machine Desc
4713: @section Everything about Instruction Patterns
4714:
4715: Each instruction pattern contains an incomplete RTL expression, with pieces
4716: to be filled in later, operand constraints that restrict how the pieces can
4717: be filled in, and an output pattern or C code to generate the assembler
4718: output, all wrapped up in a @samp{define_insn} expression.
4719:
4720: A @samp{define_insn} is an RTL expression containing four or five operands:
4721:
4722: @enumerate
4723: @item
4724: An optional name. The presence of a name indicate that this instruction
4725: pattern can perform a certain standard job for the RTL-generation
4726: pass of the compiler. This pass knows certain names and will use
4727: the instruction patterns with those names, if the names are defined
4728: in the machine description.
4729:
4730: The absence of a name is indicated by writing an empty string
4731: where the name should go. Nameless instruction patterns are never
4732: used for generating RTL code, but they may permit several simpler insns
4733: to be combined later on.
4734:
4735: Names that are not thus known and used in RTL-generation have no
4736: effect; they are equivalent to no name at all.
4737:
4738: @item
4739: The @dfn{RTL template} (@pxref{RTL Template}) is a vector of
4740: incomplete RTL expressions which show what the instruction should look
4741: like. It is incomplete because it may contain @samp{match_operand}
4742: and @samp{match_dup} expressions that stand for operands of the
4743: instruction.
4744:
4745: If the vector has only one element, that element is what the
4746: instruction should look like. If the vector has multiple elements,
4747: then the instruction looks like a @samp{parallel} expression
4748: containing that many elements as described.
4749:
4750: @item
4751: A condition. This is a string which contains a C expression that is
4752: the final test to decide whether an insn body matches this pattern.
4753:
4754: For a named pattern, the condition (if present) may not depend on
4755: the data in the insn being matched, but only the target-machine-type
4756: flags. The compiler needs to test these conditions during
4757: initialization in order to learn exactly which named instructions are
4758: available in a particular run.
4759:
4760: For nameless patterns, the condition is applied only when matching an
4761: individual insn, and only after the insn has matched the pattern's
4762: recognition template. The insn's operands may be found in the vector
4763: @code{operands}.
4764:
4765: @item
4766: The @dfn{output template}: a string that says how to output matching
4767: insns as assembler code. @samp{%} in this string specifies where
4768: to substitute the value of an operand. @xref{Output Template}.
4769:
4770: When simple substitution isn't general enough, you can specify a piece
4771: of C code to compute the output. @xref{Output Statement}.
4772:
4773: @item
4774: Optionally, some @dfn{machine-specific information}. The meaning
4775: of this information is defined only by an individual machine description;
4776: typically it might say whether this insn alters the condition codes,
4777: or how many bytes of output it generates.
4778:
4779: This operand is written as a string containing a C initializer
4780: (complete with braces) for the structure type @code{INSN_MACHINE_INFO},
4781: whose definition is up to you (@pxref{Misc}).
4782: @end enumerate
4783:
4784: @node Example, RTL Template, Patterns, Machine Desc
4785: @section Example of @samp{define_insn}
4786:
4787: Here is an actual example of an instruction pattern, for the 68000/68020.
4788:
4789: @example
4790: (define_insn "tstsi"
4791: [(set (cc0)
4792: (match_operand:SI 0 "general_operand" "rm"))]
4793: ""
4794: "*
4795: @{ if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
4796: return \"tstl %0\";
4797: return \"cmpl #0,%0\"; @}")
4798: @end example
4799:
4800: This is an instruction that sets the condition codes based on the value of
4801: a general operand. It has no condition, so any insn whose RTL description
4802: has the form shown may be handled according to this pattern. The name
4803: @samp{tstsi} means ``test a @code{SImode} value'' and tells the RTL generation
4804: pass that, when it is necessary to test such a value, an insn to do so
4805: can be constructed using this pattern.
4806:
4807: The output control string is a piece of C code which chooses which
4808: output template to return based on the kind of operand and the specific
4809: type of CPU for which code is being generated.
4810:
4811: @samp{"rm"} is an operand constraint. Its meaning is explained below.
4812:
4813: @node RTL Template, Output Template, Example, Machine Desc
4814: @section RTL Template for Generating and Recognizing Insns
4815:
4816: The RTL template is used to define which insns match the particular pattern
4817: and how to find their operands. For named patterns, the RTL template also
4818: says how to construct an insn from specified operands.
4819:
4820: Construction involves substituting specified operands into a copy of the
4821: template. Matching involves determining the values that serve as the
4822: operands in the insn being matched. Both of these activities are
4823: controlled by special expression types that direct matching and
4824: substitution of the operands.
4825:
4826: @table @code
4827: @item (match_operand:@var{m} @var{n} @var{testfn} @var{constraint})
4828: This expression is a placeholder for operand number @var{n} of
4829: the insn. When constructing an insn, operand number @var{n}
4830: will be substituted at this point. When matching an insn, whatever
4831: appears at this position in the insn will be taken as operand
4832: number @var{n}; but it must satisfy @var{testfn} or this instruction
4833: pattern will not match at all.
4834:
4835: Operand numbers must be chosen consecutively counting from zero in
4836: each instruction pattern. There may be only one @samp{match_operand}
4837: expression in the pattern for each operand number. Usually operands
4838: are numbered in the order of appearance in @samp{match_operand}
4839: expressions.
4840:
4841: @var{testfn} is a string that is the name of a C function that accepts
4842: two arguments, a machine mode and an expression. During matching,
4843: the function will be called with @var{m} as the mode argument
4844: and the putative operand as the other argument. If it returns zero,
4845: this instruction pattern fails to match. @var{testfn} may be
4846: an empty string; then it means no test is to be done on the operand.
4847:
4848: @var{constraint} is explained later (@pxref{Constraints}).
4849:
4850: Most often, @var{testfn} is @code{"general_operand"}. It checks
4851: that the putative operand is either a constant, a register or a
4852: memory reference, and that it is valid for mode @var{m}.
4853:
4854: For an operand that must be a register, @var{testfn} should be
4855: @code{"register_operand"}. It would be valid to use
4856: @code{"general_operand"}, since the reload pass would copy any
4857: non-register operands through registers, but this would make GNU CC do
4858: extra work, and it would prevent the register allocator from doing the
4859: best possible job.
4860:
4861: For an operand that must be a constant, either @var{testfn} should be
4862: @code{"immediate_operand"}, or the instruction pattern's extra
4863: condition should check for constants, or both. You cannot expect the
4864: constraints to do this work! If the constraints allow only constants,
4865: but the predicate allows something else, the compiler will crash when
4866: that case arises.
4867:
4868: @item (match_dup @var{n})
4869: This expression is also a placeholder for operand number @var{n}.
4870: It is used when the operand needs to appear more than once in the
4871: insn.
4872:
4873: In construction, @samp{match_dup} behaves exactly like
4874: @samp{match_operand}: the operand is substituted into the insn being
4875: constructed. But in matching, @samp{match_dup} behaves differently.
4876: It assumes that operand number @var{n} has already been determined by
4877: a @samp{match_operand} appearing earlier in the recognition template,
4878: and it matches only an identical-looking expression.
4879:
1.1.1.4 ! root 4880: @item (match_operator:@var{m} @var{n} "@var{predicate}" [@var{operands}@dots{}])
! 4881: This pattern is a kind of placeholder for a variable RTL expression
! 4882: code.
! 4883:
! 4884: When constructing an insn, it stands for an RTL expression whose
! 4885: expression code is taken from that of operand @var{n}, and whose
! 4886: operands are constructed from the patterns @var{operands}.
! 4887:
! 4888: When matching an expression, it matches an expression if the function
! 4889: @var{predicate} returns nonzero on that expression @emph{and} the
! 4890: patterns @var{operands} match the operands of the expression.
! 4891:
! 4892: Suppose that the function @code{commutative_operator} is defined as
! 4893: follows, to match any expression whose operator is one of the six
! 4894: commutative arithmetic operators of RTL and whose mode is @var{mode}:
! 4895:
! 4896: @example
! 4897: int
! 4898: commutative_operator (x, mode)
! 4899: rtx x;
! 4900: enum machine_mode mode;
! 4901: @{
! 4902: enum rtx_code code = GET_CODE (x);
! 4903: if (GET_MODE (x) != mode)
! 4904: return 0;
! 4905: return (code == PLUS || code == MULT || code == UMULT
! 4906: || code == AND || code == IOR || code == XOR);
! 4907: @}
! 4908: @end example
! 4909:
! 4910: Then the following pattern will match any RTL expression consisting
! 4911: of a commutative operator applied to two general operands:
! 4912:
! 4913: @example
! 4914: (match_operator:SI 2 "commutative_operator"
! 4915: [(match_operand:SI 3 "general_operand" "g")
! 4916: (match_operand:SI 4 "general_operand" "g")])
! 4917: @end example
! 4918:
! 4919: Here the vector @code{[@var{operands}@dots{}]} contains two patterns
! 4920: because the expressions to be matched all contain two operands.
! 4921:
! 4922: When this pattern does match, the two operands of the commutative
! 4923: operator are recorded as operands 3 and 4 of the insn. (This is done
! 4924: by the two instances of @samp{match_operator}.) Operand 2 of the insn
! 4925: will be the entire commutative expression: use @code{GET_CODE
! 4926: (operands[2])} to see which commutative operator was used.
! 4927:
! 4928: The machine mode @var{m} of @samp{match_operator} works like that of
! 4929: @samp{match_operand}: it is passed as the second argument to the
! 4930: predicate function, and that function is solely responsible for
! 4931: deciding whether the expression to be matched ``has'' that mode.
! 4932:
! 4933: When constructing an insn, argument 2 of the gen-function will specify
! 4934: the operation (i.e. the expression code) for the expression to be
! 4935: made. It should be an RTL expression, whose expression code is copied
! 4936: into a new expression whose operands are arguments 3 and 4 of the
! 4937: gen-function. The subexpressions of argument 2 are not used;
! 4938: only its expression code matters.
! 4939:
! 4940: There is no way to specify constraints in @samp{match_operator}. The
! 4941: operand of the insn which corresponds to the @samp{match_operator}
! 4942: never has any constraints because it is never reloaded as a whole.
! 4943: However, if parts of its @var{operands} are matched by
! 4944: @samp{match_operand} patterns, those parts may have constraints of
! 4945: their own.
! 4946:
1.1 root 4947: @item (address (match_operand:@var{m} @var{n} "address_operand" ""))
4948: This complex of expressions is a placeholder for an operand number
4949: @var{n} in a ``load address'' instruction: an operand which specifies
4950: a memory location in the usual way, but for which the actual operand
4951: value used is the address of the location, not the contents of the
4952: location.
4953:
4954: @samp{address} expressions never appear in RTL code, only in machine
4955: descriptions. And they are used only in machine descriptions that do
4956: not use the operand constraint feature. When operand constraints are
4957: in use, the letter @samp{p} in the constraint serves this purpose.
4958:
4959: @var{m} is the machine mode of the @emph{memory location being
4960: addressed}, not the machine mode of the address itself. That mode is
4961: always the same on a given target machine (it is @code{Pmode}, which
4962: normally is @code{SImode}), so there is no point in mentioning it;
4963: thus, no machine mode is written in the @samp{address} expression. If
4964: some day support is added for machines in which addresses of different
4965: kinds of objects appear differently or are used differently (such as
4966: the PDP-10), different formats would perhaps need different machine
4967: modes and these modes might be written in the @samp{address}
4968: expression.
4969: @end table
4970:
4971: @node Output Template, Output Statement, RTL Template, Machine Desc
4972: @section Output Templates and Operand Substitution
4973:
4974: The @dfn{output template} is a string which specifies how to output
4975: the assembler code for an instruction pattern. Most of the template
4976: is a fixed string which is output literally. The character @samp{%}
4977: is used to specify where to substitute an operand; it can also be
4978: used to identify places different variants of the assembler require
4979: different syntax.
4980:
4981: In the simplest case, a @samp{%} followed by a digit @var{n} says to output
4982: operand @var{n} at that point in the string.
4983:
4984: @samp{%} followed by a letter and a digit says to output an operand in an
4985: alternate fashion. Four letters have standard, built-in meanings described
4986: below. The machine description macro @code{PRINT_OPERAND} can define
4987: additional letters with nonstandard meanings.
4988:
4989: @samp{%c@var{digit}} can be used to substitute an operand that is a
4990: constant value without the syntax that normally indicates an immediate
4991: operand.
4992:
4993: @samp{%n@var{digit}} is like @samp{%c@var{digit}} except that the value of
4994: the constant is negated before printing.
4995:
4996: @samp{%a@var{digit}} can be used to substitute an operand as if it were a
4997: memory reference, with the actual operand treated as the address. This may
4998: be useful when outputting a ``load address'' instruction, because often the
4999: assembler syntax for such an instruction requires you to write the operand
5000: as if it were a memory reference.
5001:
5002: @samp{%l@var{digit}} is used to substitute a @code{label_ref} into a jump
5003: instruction.
5004:
5005: @samp{%} followed by a punctuation character specifies a substitution that
5006: does not use an operand. Only one case is standard: @samp{%%} outputs a
5007: @samp{%} into the assembler code. Other nonstandard cases can be
5008: defined in the @code{PRINT_OPERAND} macro.
5009:
5010: The template may generate multiple assembler instructions. Write the text
5011: for the instructions, with @samp{\;} between them.
5012:
5013: When the RTL contains two operand which are required by constraint to match
5014: each other, the output template must refer only to the lower-numbered operand.
5015: Matching operands are not always identical, and the rest of the compiler
5016: arranges to put the proper RTL expression for printing into the lower-numbered
5017: operand.
5018:
5019: One use of nonstandard letters or punctuation following @samp{%} is to
5020: distinguish between different assembler languages for the same machine; for
5021: example, Motorola syntax versus MIT syntax for the 68000. Motorola syntax
5022: requires periods in most opcode names, while MIT syntax does not. For
5023: example, the opcode @samp{movel} in MIT syntax is @samp{move.l} in Motorola
5024: syntax. The same file of patterns is used for both kinds of output syntax,
5025: but the character sequence @samp{%.} is used in each place where Motorola
5026: syntax wants a period. The @code{PRINT_OPERAND} macro for Motorola syntax
5027: defines the sequence to output a period; the macro for MIT syntax defines
5028: it to do nothing.
5029:
5030: @node Output Statement, Constraints, Output Template, Machine Desc
5031: @section C Statements for Generating Assembler Output
5032:
5033: Often a single fixed template string cannot produce correct and efficient
5034: assembler code for all the cases that are recognized by a single
5035: instruction pattern. For example, the opcodes may depend on the kinds of
5036: operands; or some unfortunate combinations of operands may require extra
5037: machine instructions.
5038:
5039: If the output control string starts with a @samp{*}, then it is not an
5040: output template but rather a piece of C program that should compute a
5041: template. It should execute a @code{return} statement to return the
5042: template-string you want. Most such templates use C string literals, which
5043: require doublequote characters to delimit them. To include these
5044: doublequote characters in the string, prefix each one with @samp{\}.
5045:
5046: The operands may be found in the array @code{operands}, whose C data type
5047: is @code{rtx []}.
5048:
5049: It is possible to output an assembler instruction and then go on to output
5050: or compute more of them, using the subroutine @code{output_asm_insn}. This
5051: receives two arguments: a template-string and a vector of operands. The
5052: vector may be @code{operands}, or it may be another array of @code{rtx}
5053: that you declare locally and initialize yourself.
5054:
5055: When an insn pattern has multiple alternatives in its constraints, often
5056: the appearance of the assembler code determined mostly by which alternative
5057: was matched. When this is so, the C code can test the variable
5058: @code{which_alternative}, which is the ordinal number of the alternative
5059: that was actually satisfied (0 for the first, 1 for the second alternative,
5060: etc.).
5061:
5062: For example, suppose there are two opcodes for storing zero, @samp{clrreg}
5063: for registers and @samp{clrmem} for memory locations. Here is how
5064: a pattern could use @code{which_alternative} to choose between them:
5065:
5066: @example
5067: (define_insn ""
5068: [(set (match_operand:SI 0 "general_operand" "r,m")
5069: (const_int 0))]
5070: ""
5071: "*
5072: return (which_alternative == 0
5073: ? \"clrreg %0\" : \"clrmem %0\");
5074: ")
5075: @end example
5076:
5077: @node Constraints, Standard Names, Output Statement, Machine Desc
5078: @section Operand Constraints
5079:
5080: Each @samp{match_operand} in an instruction pattern can specify a
5081: constraint for the type of operands allowed. Constraints can say whether
5082: an operand may be in a register, and which kinds of register; whether the
5083: operand can be a memory reference, and which kinds of address; whether the
5084: operand may be an immediate constant, and which possible values it may
5085: have. Constraints can also require two operands to match.
5086:
5087: @menu
5088: * Simple Constraints:: Basic use of constraints.
5089: * Multi-Alternative:: When an insn has two alternative constraint-patterns.
5090: * Class Preferences:: Constraints guide which hard register to put things in.
5091: * Modifiers:: More precise control over effects of constraints.
5092: * No Constraints:: Describing a clean machine without constraints.
5093: @end menu
5094:
5095: @node Simple Constraints, Multi-Alternative, Constraints, Constraints
5096: @subsection Simple Constraints
5097:
5098: The simplest kind of constraint is a string full of letters, each of
5099: which describes one kind of operand that is permitted. Here are
5100: the letters that are allowed:
5101:
5102: @table @asis
5103: @item @samp{m}
5104: A memory operand is allowed, with any kind of address that the machine
5105: supports in general.
5106:
5107: @item @samp{o}
5108: A memory operand is allowed, but only if the address is
5109: @dfn{offsetable}. This means that adding a small integer (actually,
5110: the width in bytes of the operand, as determined by its machine mode)
5111: may be added to the address and the result is also a valid memory
5112: address.
5113:
5114: For example, an address which is constant is offsetable; so is an
5115: address that is the sum of a register and a constant (as long as a
5116: slightly larger constant is also within the range of address-offsets
5117: supported by the machine); but an autoincrement or autodecrement
5118: address is not offsetable. More complicated indirect/indexed
5119: addresses may or may not be offsetable depending on the other
5120: addressing modes that the machine supports.
5121:
5122: Note that in an output operand which can be matched by another
5123: operand, the constraint letter @samp{o} is valid only when accompanied
5124: by both @samp{<} (if the target machine has predecrement addressing)
5125: and @samp{>} (if the target machine has preincrement addressing).
5126:
5127: When the constraint letter @samp{o} is used, the reload pass may
5128: generate instructions which copy a nonoffsetable address into an index
5129: register. The idea is that the register can be used as a replacement
5130: offsetable address. But this method requires that there be patterns
5131: to copy any kind of address into a register. Auto-increment
5132: and auto-decrement addresses are an exception; there need not be an
5133: instruction that can copy such an address into a register, because
5134: reload handles these cases specially.
5135:
5136: Most older machine designs have ``load address'' instructions which do
5137: just what is needed here. Some RISC machines do not advertise such
5138: instructions, but the possible addresses on these machines are very
5139: limited, so it is easy to fake them.
5140:
5141: @item @samp{<}
5142: A memory operand with autodecrement addressing (either predecrement or
5143: postdecrement) is allowed.
5144:
5145: @item @samp{>}
5146: A memory operand with autoincrement addressing (either preincrement or
5147: postincrement) is allowed.
5148:
5149: @item @samp{r}
5150: A register operand is allowed provided that it is in a general
5151: register.
5152:
5153: @item @samp{d}, @samp{a}, @samp{f}, @dots{}
5154: Other letters can be defined in machine-dependent fashion to stand for
5155: particular classes of registers. @samp{d}, @samp{a} and @samp{f} are
5156: defined on the 68000/68020 to stand for data, address and floating
5157: point registers.
5158:
5159: @item @samp{i}
5160: An immediate integer operand (one with constant value) is allowed.
5161: This includes symbolic constants whose values will be known only at
5162: assembly time.
5163:
5164: @item @samp{n}
5165: An immediate integer operand with a known numeric value is allowed.
5166: Many systems cannot support assembly-time constants for operands less
5167: than a word wide. Constraints for these operands should use @samp{n}
5168: rather than @samp{i}.
5169:
5170: @item @samp{I}, @samp{J}, @samp{K}, @dots{}
5171: Other letters in the range @samp{I} through @samp{M} may be defined in
5172: a machine-dependent fashion to permit immediate integer operands with
5173: explicit integer values in specified ranges. For example, on the
5174: 68000, @samp{I} is defined to stand for the range of values 1 to 8.
5175: This is the range permitted as a shift count in the shift
5176: instructions.
5177:
5178: @item @samp{F}
5179: An immediate floating operand (expression code @samp{const_double}) is
5180: allowed.
5181:
5182: @item @samp{G}, @samp{H}
5183: @samp{G} and @samp{H} may be defined in a machine-dependent fashion to
5184: permit immediate floating operands in particular ranges of values.
5185:
5186: @item @samp{s}
5187: An immediate integer operand whose value is not an explicit integer is
5188: allowed.
5189:
5190: This might appear strange; if an insn allows a constant operand with a
5191: value not known at compile time, it certainly must allow any known
5192: value. So why use @samp{s} instead of @samp{i}? Sometimes it allows
5193: better code to be generated.
5194:
5195: For example, on the 68000 in a fullword instruction it is possible to
5196: use an immediate operand; but if the immediate value is between -32
5197: and 31, better code results from loading the value into a register and
5198: using the register. This is because the load into the register can be
5199: done with a @samp{moveq} instruction. We arrange for this to happen
5200: by defining the letter @samp{K} to mean ``any integer outside the
5201: range -32 to 31'', and then specifying @samp{Ks} in the operand
5202: constraints.
5203:
5204: @item @samp{g}
5205: Any register, memory or immediate integer operand is allowed, except for
5206: registers that are not general registers.
5207:
5208: @item @samp{@var{n}} (a digit)
5209: An operand that matches operand number @var{n} is allowed.
5210: If a digit is used together with letters, the digit should come last.
5211:
5212: This is called a @dfn{matching constraint} and what it really means is
5213: that the assembler has only a single operand that fills two roles
5214: considered separate in the RTL insn. For example, an add insn has two
5215: input operands and one output operand in the RTL, but on most machines
5216: an add instruction really has only two operands, one of them an
5217: input-output operand.
5218:
5219: Matching constraints work only in circumstances like that add insn.
5220: More precisely, the matching constraint must appear in an input-only
5221: operand and the operand that it matches must be an output-only operand
5222: with a lower number.
5223:
5224: For operands to match in a particular case usually means that they
5225: are identical-looking RTL expressions. But in a few special cases
5226: specific kinds of dissimilarity are allowed. For example, @code{*x}
5227: as an input operand will match @code{*x++} as an output operand.
5228: For proper results in such cases, the output template should always
5229: use the output-operand's number when printing the operand.
5230:
5231: @item @samp{p}
5232: An operand that is a valid memory address is allowed. This is
5233: for ``load address'' and ``push address'' instructions.
5234:
5235: If @samp{p} is used in the constraint, the test-function in the
5236: @samp{match_operand} must be @code{address_operand}.
5237: @end table
5238:
5239: In order to have valid assembler code, each operand must satisfy
5240: its constraint. But a failure to do so does not prevent the pattern
5241: from applying to an insn. Instead, it directs the compiler to modify
5242: the code so that the constraint will be satisfied. Usually this is
5243: done by copying an operand into a register.
5244:
5245: Contrast, therefore, the two instruction patterns that follow:
5246:
5247: @example
5248: (define_insn ""
5249: [(set (match_operand:SI 0 "general_operand" "r")
5250: (plus:SI (match_dup 0)
5251: (match_operand:SI 1 "general_operand" "r")))]
5252: ""
5253: "@dots{}")
5254: @end example
5255:
5256: @noindent
5257: which has two operands, one of which must appear in two places, and
5258:
5259: @example
5260: (define_insn ""
5261: [(set (match_operand:SI 0 "general_operand" "r")
5262: (plus:SI (match_operand:SI 1 "general_operand" "0")
5263: (match_operand:SI 2 "general_operand" "r")))]
5264: ""
5265: "@dots{}")
5266: @end example
5267:
5268: @noindent
5269: which has three operands, two of which are required by a constraint to be
5270: identical. If we are considering an insn of the form
5271:
5272: @example
5273: (insn @var{n} @var{prev} @var{next}
5274: (set (reg:SI 3)
5275: (plus:SI (reg:SI 6) (reg:SI 109)))
5276: @dots{})
5277: @end example
5278:
5279: @noindent
5280: the first pattern would not apply at all, because this insn does not
5281: contain two identical subexpressions in the right place. The pattern would
5282: say, ``That does not look like an add instruction; try other patterns.''
5283: The second pattern would say, ``Yes, that's an add instruction, but there
5284: is something wrong with it.'' It would direct the reload pass of the
5285: compiler to generate additional insns to make the constraint true. The
5286: results might look like this:
5287:
5288: @example
5289: (insn @var{n2} @var{prev} @var{n}
5290: (set (reg:SI 3) (reg:SI 6))
5291: @dots{})
5292:
5293: (insn @var{n} @var{n2} @var{next}
5294: (set (reg:SI 3)
5295: (plus:SI (reg:SI 3) (reg:SI 109)))
5296: @dots{})
5297: @end example
5298:
5299: It is up to you to make sure that each operand, in each pattern, has
5300: constraints that can handle any RTL expression that could be present for
5301: that operand. (When multiple alternatives are in use, each pattern must,
5302: for each possible combination of operand expressions, have at least one
5303: alternative which can handle that combination of operands.) The
5304: constraints don't need to @emph{allow} any possible operand---when this is
5305: the case, they do not constrain---but they must at least point the way to
5306: reloading any possible operand so that it will fit.
5307:
5308: @itemize @bullet
5309: @item
5310: If the constraint accepts whatever operands the predicate permits,
5311: there is no problem: reloading is never necessary for this operand.
5312:
5313: For example, an operand whose constraints permit everything except
5314: registers is safe provided its predicate rejects registers.
5315:
5316: An operand whose predicate accepts only constant values is safe
5317: provided its constraints include the letter @samp{i}. If any possible
5318: constant value is accepted, then nothing less than @samp{i} will do;
5319: if the predicate is more selective, than the constraints may also be
5320: more selective.
5321:
5322: @item
5323: Any operand expression can be reloaded by copying it into a register.
5324: So if an operand's constraints allow some kind of register, it is
5325: certain to be safe. It need not permit all classes of registers; the
5326: compiler knows how to copy a register into another register of the
5327: proper class in order to make an instruction valid.
5328:
5329: @item
5330: A nonoffsetable memory reference can be reloaded by copying the
5331: address into a register. So if the constraint uses the letter
5332: @samp{o}, all memory references are taken care of.
5333:
5334: @item
5335: A constant operand can be reloaded by storing it in memory; it then
5336: becomes an offsetable memory reference. So if the constraint uses the
5337: letters @samp{o} or @samp{m}, constant operands are not a problem.
5338: @end itemize
5339:
5340: If the operand's predicate can recognize registers, but the constraint does
5341: not permit them, it can make the compiler crash. When this operand happens
5342: to be a register, the reload pass will be stymied, because it does not know
5343: how to copy a register temporarily into memory.
5344:
5345: @node Multi-Alternative, Class Preferences, Simple Constraints, Constraints
5346: @subsection Multiple Alternative Constraints
5347:
5348: Sometimes a single instruction has multiple alternative sets of possible
5349: operands. For example, on the 68000, a logical-or instruction can combine
5350: register or an immediate value into memory, or it can combine any kind of
5351: operand into a register; but it cannot combine one memory location into
5352: another.
5353:
5354: These constraints are represented as multiple alternatives. An alternative
5355: can be described by a series of letters for each operand. The overall
5356: constraint for an operand is made from the letters for this operand
5357: from the first alternative, a comma, the letters for this operand from
5358: the second alternative, a comma, and so on until the last alternative.
5359: Here is how it is done for fullword logical-or on the 68000:
5360:
5361: @example
5362: (define_insn "iorsi3"
5363: [(set (match_operand:SI 0 "general_operand" "=%m,d")
5364: (ior:SI (match_operand:SI 1 "general_operand" "0,0")
5365: (match_operand:SI 2 "general_operand" "dKs,dmKs")))]
5366: @dots{})
5367: @end example
5368:
5369: The first alternative has @samp{m} (memory) for operand 0, @samp{0} for
5370: operand 1 (meaning it must match operand 0), and @samp{dKs} for operand 2.
5371: The second alternative has @samp{d} (data register) for operand 0, @samp{0}
5372: for operand 1, and @samp{dmKs} for operand 2. The @samp{=} and @samp{%} in
5373: the constraint for operand 0 are not part of any alternative; their meaning
5374: is explained in the next section.
5375:
5376: If all the operands fit any one alternative, the instruction is valid.
5377: Otherwise, for each alternative, the compiler counts how many instructions
5378: must be added to copy the operands so that that alternative applies.
5379: The alternative requiring the least copying is chosen. If two alternatives
5380: need the same amount of copying, the one that comes first is chosen.
5381: These choices can be altered with the @samp{?} and @samp{!} characters:
5382:
5383: @table @samp
5384: @item ?
5385: Disparage slightly the alternative that the @samp{?} appears in,
5386: as a choice when no alternative applies exactly. The compiler regards
5387: this alternative as one unit more costly for each @samp{?} that appears
5388: in it.
5389:
5390: @item !
5391: Disparage severely the alternative that the @samp{!} appears in.
5392: When operands must be copied into registers, the compiler will
5393: never choose this alternative as the one to strive for.
5394: @end table
5395:
5396: When an insn pattern has multiple alternatives in its constraints,
5397: often the appearance of the assembler code determined mostly by which
5398: alternative was matched. When this is so, the C code for writing the
5399: assembler code can use the variable @code{which_alternative}, which is
5400: the ordinal number of the alternative that was actually satisfied
5401: (0 for the first, 1 for the second alternative, etc.). For example:
5402:
5403: @example
5404: (define_insn ""
5405: [(set (match_operand:SI 0 "general_operand" "r,m")
5406: (const_int 0))]
5407: ""
5408: "*
5409: return (which_alternative == 0
5410: ? \"clrreg %0\" : \"clrmem %0\");
5411: ")
5412: @end example
5413:
5414: @node Class Preferences, Modifiers, Multi-Alternative, Constraints
5415: @subsection Register Class Preferences
5416:
5417: The operand constraints have another function: they enable the compiler
5418: to decide which kind of hardware register a pseudo register is best
5419: allocated to. The compiler examines the constraints that apply to the
5420: insns that use the pseudo register, looking for the machine-dependent
5421: letters such as @samp{d} and @samp{a} that specify classes of registers.
5422: The pseudo register is put in whichever class gets the most ``votes''.
5423: The constraint letters @samp{g} and @samp{r} also vote: they vote in
5424: favor of a general register. The machine description says which registers
5425: are considered general.
5426:
5427: Of course, on some machines all registers are equivalent, and no register
5428: classes are defined. Then none of this complexity is relevant.
5429:
5430: @node Modifiers, No Constraints, Class Preferences, Constraints
5431: @subsection Constraint Modifier Characters
5432:
5433: @table @samp
5434: @item =
5435: Means that this operand is write-only for this instruction: the previous
5436: value is discarded and replaced by output data.
5437:
5438: @item +
5439: Means that this operand is both read and written by the instruction.
5440:
5441: When the compiler fixes up the operands to satisfy the constraints,
5442: it needs to know which operands are inputs to the instruction and
5443: which are outputs from it. @samp{=} identifies an output; @samp{+}
5444: identifies an operand that is both input and output; all other operands
5445: are assumed to be input only.
5446:
5447: @item &
5448: Means (in a particular alternative) that this operand is written
5449: before the instruction is finished using the input operands.
5450: Therefore, this operand may not lie in a register that is used as an
5451: input operand or as part of any memory address.
5452:
5453: @samp{&} applies only to the alternative in which it is written. In
5454: constraints with multiple alternatives, sometimes one alternative
5455: requires @samp{&} while others do not. See, for example, the
5456: @samp{movdf} insn of the 68000.
5457:
5458: @samp{&} does not obviate the need to write @samp{=}.
5459:
5460: @item %
5461: Declares the instruction to be commutative for this operand and the
5462: following operand. This means that the compiler may interchange the
5463: two operands if that is the cheapest way to make all operands fit the
5464: constraints. This is often used in patterns for addition instructions
5465: that really have only two operands: the result must go in one of the
5466: arguments. Here for example, is how the 68000 halfword-add
5467: instruction is defined:
5468:
5469: @example
5470: (define_insn "addhi3"
5471: [(set (match_operand:HI 0 "general_operand" "=m,r")
5472: (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
5473: (match_operand:HI 2 "general_operand" "di,g")))]
5474: @dots{})
5475: @end example
5476:
5477: Note that in previous versions of GNU CC the @samp{%} constraint
5478: modifier always applied to operands 1 and 2 regardless of which
5479: operand it was written in. The usual custom was to write it in
5480: operand 0. Now it must be in operand 1 if the operands to be
5481: exchanged are 1 and 2.
5482:
5483: @item #
5484: Says that all following characters, up to the next comma, are to be
5485: ignored as a constraint. They are significant only for choosing
5486: register preferences.
5487:
5488: @item *
5489: Says that the following character should be ignored when choosing
5490: register preferences. @samp{*} has no effect on the meaning of the
5491: constraint as a constraint.
5492:
5493: Here is an example: the 68000 has an instruction to sign-extend a
5494: halfword in a data register, and can also sign-extend a value by
5495: copying it into an address register. While either kind of register is
5496: acceptable, the constraints on an address-register destination are
5497: less strict, so it is best if register allocation makes an address
5498: register its goal. Therefore, @samp{*} is used so that the @samp{d}
5499: constraint letter (for data register) is ignored when computing
5500: register preferences.
5501:
5502: @example
5503: (define_insn "extendhisi2"
5504: [(set (match_operand:SI 0 "general_operand" "=*d,a")
5505: (sign_extend:SI
5506: (match_operand:HI 1 "general_operand" "0,g")))]
5507: @dots{})
5508: @end example
5509: @end table
5510:
5511: @node No Constraints,, Modifiers, Constraints
5512: @subsection Not Using Constraints
5513:
5514: Some machines are so clean that operand constraints are not required. For
5515: example, on the Vax, an operand valid in one context is valid in any other
5516: context. On such a machine, every operand constraint would be @samp{g},
5517: excepting only operands of ``load address'' instructions which are
5518: written as if they referred to a memory location's contents but actual
5519: refer to its address. They would have constraint @samp{p}.
5520:
5521: For such machines, instead of writing @samp{g} and @samp{p} for all
5522: the constraints, you can choose to write a description with empty constraints.
5523: Then you write @samp{""} for the constraint in every @samp{match_operand}.
5524: Address operands are identified by writing an @samp{address} expression
5525: around the @samp{match_operand}, not by their constraints.
5526:
5527: When the machine description has just empty constraints, certain parts
5528: of compilation are skipped, making the compiler faster.
5529:
5530: @node Standard Names, Pattern Ordering, Constraints, Machine Desc
5531: @section Standard Names for Patterns Used in Generation
5532:
5533: Here is a table of the instruction names that are meaningful in the RTL
5534: generation pass of the compiler. Giving one of these names to an
5535: instruction pattern tells the RTL generation pass that it can use the
5536: pattern in to accomplish a certain task.
5537:
5538: @table @asis
5539: @item @samp{mov@var{m}}
5540: Here @var{m} is a two-letter machine mode name, in lower case. This
5541: instruction pattern moves data with that machine mode from operand 1 to
5542: operand 0. For example, @samp{movsi} moves full-word data.
5543:
5544: If operand 0 is a @samp{subreg} with mode @var{m} of a register whose
5545: natural mode is wider than @var{m}, the effect of this instruction is
5546: to store the specified value in the part of the register that corresponds
5547: to mode @var{m}. The effect on the rest of the register is undefined.
5548:
5549: This class of patterns is special in several ways. First of all, each
5550: of these names @emph{must} be defined, because there is no other way
5551: to copy a datum from one place to another.
5552:
5553: Second, these patterns are not used solely in the RTL generation pass.
5554: Even the reload pass can generate move insns to copy values from stack
5555: slots into temporary registers. When it does so, one of the operands
5556: is a hard register and the other is an operand that can have a reload.
5557:
5558: Therefore, when given such a pair of operands, the pattern must
5559: generate RTL which needs no temporary registers---no registers other
5560: than the operands. For example, if you support the pattern with a
5561: @code{define_expand}, then in such a case you mustn't call
5562: @code{force_reg} or any other such function which might generate new
5563: pseudo registers.
5564:
5565: This requirement exists even for subword modes on a RISC machine where
5566: fetching those modes from memory normally requires several insns and
5567: some temporary registers. Look in @file{spur.md} to see how the
5568: requirement is satisfied.
5569:
5570: The variety of operands that have reloads depends on the rest of the
5571: machine description, but typically on a RISC machine these can only be
5572: pseudo registers that did not get hard registers, while on other
5573: machines explicit memory references will get optional reloads.
5574:
5575: In addition, the constraints must allow any hard register to be moved
5576: to any other hard register (provided that @code{HARD_REGNO_MODE_OK}
5577: permits mode @var{m} in each of the registers).
5578:
5579: @item @samp{movstrict@var{m}}
5580: Like @samp{mov@var{m}} except that if operand 0 is a @samp{subreg}
5581: with mode @var{m} of a register whose natural mode is wider,
5582: the @samp{movstrict@var{m}} instruction is guaranteed not to alter
5583: any of the register except the part which belongs to mode @var{m}.
5584:
5585: @item @samp{add@var{m}3}
5586: Add operand 2 and operand 1, storing the result in operand 0. All operands
5587: must have mode @var{m}. This can be used even on two-address machines, by
5588: means of constraints requiring operands 1 and 0 to be the same location.
5589:
5590: @item @samp{sub@var{m}3}, @samp{mul@var{m}3}, @samp{umul@var{m}3}, @samp{div@var{m}3}, @samp{udiv@var{m}3}, @samp{mod@var{m}3}, @samp{umod@var{m}3}, @samp{and@var{m}3}, @samp{ior@var{m}3}, @samp{xor@var{m}3}
5591: Similar, for other arithmetic operations.
5592:
5593: There are special considerations for register classes for logical-and
5594: instructions, affecting also the macro @code{PREFERRED_RELOAD_CLASS}.
5595: They apply not only to the patterns with these standard names, but to
5596: any patterns that will match such an instruction. @xref{Register
5597: Classes}.
5598:
5599: @item @samp{mulhisi3}
5600: Multiply operands 1 and 2, which have mode @code{HImode}, and store
5601: a @code{SImode} product in operand 0.
5602:
5603: @item @samp{mulqihi3}, @samp{mulsidi3}
5604: Similar widening-multiplication instructions of other widths.
5605:
5606: @item @samp{umulqihi3}, @samp{umulhisi3}, @samp{umulsidi3}
5607: Similar widening-multiplication instructions that do unsigned
5608: multiplication.
5609:
5610: @item @samp{divmod@var{m}4}
5611: Signed division that produces both a quotient and a remainder.
5612: Operand 1 is divided by operand 2 to produce a quotient stored
5613: in operand 0 and a remainder stored in operand 3.
5614:
5615: @item @samp{udivmod@var{m}4}
5616: Similar, but does unsigned division.
5617:
5618: @item @samp{divmod@var{m}@var{n}4}
5619: Like @samp{divmod@var{m}4} except that only the dividend has mode
5620: @var{m}; the divisor, quotient and remainder have mode @var{n}.
5621: For example, the Vax has a @samp{divmoddisi4} instruction
5622: (but it is omitted from the machine description, because it
5623: is so slow that it is faster to compute remainders by the
5624: circumlocution that the compiler will use if this instruction is
5625: not available).
5626:
5627: @item @samp{ashl@var{m}3}
5628: Arithmetic-shift operand 1 left by a number of bits specified by
5629: operand 2, and store the result in operand 0. Operand 2 has
5630: mode @code{SImode}, not mode @var{m}.
5631:
5632: @item @samp{ashr@var{m}3}, @samp{lshl@var{m}3}, @samp{lshr@var{m}3}, @samp{rotl@var{m}3}, @samp{rotr@var{m}3}
5633: Other shift and rotate instructions.
5634:
5635: Logical and arithmetic left shift are the same. Machines that do not
5636: allow negative shift counts often have only one instruction for
5637: shifting left. On such machines, you should define a pattern named
5638: @samp{ashl@var{m}3} and leave @samp{lshl@var{m}3} undefined.
5639:
5640: There are special considerations for register classes for shift
5641: instructions, affecting also the macro @code{PREFERRED_RELOAD_CLASS}.
5642: They apply not only to the patterns with these standard names, but to
5643: any patterns that will match such an instruction. @xref{Register
5644: Classes}.
5645:
5646: @item @samp{neg@var{m}2}
5647: Negate operand 1 and store the result in operand 0.
5648:
5649: @item @samp{abs@var{m}2}
5650: Store the absolute value of operand 1 into operand 0.
5651:
5652: @item @samp{sqrt@var{m}2}
5653: Store the square root of operand 1 into operand 0.
5654:
5655: @item @samp{ffs@var{m}2}
5656: Store into operand 0 one plus the index of the least significant 1-bit
5657: of operand 1. If operand 1 is zero, store zero. @var{m} is the mode
5658: of operand 0; operand 1's mode is specified by the instruction
5659: pattern, and the compiler will convert the operand to that mode before
5660: generating the instruction.
5661:
5662: @item @samp{one_cmpl@var{m}2}
5663: Store the bitwise-complement of operand 1 into operand 0.
5664:
5665: @item @samp{cmp@var{m}}
5666: Compare operand 0 and operand 1, and set the condition codes.
5667: The RTL pattern should look like this:
5668:
5669: @example
5670: (set (cc0) (minus (match_operand:@var{m} 0 @dots{})
5671: (match_operand:@var{m} 1 @dots{})))
5672: @end example
5673:
5674: Each such definition in the machine description, for integer mode
5675: @var{m}, must have a corresponding @samp{tst@var{m}} pattern, because
5676: optimization can simplify the compare into a test when operand 1 is
5677: zero.
5678:
5679: @item @samp{tst@var{m}}
5680: Compare operand 0 against zero, and set the condition codes.
5681: The RTL pattern should look like this:
5682:
5683: @example
5684: (set (cc0) (match_operand:@var{m} 0 @dots{}))
5685: @end example
5686:
5687: @item @samp{movstr@var{m}}
5688: Block move instruction. The addresses of the destination and source
5689: strings are the first two operands, and both are in mode @code{Pmode}.
5690: The number of bytes to move is the third operand, in mode @var{m}.
5691:
5692: @item @samp{cmpstr@var{m}}
5693: Block compare instruction, with operands like @samp{movstr@var{m}}
5694: except that the two memory blocks are compared byte by byte
5695: in lexicographic order. The effect of the instruction is to set
5696: the condition codes.
5697:
5698: @item @samp{float@var{m}@var{n}2}
5699: Convert operand 1 (valid for fixed point mode @var{m}) to floating
5700: point mode @var{n} and store in operand 0 (which has mode @var{n}).
5701:
5702: @item @samp{fix@var{m}@var{n}2}
5703: Convert operand 1 (valid for floating point mode @var{m}) to fixed
5704: point mode @var{n} as a signed number and store in operand 0 (which
5705: has mode @var{n}). This instruction's result is defined only when
5706: the value of operand 1 is an integer.
5707:
5708: @item @samp{fixuns@var{m}@var{n}2}
5709: Convert operand 1 (valid for floating point mode @var{m}) to fixed
5710: point mode @var{n} as an unsigned number and store in operand 0 (which
5711: has mode @var{n}). This instruction's result is defined only when the
5712: value of operand 1 is an integer.
5713:
5714: @item @samp{ftrunc@var{m}2}
5715: Convert operand 1 (valid for floating point mode @var{m}) to an
5716: integer value, still represented in floating point mode @var{m}, and
5717: store it in operand 0 (valid for floating point mode @var{m}).
5718:
5719: @item @samp{fix_trunc@var{m}@var{n}2}
5720: Like @samp{fix@var{m}@var{n}2} but works for any floating point value
5721: of mode @var{m} by converting the value to an integer.
5722:
5723: @item @samp{fixuns_trunc@var{m}@var{n}2}
5724: Like @samp{fixuns@var{m}@var{n}2} but works for any floating point
5725: value of mode @var{m} by converting the value to an integer.
5726:
5727: @item @samp{trunc@var{m}@var{n}}
5728: Truncate operand 1 (valid for mode @var{m}) to mode @var{n} and
5729: store in operand 0 (which has mode @var{n}). Both modes must be fixed
5730: point or both floating point.
5731:
5732: @item @samp{extend@var{m}@var{n}}
5733: Sign-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
5734: store in operand 0 (which has mode @var{n}). Both modes must be fixed
5735: point or both floating point.
5736:
5737: @item @samp{zero_extend@var{m}@var{n}}
5738: Zero-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
5739: store in operand 0 (which has mode @var{n}). Both modes must be fixed
5740: point.
5741:
5742: @item @samp{extv}
5743: Extract a bit-field from operand 1 (a register or memory operand),
5744: where operand 2 specifies the width in bits and operand 3 the starting
5745: bit, and store it in operand 0. Operand 0 must have @code{Simode}.
5746: Operand 1 may have mode @code{QImode} or @code{SImode}; often
5747: @code{SImode} is allowed only for registers. Operands 2 and 3 must be
5748: valid for @code{SImode}.
5749:
5750: The RTL generation pass generates this instruction only with constants
5751: for operands 2 and 3.
5752:
5753: The bit-field value is sign-extended to a full word integer
5754: before it is stored in operand 0.
5755:
5756: @item @samp{extzv}
5757: Like @samp{extv} except that the bit-field value is zero-extended.
5758:
5759: @item @samp{insv}
5760: Store operand 3 (which must be valid for @code{SImode}) into a
5761: bit-field in operand 0, where operand 1 specifies the width in bits
5762: and operand 2 the starting bit. Operand 0 may have mode @code{QImode}
5763: or @code{SImode}; often @code{SImode} is allowed only for registers.
5764: Operands 1 and 2 must be valid for @code{SImode}.
5765:
5766: The RTL generation pass generates this instruction only with constants
5767: for operands 1 and 2.
5768:
5769: @item @samp{s@var{cond}}
5770: Store zero or nonzero in the operand according to the condition codes.
5771: Value stored is nonzero iff the condition @var{cond} is true.
5772: @var{cond} is the name of a comparison operation expression code, such
5773: as @samp{eq}, @samp{lt} or @samp{leu}.
5774:
5775: You specify the mode that the operand must have when you write the
5776: @code{match_operand} expression. The compiler automatically sees
5777: which mode you have used and supplies an operand of that mode.
5778:
5779: The value stored for a true condition must have 1 as its low bit.
5780: Otherwise the instruction is not suitable and must be omitted from the
5781: machine description. You must tell the compiler exactly which value
5782: is stored by defining the macro @code{STORE_FLAG_VALUE}.
5783:
5784: @item @samp{b@var{cond}}
5785: Conditional branch instruction. Operand 0 is a @samp{label_ref}
5786: that refers to the label to jump to. Jump if the condition codes
5787: meet condition @var{cond}.
5788:
5789: @item @samp{call}
5790: Subroutine call instruction returning no value. Operand 0 is the
5791: function to call; operand 1 is the number of bytes of arguments pushed
5792: (in mode @code{SImode}, except it is normally a @samp{const_int});
5793: operand 2 is the number of registers used as operands.
5794:
5795: On most machines, operand 2 is not actually stored into the RTL
5796: pattern. It is supplied for the sake of some RISC machines which need
5797: to put this information into the assembler code; they can put it in
5798: the RTL instead of operand 1.
5799:
5800: Operand 0 should be a @samp{mem} RTX whose address is the address of
5801: the function.
5802:
5803: @item @samp{call_value}
5804: Subroutine call instruction returning a value. Operand 0 is the hard
5805: register in which the value is returned. There are three more
5806: operands, the same as the three operands of the @samp{call}
5807: instruction (but with numbers increased by one).
5808:
5809: Subroutines that return @code{BLKmode} objects use the @samp{call}
5810: insn.
5811:
5812: @item @samp{return}
5813: Subroutine return instruction. This instruction pattern name should be
5814: defined only if a single instruction can do all the work of returning
5815: from a function.
5816:
5817: @item @samp{casesi}
5818: Instruction to jump through a dispatch table, including bounds checking.
5819: This instruction takes five operands:
5820:
5821: @enumerate
5822: @item
5823: The index to dispatch on, which has mode @code{SImode}.
5824:
5825: @item
5826: The lower bound for indices in the table, an integer constant.
5827:
5828: @item
5829: The upper bound for indices in the table, an integer constant.
5830:
5831: @item
5832: A label to jump to if the index has a value outside the bounds.
5833: (If the machine-description macro @code{CASE_DROPS_THROUGH} is defined,
5834: then an out-of-bounds index drops through to the code following
5835: the jump table instead of jumping to this label. In that case,
5836: this label is not actually used by the @samp{casesi} instruction,
5837: but it is always provided as an operand.)
5838:
5839: @item
5840: A label that precedes the table itself.
5841: @end enumerate
5842:
5843: The table is a @samp{addr_vec} or @samp{addr_diff_vec} inside of a
5844: @samp{jump_insn}. The number of elements in the table is one plus the
5845: difference between the upper bound and the lower bound.
5846:
5847: @item @samp{tablejump}
5848: Instruction to jump to a variable address. This is a low-level
5849: capability which can be used to implement a dispatch table when there
5850: is no @samp{casesi} pattern.
5851:
5852: This pattern requires two operands: the address or offset, and a label
5853: which should immediately precede the jump table. If the macro
5854: @code{CASE_VECTOR_PC_RELATIVE} is defined then the first operand is an
5855: absolute address to jump to; otherwise, it is an offset which counts
5856: from the address of the table.
5857:
5858: The @samp{tablejump} insn is always the last insn before the jump
5859: table it uses. Its assembler code normally has no need to use the
5860: second operand, but you should incorporate it in the RTL pattern so
5861: that the jump optimizer will not delete the table as unreachable code.
5862: @end table
5863:
5864: @node Pattern Ordering, Dependent Patterns, Standard Names, Machine Desc
5865: @section When the Order of Patterns Matters
5866:
5867: Sometimes an insn can match more than one instruction pattern. Then the
5868: pattern that appears first in the machine description is the one used.
5869: Therefore, more specific patterns (patterns that will match fewer things)
5870: and faster instructions (those that will produce better code when they
5871: do match) should usually go first in the description.
5872:
5873: In some cases the effect of ordering the patterns can be used to hide
5874: a pattern when it is not valid. For example, the 68000 has an
5875: instruction for converting a fullword to floating point and another
5876: for converting a byte to floating point. An instruction converting
5877: an integer to floating point could match either one. We put the
5878: pattern to convert the fullword first to make sure that one will
5879: be used rather than the other. (Otherwise a large integer might
5880: be generated as a single-byte immediate quantity, which would not work.)
5881: Instead of using this pattern ordering it would be possible to make the
5882: pattern for convert-a-byte smart enough to deal properly with any
5883: constant value.
5884:
5885: @node Dependent Patterns, Jump Patterns, Pattern Ordering, Machine Desc
5886: @section Interdependence of Patterns
5887:
5888: Every machine description must have a named pattern for each of the
5889: conditional branch names @samp{b@var{cond}}. The recognition template
5890: must always have the form
5891:
5892: @example
5893: (set (pc)
5894: (if_then_else (@var{cond} (cc0) (const_int 0))
5895: (label_ref (match_operand 0 "" ""))
5896: (pc)))
5897: @end example
5898:
5899: @noindent
5900: In addition, every machine description must have an anonymous pattern
5901: for each of the possible reverse-conditional branches. These patterns
5902: look like
5903:
5904: @example
5905: (set (pc)
5906: (if_then_else (@var{cond} (cc0) (const_int 0))
5907: (pc)
5908: (label_ref (match_operand 0 "" ""))))
5909: @end example
5910:
5911: @noindent
5912: They are necessary because jump optimization can turn direct-conditional
5913: branches into reverse-conditional branches.
5914:
5915: The compiler does more with RTL than just create it from patterns
5916: and recognize the patterns: it can perform arithmetic expression codes
5917: when constant values for their operands can be determined. As a result,
5918: sometimes having one pattern can require other patterns. For example, the
5919: Vax has no `and' instruction, but it has `and not' instructions. Here
5920: is the definition of one of them:
5921:
5922: @example
5923: (define_insn "andcbsi2"
5924: [(set (match_operand:SI 0 "general_operand" "")
5925: (and:SI (match_dup 0)
5926: (not:SI (match_operand:SI
5927: 1 "general_operand" ""))))]
5928: ""
5929: "bicl2 %1,%0")
5930: @end example
5931:
5932: @noindent
5933: If operand 1 is an explicit integer constant, an instruction constructed
5934: using that pattern can be simplified into an `and' like this:
5935:
5936: @example
5937: (set (reg:SI 41)
5938: (and:SI (reg:SI 41)
5939: (const_int 0xffff7fff)))
5940: @end example
5941:
5942: @noindent
5943: (where the integer constant is the one's complement of what
5944: appeared in the original instruction).
5945:
5946: To avoid a fatal error, the compiler must have a pattern that recognizes
5947: such an instruction. Here is what is used:
5948:
5949: @example
5950: (define_insn ""
5951: [(set (match_operand:SI 0 "general_operand" "")
5952: (and:SI (match_dup 0)
5953: (match_operand:SI 1 "general_operand" "")))]
5954: "GET_CODE (operands[1]) == CONST_INT"
5955: "*
5956: @{ operands[1]
5957: = gen_rtx (CONST_INT, VOIDmode, ~INTVAL (operands[1]));
5958: return \"bicl2 %1,%0\";
5959: @}")
5960: @end example
5961:
5962: @noindent
5963: Whereas a pattern to match a general `and' instruction is impossible to
5964: support on the Vax, this pattern is possible because it matches only a
5965: constant second argument: a special case that can be output as an `and not'
5966: instruction.
5967:
5968: A ``compare'' instruction whose RTL looks like this:
5969:
5970: @example
5971: (set (cc0) (minus @var{operand} (const_int 0)))
5972: @end example
5973:
5974: @noindent
5975: may be simplified by optimization into a ``test'' like this:
5976:
5977: @example
5978: (set (cc0) @var{operand})
5979: @end example
5980:
5981: @noindent
5982: So in the machine description, each ``compare'' pattern for an integer
5983: mode must have a corresponding ``test'' pattern that will match the
5984: result of such simplification.
5985:
5986: In some cases machines support instructions identical except for the
5987: machine mode of one or more operands. For example, there may be
5988: ``sign-extend halfword'' and ``sign-extend byte'' instructions whose
5989: patterns are
5990:
5991: @example
5992: (set (match_operand:SI 0 @dots{})
5993: (extend:SI (match_operand:HI 1 @dots{})))
5994:
5995: (set (match_operand:SI 0 @dots{})
5996: (extend:SI (match_operand:QI 1 @dots{})))
5997: @end example
5998:
5999: @noindent
6000: Constant integers do not specify a machine mode, so an instruction to
6001: extend a constant value could match either pattern. The pattern it
6002: actually will match is the one that appears first in the file. For correct
6003: results, this must be the one for the widest possible mode (@code{HImode},
6004: here). If the pattern matches the @code{QImode} instruction, the results
6005: will be incorrect if the constant value does not actually fit that mode.
6006:
6007: Such instructions to extend constants are rarely generated because they are
6008: optimized away, but they do occasionally happen in nonoptimized
6009: compilations.
6010:
6011: When an instruction has the constraint letter @samp{o}, the reload
6012: pass may generate instructions which copy a nonoffsetable address into
6013: an index register. The idea is that the register can be used as a
6014: replacement offsetable address. In order for these generated
6015: instructions to work, there must be patterns to copy any kind of valid
6016: address into a register.
6017:
6018: Most older machine designs have ``load address'' instructions which do
6019: just what is needed here. Some RISC machines do not advertise such
6020: instructions, but the possible addresses on these machines are very
6021: limited, so it is easy to fake them.
6022:
6023: Auto-increment and auto-decrement addresses are an exception; there
6024: need not be an instruction that can copy such an address into a
6025: register, because reload handles these cases in a different manner.
6026:
6027: @node Jump Patterns, Peephole Definitions, Dependent Patterns, Machine Desc
6028: @section Defining Jump Instruction Patterns
6029:
6030: GNU CC assumes that the machine has a condition code. A comparison insn
6031: sets the condition code, recording the results of both signed and unsigned
6032: comparison of the given operands. A separate branch insn tests the
6033: condition code and branches or not according its value. The branch insns
6034: come in distinct signed and unsigned flavors. Many common machines, such
6035: as the Vax, the 68000 and the 32000, work this way.
6036:
6037: Some machines have distinct signed and unsigned compare instructions, and
6038: only one set of conditional branch instructions. The easiest way to handle
6039: these machines is to treat them just like the others until the final stage
6040: where assembly code is written. At this time, when outputting code for the
6041: compare instruction, peek ahead at the following branch using
6042: @code{NEXT_INSN (insn)}. (The variable @code{insn} refers to the insn
6043: being output, in the output-writing code in an instruction pattern.) If
6044: the RTL says that is an unsigned branch, output an unsigned compare;
6045: otherwise output a signed compare. When the branch itself is output, you
6046: can treat signed and unsigned branches identically.
6047:
6048: The reason you can do this is that GNU CC always generates a pair of
6049: consecutive RTL insns, one to set the condition code and one to test it,
6050: and keeps the pair inviolate until the end.
6051:
6052: To go with this technique, you must define the machine-description macro
6053: @code{NOTICE_UPDATE_CC} to do @code{CC_STATUS_INIT}; in other words, no
6054: compare instruction is superfluous.
6055:
6056: Some machines have compare-and-branch instructions and no condition code.
6057: A similar technique works for them. When it is time to ``output'' a
6058: compare instruction, record its operands in two static variables. When
6059: outputting the branch-on-condition-code instruction that follows, actually
6060: output a compare-and-branch instruction that uses the remembered operands.
6061:
6062: It also works to define patterns for compare-and-branch instructions.
6063: In optimizing compilation, the pair of compare and branch instructions
6064: will be combined accoprding to these patterns. But this does not happen
6065: if optimization is not requested. So you must use one of the solutions
6066: above in addition to any special patterns you define.
6067:
6068: @node Peephole Definitions, Expander Definitions, Jump Patterns, Machine Desc
6069: @section Defining Machine-Specific Peephole Optimizers
6070:
6071: In addition to instruction patterns the @file{md} file may contain
6072: definitions of machine-specific peephole optimizations.
6073:
6074: The combiner does not notice certain peephole optimizations when the data
6075: flow in the program does not suggest that it should try them. For example,
6076: sometimes two consecutive insns related in purpose can be combined even
6077: though the second one does not appear to use a register computed in the
6078: first one. A machine-specific peephole optimizer can detect such
6079: opportunities.
6080:
6081: A definition looks like this:
6082:
6083: @example
6084: (define_peephole
6085: [@var{insn-pattern-1}
6086: @var{insn-pattern-2}
6087: @dots{}]
6088: "@var{condition}"
6089: "@var{template}"
6090: "@var{machine-specific info}")
6091: @end example
6092:
6093: @noindent
6094: The last string operand may be omitted if you are not using any
6095: machine-specific information in this machine description. If present,
6096: it must obey the same rules as in a @samp{define_insn}.
6097:
6098: In this skeleton, @var{insn-pattern-1} and so on are patterns to match
6099: consecutive instructions. The optimization applies to a sequence of
6100: instructions when @var{insn-pattern-1} matches the first one,
6101: @var{insn-pattern-2} matches the next, and so on.@refill
6102:
6103: @var{insn-pattern-1} and so on look @emph{almost} like the second operand
6104: of @code{define_insn}. There is one important difference: this pattern is
6105: an RTX, not a vector. If the @code{define_insn} pattern would be a vector
6106: of one element, the @var{insn-pattern} should be just that element, no
6107: vector. If the @code{define_insn} pattern would have multiple elements
6108: then the @var{insn-pattern} must place the vector inside an explicit
6109: @code{parallel} RTX.@refill
6110:
6111: The operands of the instructions are matched with @code{match_operands} and
6112: @code{match_dup}, as usual). What is not usual is that the operand numbers
6113: apply to all the instruction patterns in the definition. So, you can check
6114: for identical operands in two instructions by using @code{match_operand}
6115: in one instruction and @code{match_dup} in the other.
6116:
6117: The operand constraints used in @code{match_operand} patterns do not have
6118: any direct effect on the applicability of the optimization, but they will
6119: be validated afterward, so write constraints that are sure to fit whenever
6120: the optimization is applied. It is safe to use @code{"g"} for each
6121: operand.
6122:
6123: Once a sequence of instructions matches the patterns, the @var{condition}
6124: is checked. This is a C expression which makes the final decision whether
6125: to perform the optimization (do so if the expression is nonzero). If
6126: @var{condition} is omitted (in other words, the string is empty) then the
6127: optimization is applied to every sequence of instructions that matches the
6128: patterns.
6129:
6130: The defined peephole optimizations are applied after register allocation is
6131: complete. Therefore, the optimizer can check which operands have ended up
6132: in which kinds of registers, just by looking at the operands.
6133:
6134: The way to refer to the operands in @var{condition} is to write
6135: @code{operands[@var{i}]} for operand number @var{i} (as matched by
6136: @code{(match_operand @var{i} @dots{})}). Use the variable @code{insn} to
6137: refer to the last of the insns being matched; use @code{PREV_INSN} to find
6138: the preceding insns (but be careful to skip over any @samp{note} insns that
6139: intervene).@refill
6140:
6141: When optimizing computations with intermediate results, you can use
6142: @var{condition} to match only when the intermediate results are not used
6143: elsewhere. Use the C expression @code{dead_or_set_p (@var{insn},
6144: @var{op})}, where @var{insn} is the insn in which you expect the value to
6145: be used for the last time (from the value of @code{insn}, together with use
6146: of @code{PREV_INSN}), and @var{op} is the intermediate value (from
6147: @code{operands[@var{i}]}).@refill
6148:
6149: Applying the optimization means replacing the sequence of instructions with
6150: one new instruction. The @var{template} controls ultimate output of
6151: assembler code for this combined instruction. It works exactly like the
6152: template of a @code{define_insn}. Operand numbers in this template are the
6153: same ones used in matching the original sequence of instructions.
6154:
6155: The result of a defined peephole optimizer does not need to match any of
6156: the instruction patterns, and it does not have an opportunity to match
6157: them. The peephole optimizer definition itself serves as the instruction
6158: pattern to control how the instruction is output.
6159:
6160: Defined peephole optimizers are run in the last jump optimization pass, so
6161: the instructions they produce are never combined or rearranged
6162: automatically in any way.
6163:
6164: Here is an example, taken from the 68000 machine description:
6165:
6166: @example
6167: (define_peephole
6168: [(set (reg:SI 15) (plus:SI (reg:SI 15) (const_int 4)))
6169: (set (match_operand:DF 0 "register_operand" "f")
6170: (match_operand:DF 1 "register_operand" "ad"))]
6171: "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
6172: "*
6173: @{
6174: rtx xoperands[2];
6175: xoperands[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
6176: #ifdef MOTOROLA
6177: output_asm_insn (\"move.l %1,(sp)\", xoperands);
6178: output_asm_insn (\"move.l %1,-(sp)\", operands);
6179: return \"fmove.d (sp)+,%0\";
6180: #else
6181: output_asm_insn (\"movel %1,sp@@\", xoperands);
6182: output_asm_insn (\"movel %1,sp@@-\", operands);
6183: return \"fmoved sp@@+,%0\";
6184: #endif
6185: @}
6186: ")
6187: @end example
6188:
6189: The effect of this optimization is to change
6190:
6191: @example
6192: jbsr _foobar
6193: addql #4,sp
6194: movel d1,sp@@-
6195: movel d0,sp@@-
6196: fmoved sp@@+,fp0
6197: @end example
6198:
6199: @noindent
6200: into
6201:
6202: @example
6203: jbsr _foobar
6204: movel d1,sp@@
6205: movel d0,sp@@-
6206: fmoved sp@@+,fp0
6207: @end example
6208:
6209: @node Expander Definitions,, Peephole Definitions, Machine Desc
6210: @section Defining RTL Sequences for Code Generation
6211:
6212: On some target machines, some standard pattern names for RTL generation
6213: cannot be handled with single insn, but a sequence of RTL insns can
6214: represent them. For these target machines, you can write a
6215: @samp{define_expand} to specify how to generate the sequence of RTL.
6216:
6217: A @samp{define_expand} is an RTL expression that looks almost like a
6218: @samp{define_insn}; but, unlike the latter, a @samp{define_expand} is used
6219: only for RTL generation and it can produce more than one RTL insn.
6220:
6221: A @samp{define_expand} RTX has four operands:
6222:
6223: @itemize @bullet
6224: @item
6225: The name. Each @samp{define_expand} must have a name, since the only
6226: use for it is to refer to it by name.
6227:
6228: @item
6229: The RTL template. This is just like the RTL template for a
6230: @samp{define_peephole} in that it is a vector of RTL expressions
6231: each being one insn.
6232:
6233: @item
6234: The condition, a string containing a C expression. This expression is
6235: used to express how the availability of this pattern depends on
6236: subclasses of target machine, selected by command-line options when
6237: GNU CC is run. This is just like the condition of a
6238: @samp{define_insn} that has a standard name.
6239:
6240: @item
6241: The preparation statements, a string containing zero or more C
6242: statements which are to be executed before RTL code is generated from
6243: the RTL template.
6244:
6245: Usually these statements prepare temporary registers for use as
6246: internal operands in the RTL template, but they can also generate RTL
6247: insns directly by calling routines such as @samp{emit_insn}, etc.
6248: Any such insns precede the ones that come from the RTL template.
6249: @end itemize
6250:
6251: The RTL template, in addition to controlling generation of RTL insns,
6252: also describes the operands that need to be specified when this pattern
6253: is used. In particular, it gives a predicate for each operand.
6254:
6255: A true operand, which need to be specified in order to generate RTL from
6256: the pattern, should be described with a @samp{match_operand} in its first
6257: occurrence in the RTL template. This enters information on the operand's
6258: predicate into the tables that record such things. GNU CC uses the
6259: information to preload the operand into a register if that is required for
6260: valid RTL code. If the operand is referred to more than once, subsequent
6261: references should use @samp{match_dup}.
6262:
6263: The RTL template may also refer to internal ``operands'' which are
6264: temporary registers or labels used only within the sequence made by the
6265: @samp{define_expand}. Internal operands are substituted into the RTL
6266: template with @samp{match_dup}, never with @samp{match_operand}. The
6267: values of the internal operands are not passed in as arguments by the
6268: compiler when it requests use of this pattern. Instead, they are computed
6269: within the pattern, in the preparation statements. These statements
6270: compute the values and store them into the appropriate elements of
6271: @code{operands} so that @samp{match_dup} can find them.
6272:
6273: There are two special macros defined for use in the preparation statements:
6274: @code{DONE} and @code{FAIL}. Use them with a following semicolon,
6275: as a statement.
6276:
6277: @table @code
6278: @item DONE
6279: Use the @code{DONE} macro to end RTL generation for the pattern. The
6280: only RTL insns resulting from the pattern on this occasion will be
6281: those already emitted by explicit calls to @code{emit_insn} within the
6282: preparation statements; the RTL template will not be generated.
6283:
6284: @item FAIL
6285: Make the pattern fail on this occasion. When a pattern fails, it means
6286: that the pattern was not truly available. The calling routines in the
6287: compiler will try other strategies for code generation using other patterns.
6288:
6289: Failure is currently supported only for binary operations (addition,
6290: multiplication, shifting, etc.).
6291:
6292: Do not emit any insns explicitly with @code{emit_insn} before failing.
6293: @end table
6294:
6295: Here is an example, the definition of left-shift for the SPUR chip:
6296:
6297: @example
6298: (define_expand "ashlsi3"
6299: [(set (match_operand:SI 0 "register_operand" "")
6300: (ashift:SI
6301: (match_operand:SI 1 "register_operand" "")
6302: (match_operand:SI 2 "nonmemory_operand" "")))]
6303: ""
6304: "
6305: @{
6306: if (GET_CODE (operands[2]) != CONST_INT
6307: || (unsigned) INTVAL (operands[2]) > 3)
6308: FAIL;
6309: @}")
6310: @end example
6311:
6312: @noindent
6313: This example uses @samp{define_expand} so that it can generate an RTL insn
6314: for shifting when the shift-count is in the supported range of 0 to 3 but
6315: fail in other cases where machine insns aren't available. When it fails,
6316: the compiler tries another strategy using different patterns (such as, a
6317: library call).
6318:
6319: If the compiler were able to handle nontrivial condition-strings in
6320: patterns with names, then there would be possible to use a
6321: @samp{define_insn} in that case. Here is another case (zero-extension on
6322: the 68000) which makes more use of the power of @samp{define_expand}:
6323:
6324: @example
6325: (define_expand "zero_extendhisi2"
6326: [(set (match_operand:SI 0 "general_operand" "")
6327: (const_int 0))
6328: (set (strict_low_part
6329: (subreg:HI
6330: (match_operand:SI 0 "general_operand" "")
6331: 0))
6332: (match_operand:HI 1 "general_operand" ""))]
6333: ""
6334: "operands[1] = make_safe_from (operands[1], operands[0]);")
6335: @end example
6336:
6337: @noindent
6338: Here two RTL insns are generated, one to clear the entire output operand
6339: and the other to copy the input operand into its low half. This sequence
6340: is incorrect if the input operand refers to [the old value of] the output
6341: operand, so the preparation statement makes sure this isn't so. The
6342: function @code{make_safe_from} copies the @code{operands[1]} into a
6343: temporary register if it refers to @code{operands[0]}. It does this
6344: by emitting another RTL insn.
6345:
6346: Finally, a third example shows the use of an internal operand.
6347: Zero-extension on the SPUR chip is done by @samp{and}-ing the result
6348: against a halfword mask. But this mask cannot be represented by a
6349: @samp{const_int} because the constant value is too large to be legitimate
6350: on this machine. So it must be copied into a register with
6351: @code{force_reg} and then the register used in the @samp{and}.
6352:
6353: @example
6354: (define_expand "zero_extendhisi2"
6355: [(set (match_operand:SI 0 "register_operand" "")
6356: (and:SI (subreg:SI
6357: (match_operand:HI 1 "register_operand" "")
6358: 0)
6359: (match_dup 2)))]
6360: ""
6361: "operands[2]
6362: = force_reg (SImode, gen_rtx (CONST_INT,
6363: VOIDmode, 65535)); ")
6364: @end example
6365:
6366: @node Machine Macros, Config, Machine Desc, Top
6367: @chapter Machine Description Macros
6368:
6369: The other half of the machine description is a C header file conventionally
6370: given the name @file{tm-@var{machine}.h}. The file @file{tm.h} should be a
6371: link to it. The header file @file{config.h} includes @file{tm.h} and most
6372: compiler source files include @file{config.h}.
6373:
6374: @menu
6375: * Run-time Target:: Defining -m options like -m68000 and -m68020.
6376: * Storage Layout:: Defining sizes and alignments of data types.
6377: * Registers:: Naming and describing the hardware registers.
6378: * Register Classes:: Defining the classes of hardware registers.
6379: * Stack Layout:: Defining which way the stack grows and by how much.
6380: * Library Names:: Specifying names of subroutines to call automatically.
6381: * Addressing Modes:: Defining addressing modes valid for memory operands.
6382: * Condition Code:: Defining how insns update the condition code.
6383: * Assembler Format:: Defining how to write insns and pseudo-ops to output.
6384: * Misc:: Everything else.
6385: @end menu
6386:
6387: @node Run-time Target, Storage Layout, Machine Macros, Machine Macros
6388: @section Run-time Target Specification
6389:
6390: @table @code
6391: @item CPP_PREDEFINES
6392: Define this to be a string constant containing @samp{-D} options to
6393: define the predefined macros that identify this machine and system.
6394: These macros will be predefined unless the @samp{-ansi} option is
6395: specified.
6396:
1.1.1.4 ! root 6397: In addition, a parallel set of macros are predefined, whose names are
! 6398: made by appending @samp{__} at the beginning and at the end. These
! 6399: @samp{__} macros are permitted by the ANSI standard, so they are
! 6400: predefined regardless of whether @samp{-ansi} is specified.
! 6401:
! 6402: For example, on the Sun, one can use the following value:
1.1 root 6403:
6404: @example
6405: "-Dmc68000 -Dsun -Dunix"
6406: @end example
6407:
1.1.1.4 ! root 6408: The result is to define the macros @samp{__Dmc68000__}, @samp{__sun__}
! 6409: and @samp{__unix__} unconditionally, and the macros @samp{mc68000},
! 6410: @samp{sun} and @samp{unix} provided @samp{-ansi} is not specified.
! 6411:
1.1 root 6412: @item CPP_SPEC
6413: A C string constant that tells the GNU CC driver program options to
6414: pass to CPP. It can also specify how to translate options you
6415: give to GNU CC into options for GNU CC to pass to the CPP.
6416:
6417: Do not define this macro if it does not need to do anything.
6418:
6419: @item CC1_SPEC
6420: A C string constant that tells the GNU CC driver program options to
6421: pass to CC1. It can also specify how to translate options you
6422: give to GNU CC into options for GNU CC to pass to the CC1.
6423:
6424: Do not define this macro if it does not need to do anything.
6425:
6426: @item extern int target_flags;
6427: This declaration should be present.
6428:
6429: @item TARGET_@dots{}
6430: This series of macros is to allow compiler command arguments to
6431: enable or disable the use of optional features of the target machine.
6432: For example, one machine description serves both the 68000 and
6433: the 68020; a command argument tells the compiler whether it should
6434: use 68020-only instructions or not. This command argument works
6435: by means of a macro @code{TARGET_68020} that tests a bit in
6436: @code{target_flags}.
6437:
6438: Define a macro @code{TARGET_@var{featurename}} for each such option.
6439: Its definition should test a bit in @code{target_flags}; for example:
6440:
6441: @example
6442: #define TARGET_68020 (target_flags & 1)
6443: @end example
6444:
6445: One place where these macros are used is in the condition-expressions
6446: of instruction patterns. Note how @code{TARGET_68020} appears
6447: frequently in the 68000 machine description file, @file{m68k.md}.
6448: Another place they are used is in the definitions of the other
6449: macros in the @file{tm-@var{machine}.h} file.
6450:
6451: @item TARGET_SWITCHES
6452: This macro defines names of command options to set and clear
6453: bits in @code{target_flags}. Its definition is an initializer
6454: with a subgrouping for each command option.
6455:
6456: Each subgrouping contains a string constant, that defines the option
6457: name, and a number, which contains the bits to set in
6458: @code{target_flags}. A negative number says to clear bits instead;
6459: the negative of the number is which bits to clear. The actual option
6460: name is made by appending @samp{-m} to the specified name.
6461:
6462: One of the subgroupings should have a null string. The number in
6463: this grouping is the default value for @code{target_flags}. Any
6464: target options act starting with that value.
6465:
6466: Here is an example which defines @samp{-m68000} and @samp{-m68020}
6467: with opposite meanings, and picks the latter as the default:
6468:
6469: @example
6470: #define TARGET_SWITCHES \
6471: @{ @{ "68020", 1@}, \
6472: @{ "68000", -1@}, \
6473: @{ "", 1@}@}
6474: @end example
6475:
6476: @item OVERRIDE_OPTIONS
6477: Sometimes certain combinations of command options do not make sense on
6478: a particular target machine. You can define a macro
6479: @code{OVERRIDE_OPTIONS} to take account of this. This macro, if
6480: defined, is executed once just after all the command options have been
6481: parsed.
6482: @end table
6483:
6484: @node Storage Layout, Registers, Run-time Target, Machine Macros
6485: @section Storage Layout
6486:
6487: Note that the definitions of the macros in this table which are sizes or
6488: alignments measured in bits do not need to be constant. They can be C
6489: expressions that refer to static variables, such as the @code{target_flags}.
6490: @xref{Run-time Target}.
6491:
6492: @table @code
6493: @item BITS_BIG_ENDIAN
6494: Define this macro if the most significant bit in a byte has the lowest
6495: number. This means that bit-field instructions count from the most
6496: significant bit. If the machine has no bit-field instructions, this
6497: macro is irrelevant.
6498:
6499: @item BYTES_BIG_ENDIAN
6500: Define this macro if the most significant byte in a word has the
6501: lowest number.
6502:
6503: @item WORDS_BIG_ENDIAN
6504: Define this macro if, in a multiword object, the most significant
6505: word has the lowest number.
6506:
6507: @item BITS_PER_UNIT
6508: Number of bits in an addressable storage unit (byte); normally 8.
6509:
6510: @item BITS_PER_WORD
6511: Number of bits in a word; normally 32.
6512:
6513: @item UNITS_PER_WORD
6514: Number of storage units in a word; normally 4.
6515:
6516: @item POINTER_SIZE
6517: Width of a pointer, in bits.
6518:
6519: @item POINTER_BOUNDARY
6520: Alignment required for pointers stored in memory, in bits.
6521:
6522: @item PARM_BOUNDARY
6523: Alignment required for function parameters on the stack, in bits.
6524:
6525: @item STACK_BOUNDARY
6526: Define this macro if you wish to preserve a certain alignment for
6527: the stack pointer at all times. The definition is a C expression
6528: for the desired alignment (measured in bits).
6529:
6530: @item FUNCTION_BOUNDARY
6531: Alignment required for a function entry point, in bits.
6532:
6533: @item BIGGEST_ALIGNMENT
6534: Biggest alignment that any data type can require on this machine, in bits.
6535:
6536: @item EMPTY_FIELD_BOUNDARY
6537: Alignment in bits to be given to a structure bit field that follows an
6538: empty field such as @code{int : 0;}.
6539:
6540: @item STRUCTURE_SIZE_BOUNDARY
6541: Number of bits which any structure or union's size must be a multiple of.
6542: Each structure or union's size is rounded up to a multiple of this.
6543:
6544: If you do not define this macro, the default is the same as
6545: @code{BITS_PER_UNIT}.
6546:
6547: @item STRICT_ALIGNMENT
6548: Define this if instructions will fail to work if given data not
6549: on the nominal alignment. If instructions will merely go slower
6550: in that case, do not define this macro.
6551:
6552: @item PCC_BITFIELD_TYPE_MATTERS
6553: Define this if you wish to imitate a certain bizarre behavior pattern
6554: of some instances of PCC: a bit field whose declared type is
6555: @code{int} has the same effect on the size and alignment of a
6556: structure as an actual @code{int} would have.
6557:
6558: Just what effect that is in GNU CC depends on other parameters, but on
6559: most machines it would force the structure's alignment and size to a
6560: multiple of 32 or @code{BIGGEST_ALIGNMENT} bits.
6561:
6562: @item CHECK_FLOAT_VALUE (@var{mode}, @var{value})
6563: A C statement to validate the value @var{value} (or type
6564: @code{double}) for mode @var{mode}. This means that you check whether
6565: @var{value} fits within the possible range of values for mode
6566: @var{mode} on this target machine. The mode @var{mode} is always
6567: @code{SFmode} or @code{DFmode}.
6568:
6569: If @var{value} is not valid, you should call @code{error} to print an
6570: error message and then assign some valid value to @var{value}.
6571: Allowing an invalid value to go through the compiler can produce
6572: incorrect assembler code which may even cause Unix assemblers to
6573: crash.
6574:
6575: This macro need not be defined if there is no work for it to do.
6576: @end table
6577:
6578: @node Registers, Register Classes, Storage Layout, Machine Macros
6579: @section Register Usage
6580:
6581: @table @code
6582: @item FIRST_PSEUDO_REGISTER
6583: Number of hardware registers known to the compiler. They receive
6584: numbers 0 through @code{FIRST_PSEUDO_REGISTER-1}; thus, the first
6585: pseudo register's number really is assigned the number
6586: @code{FIRST_PSEUDO_REGISTER}.
6587:
6588: @item FIXED_REGISTERS
6589: An initializer that says which registers are used for fixed purposes
6590: all throughout the compiled code and are therefore not available for
6591: general allocation. These would include the stack pointer, the frame
6592: pointer (except on machines where that can be used as a general
6593: register when no frame pointer is needed), the program counter on
6594: machines where that is considered one of the addressable registers,
6595: and any other numbered register with a standard use.
6596:
6597: This information is expressed as a sequence of numbers, separated by
6598: commas and surrounded by braces. The @var{n}th number is 1 if
6599: register @var{n} is fixed, 0 otherwise.
6600:
6601: The table initialized from this macro, and the table initialized by
6602: the following one, may be overridden at run time either automatically,
6603: by the actions of the macro @code{CONDITIONAL_REGISTER_USAGE}, or by
6604: the user with the command options @samp{-ffixed-@var{reg}},
6605: @samp{-fcall-used-@var{reg}} and @samp{-fcall-saved-@var{reg}}.
6606:
6607: @item CALL_USED_REGISTERS
6608: Like @code{FIXED_REGISTERS} but has 1 for each register that is
6609: clobbered (in general) by function calls as well as for fixed
6610: registers. This macro therefore identifies the registers that are not
6611: available for general allocation of values that must live across
6612: function calls.
6613:
6614: If a register has 0 in @code{CALL_USED_REGISTERS}, the compiler
6615: automatically saves it on function entry and restores it on function
6616: exit, if the register is used within the function.
6617:
6618: @item CONDITIONAL_REGISTER_USAGE
6619: Zero or more C statements that may conditionally modify two variables
6620: @code{fixed_regs} and @code{call_used_regs} (both of type @code{char
6621: []}) after they have been initialized from the two preceding macros.
6622:
6623: This is necessary in case the fixed or call-clobbered registers depend
6624: on target flags.
6625:
6626: You need not define this macro if it has no work to do.
6627:
6628: If the usage of an entire class of registers depends on the target
6629: flags, you may indicate this to gcc by using this macro to modify
6630: @code{fixed_regs} and @code{call_used_regs} to 1 for each of the
6631: registers in the classes which should not be used by gcc. Also define
6632: the macro @code{REG_CLASS_FROM_LETTER} to return @code{NO_REGS} if it
6633: is called with a letter for a class that shouldn't be used.
6634:
6635: (However, if this class is not included in @code{GENERAL_REGS} and all
6636: of the insn patterns whose constraints permit this class are
6637: controlled by target switches, then GCC will automatically avoid using
6638: these registers when the target switches are opposed to them.)
6639:
6640: @item OVERLAPPING_REGNO_P (@var{regno})
6641: If defined, this is a C expression whose value is @var{regno} is
6642: nonzero if hard register number @var{regno} is an overlapping
6643: register. This means a hard register which overlaps a hard register
6644: with a different number. (Such overlap is undesirable, but
6645: occasionally it allows a machine to be supported which otherwise could
6646: not be.) This macro must return nonzero for @emph{all} the registers
6647: which overlap each other. GNU CC can use an overlapping register only
6648: in certain limited ways. It can be used for allocation within a basic
6649: block, and may be spilled for reloading; that is all.
6650:
6651: If this macro is not defined, it means that none of the hard registers
6652: overlap each other. This is the usual situation.
6653:
6654: @item INSN_CLOBBERS_REGNO_P (@var{insn}, @var{regno})
6655: If defined, this is a C expression whose value should be nonzero if
6656: the insn @var{insn} has the effect of mysteriously clobbering the
6657: contents of hard register number @var{regno}. By ``mysterious'' we
6658: mean that the insn's RTL expression doesn't describe such an effect.
6659:
6660: If this macro is not defined, it means that no insn clobbers registers
6661: mysteriously. This is the usual situation; all else being equal,
6662: it is best for the RTL expression to show all the activity.
6663:
6664: @item PRESERVE_DEATH_INFO_REGNO_P (@var{regno})
6665: If defined, this is a C expression whose value is nonzero if accurate
6666: @code{REG_DEAD} notes are needed for hard register number @var{regno}
6667: at the time of outputting the assembler code. When this is so, a few
6668: optimizations that take place after register allocation and could
6669: invalidate the death notes are not done when this register is
6670: involved.
6671:
6672: You would arrange to preserve death info for a register when some
6673: of the code in the machine description which is executed to write
6674: the assembler code looks at the the death notes. This is
6675: necessary only when the actual hardware feature which GNU CC
6676: thinks of as a register is not actually a register of the usual sort.
6677: (It might, for example, be a hardware stack.)
6678:
6679: If this macro is not defined, it means that no death notes need to be
6680: preserved. This is the usual situation.
6681:
6682: @item HARD_REGNO_REGS (@var{regno}, @var{mode})
6683: A C expression for the number of consecutive hard registers, starting
6684: at register number @var{regno}, required to hold a value of mode
6685: @var{mode}.
6686:
6687: On a machine where all registers are exactly one word, a suitable
6688: definition of this macro is
6689:
6690: @example
6691: #define HARD_REGNO_NREGS(REGNO, MODE) \
6692: ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
6693: / UNITS_PER_WORD))
6694: @end example
6695:
6696: @item HARD_REGNO_MODE_OK (@var{regno}, @var{mode})
6697: A C expression that is nonzero if it is permissible to store a value
6698: of mode @var{mode} in hard register number @var{regno} (or in several
6699: registers starting with that one). For a machine where all registers
6700: are equivalent, a suitable definition is
6701:
6702: @example
6703: #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
6704: @end example
6705:
6706: It is not necessary for this macro to check for fixed register numbers
6707: because the allocation mechanism considers them to be always occupied.
6708:
6709: Many machines have special registers for floating point arithmetic.
6710: Often people assume that floating point machine modes are allowed only
6711: in floating point registers. This is not true. Any registers that
6712: can hold integers can safely @emph{hold} a floating point machine
6713: mode, whether or not floating arithmetic can be done on it in those
6714: registers.
6715:
6716: The true significance of special floating registers is rather than
6717: non-floating-point machine modes @emph{may not} go in those registers.
6718: This is true if the floating registers normalize any value stored in
6719: them, because storing a non-floating value there would garble it. If
6720: the floating registers do not automatically normalize, if you can
6721: store any bit pattern in one and retrieve it unchanged without a trap,
6722: then any machine mode may go in a floating register and this macro
6723: should say so.
6724:
6725: Sometimes there are floating registers that are especially slow to
6726: access, so that it is better to store a value in a stack frame than in
6727: such a register if floating point arithmetic is not being done. As long
6728: as the floating registers are not in class @code{GENERAL_REGS}, they
6729: will not be used unless some insn's constraint asks for one.
6730:
6731: It is obligatory to support floating point `move' instructions into
6732: and out of any registers that can hold fixed point values, because
6733: unions and structures (which have modes @samp{SImode} or
6734: @samp{DImode}) can be in those registers and they may have floating
6735: point members.
6736:
6737: There may also be a need to support fixed point `move' instructions in
6738: and out of floating point registers. Unfortunately, I have forgotten
6739: why this was so, and I don't know whether it is still true. If
6740: @code{HARD_REGNO_MODE_OK} rejects fixed point values in floating point
6741: registers, then the constraints of the fixed point `move' instructions
6742: must be designed to avoid ever trying to reload into a floating point
6743: register.
6744:
6745: @item MODES_TIEABLE_P (@var{mode1}, @var{mode2})
6746: A C expression that is nonzero if it is desirable to choose register
6747: allocation so as to avoid move instructions between a value of mode
6748: @var{mode1} and a value of mode @var{mode2}.
6749:
6750: If @code{HARD_REGNO_MODE_OK (@var{r}, @var{mode1})} and
6751: @code{HARD_REGNO_MODE_OK (@var{r}, @var{mode2})} are ever different
6752: for any @var{r}, then @code{MODES_TIEABLE_P (@var{mode1},
6753: @var{mode2})} must be zero.
6754:
6755: @item PC_REGNUM
6756: If the program counter has a register number, define this as that
6757: register number. Otherwise, do not define it.
6758:
6759: @item STACK_POINTER_REGNUM
6760: The register number of the stack pointer register, which must also be
6761: a fixed register according to @code{FIXED_REGISTERS}. On many
6762: machines, the hardware determines which register this is.
6763:
6764: @item FRAME_POINTER_REGNUM
6765: The register number of the frame pointer register, which is used to
6766: access automatic variables in the stack frame. On some machines, the
6767: hardware determines which register this is. On other machines, you
6768: can choose any register you wish for this purpose.
6769:
6770: @item FRAME_POINTER_REQUIRED
6771: A C expression which is nonzero if a function must have and use a
6772: frame pointer. This expression is evaluated in the reload pass, in
6773: the function @code{reload}, and it can in principle examine the
6774: current function and decide according to the facts, but on most
6775: machines the constant 0 or the constant 1 suffices. Use 0 when the
6776: machine allows code to be generated with no frame pointer, and doing
6777: so saves some time or space. Use 1 when there is no possible
6778: advantage to avoiding a frame pointer.
6779:
6780: In certain cases, the compiler does not know how to do without a frame
6781: pointer. The compiler recognizes those cases and automatically gives
6782: the function a frame pointer regardless of what
6783: @code{FRAME_POINTER_REQUIRED} says. You don't need to worry about
6784: them.@refill
6785:
6786: In a function that does not require a frame pointer, the frame pointer
6787: register can be allocated for ordinary usage, unless you mark it as a
6788: fixed register. See @code{FIXED_REGISTERS} for more information.
6789:
6790: @item ARG_POINTER_REGNUM
6791: The register number of the arg pointer register, which is used to
6792: access the function's argument list. On some machines, this is the
6793: same as the frame pointer register. On some machines, the hardware
6794: determines which register this is. On other machines, you can choose
6795: any register you wish for this purpose. If this is not the same
6796: register as the frame pointer register, then you must mark it as a
6797: fixed register according to @code{FIXED_REGISTERS}.
6798:
6799: @item STATIC_CHAIN_REGNUM
6800: The register number used for passing a function's static chain
6801: pointer. This is needed for languages such as Pascal and Algol where
6802: functions defined within other functions can access the local
6803: variables of the outer functions; it is not currently used because C
6804: does not provide this feature, but you must define the macro.
6805:
6806: The static chain register need not be a fixed register.
6807:
6808: @item STRUCT_VALUE_REGNUM
6809: When a function's value's mode is @code{BLKmode}, the value is not
6810: returned according to @code{FUNCTION_VALUE}. Instead, the caller
6811: passes the address of a block of memory in which the value should be
6812: stored.
6813:
6814: If this value is passed in a register, then @code{STRUCT_VALUE_REGNUM}
6815: should be the number of that register.
6816:
6817: @item STRUCT_VALUE
6818: If the structure value address is not passed in a register, define
6819: @code{STRUCT_VALUE} as an expression returning an RTX for the place
6820: where the address is passed. If it returns a @samp{mem} RTX, the
6821: address is passed as an ``invisible'' first argument.
6822:
6823: @item STRUCT_VALUE_INCOMING_REGNUM
6824: On some architectures the place where the structure value address
6825: is found by the called function is not the same place that the
6826: caller put it. This can be due to register windows, or it could
6827: be because the function prologue moves it to a different place.
6828:
6829: If the incoming location of the structure value address is in a
6830: register, define this macro as the register number.
6831:
6832: @item STRUCT_VALUE_INCOMING
6833: If the incoming location is not a register, define
6834: @code{STRUCT_VALUE_INCOMING} as an expression for an RTX for where the
6835: called function should find the value. If it should find the value on
6836: the stack, define this to create a @samp{mem} which refers to the
6837: frame pointer. If the value is a @samp{mem}, the compiler assumes it
6838: is for an invisible first argument, and leaves space for it when
6839: finding the first real argument.
6840:
6841: @item REG_ALLOC_ORDER
6842: If defined, an initializer for a vector of integers, containing the
6843: numbers of hard registers in the order in which the GNU CC should
6844: prefer to use them (from most preferred to least).
6845:
6846: If this macro is not defined, registers are used lowest numbered first
6847: (all else being equal).
6848:
6849: One use of this macro is on the 360, where the highest numbered
6850: registers must always be saved and the save-multiple-registers
6851: instruction supports only sequences of consecutive registers. This
6852: macro is defined to cause the highest numbered allocatable registers
6853: to be used first.
6854: @end table
6855:
6856: @node Register Classes, Stack Layout, Registers, Machine Macros
6857: @section Register Classes
6858:
6859: On many machines, the numbered registers are not all equivalent.
6860: For example, certain registers may not be allowed for indexed addressing;
6861: certain registers may not be allowed in some instructions. These machine
6862: restrictions are described to the compiler using @dfn{register classes}.
6863:
6864: You define a number of register classes, giving each one a name and saying
6865: which of the registers belong to it. Then you can specify register classes
6866: that are allowed as operands to particular instruction patterns.
6867:
6868: In general, each register will belong to several classes. In fact, one
6869: class must be named @code{ALL_REGS} and contain all the registers. Another
6870: class must be named @code{NO_REGS} and contain no registers. Often the
6871: union of two classes will be another class; however, this is not required.
6872:
6873: One of the classes must be named @code{GENERAL_REGS}. There is nothing
6874: terribly special about the name, but the operand constraint letters
6875: @samp{r} and @samp{g} specify this class. If @code{GENERAL_REGS} is
6876: the same as @code{ALL_REGS}, just define it as a macro which expands
6877: to @code{ALL_REGS}.
6878:
6879: The way classes other than @code{GENERAL_REGS} are specified in operand
6880: constraints is through machine-dependent operand constraint letters.
6881: You can define such letters to correspond to various classes, then use
6882: them in operand constraints.
6883:
6884: You should define a class for the union of two classes whenever some
6885: instruction allows both classes. For example, if an instruction allows
6886: either a floating-point (coprocessor) register or a general register for a
6887: certain operand, you should define a class @code{FLOAT_OR_GENERAL_REGS}
6888: which includes both of them. Otherwise you will get suboptimal code.
6889:
6890: You must also specify certain redundant information about the register
6891: classes: for each class, which classes contain it and which ones are
6892: contained in it; for each pair of classes, the largest class contained
6893: in their union.
6894:
6895: Register classes used for input-operands of bitwise-and or shift
6896: instructions have a special requirement: each such class must have, for
6897: each fixed-point machine mode, a subclass whose registers can transfer that
6898: mode to or from memory. For example, on some machines, the operations for
6899: single-byte values (@code{QImode}) are limited to certain registers. When
6900: this is so, each register class that is used in a bitwise-and or shift
6901: instruction must have a subclass consisting of registers from which
6902: single-byte values can be loaded or stored. This is so that
6903: @code{PREFERRED_RELOAD_CLASS} can always have a possible value to return.
6904:
6905: @table @code
6906: @item enum reg_class
6907: An enumeral type that must be defined with all the register class names
6908: as enumeral values. @code{NO_REGS} must be first. @code{ALL_REGS}
6909: must be the last register class, followed by one more enumeral value,
6910: @code{LIM_REG_CLASSES}, which is not a register class but rather
6911: tells how many classes there are.
6912:
6913: Each register class has a number, which is the value of casting
6914: the class name to type @code{int}. The number serves as an index
6915: in many of the tables described below.
6916:
6917: @item N_REG_CLASSES
6918: The number of distinct register classes, defined as follows:
6919:
6920: @example
6921: #define N_REG_CLASSES (int) LIM_REG_CLASSES
6922: @end example
6923:
6924: @item REG_CLASS_NAMES
6925: An initializer containing the names of the register classes as C string
6926: constants. These names are used in writing some of the debugging dumps.
6927:
6928: @item REG_CLASS_CONTENTS
6929: An initializer containing the contents of the register classes, as integers
6930: which are bit masks. The @var{n}th integer specifies the contents of class
6931: @var{n}. The way the integer @var{mask} is interpreted is that
6932: register @var{r} is in the class if @code{@var{mask} & (1 << @var{r})} is 1.
6933:
6934: When the machine has more than 32 registers, an integer does not suffice.
6935: Then the integers are replaced by sub-initializers, braced groupings containing
6936: several integers. Each sub-initializer must be suitable as an initializer
6937: for the type @code{HARD_REG_SET} which is defined in @file{hard-reg-set.h}.
6938:
6939: @item REGNO_REG_CLASS (@var{regno})
6940: A C expression whose value is a register class containing hard register
6941: @var{regno}. In general there is more that one such class; choose a class
6942: which is @dfn{minimal}, meaning that no smaller class also contains the
6943: register.
6944:
6945: @item BASE_REG_CLASS
6946: A macro whose definition is the name of the class to which a valid
6947: base register must belong. A base register is one used in an address
6948: which is the register value plus a displacement.
6949:
6950: @item INDEX_REG_CLASS
6951: A macro whose definition is the name of the class to which a valid
6952: index register must belong. An index register is one used in an
6953: address where its value is either multiplied by a scale factor or
6954: added to another register (as well as added to a displacement).
6955:
6956: @item REG_CLASS_FROM_LETTER (@var{char})
6957: A C expression which defines the machine-dependent operand constraint
6958: letters for register classes. If @var{char} is such a letter, the
6959: value should be the register class corresponding to it. Otherwise,
6960: the value should be @code{NO_REGS}.
6961:
6962: @item REGNO_OK_FOR_BASE_P (@var{num})
6963: A C expression which is nonzero if register number @var{num} is
6964: suitable for use as a base register in operand addresses. It may be
6965: either a suitable hard register or a pseudo register that has been
6966: allocated such a hard register.
6967:
6968: @item REGNO_OK_FOR_INDEX_P (@var{num})
6969: A C expression which is nonzero if register number @var{num} is
6970: suitable for use as an index register in operand addresses. It may be
6971: either a suitable hard register or a pseudo register that has been
6972: allocated such a hard register.
6973:
6974: The difference between an index register and a base register is that
6975: the index register may be scaled. If an address involves the sum of
6976: two registers, neither one of them scaled, then either one may be
6977: labeled the ``base'' and the other the ``index''; but whichever
6978: labeling is used must fit the machine's constraints of which registers
6979: may serve in each capacity. The compiler will try both labelings,
6980: looking for one that is valid, and will reload one or both registers
6981: only if neither labeling works.
6982:
6983: @item PREFERRED_RELOAD_CLASS (@var{x}, @var{class})
6984: A C expression that places additional restrictions on the register class
6985: to use when it is necessary to copy value @var{x} into a register in class
6986: @var{class}. The value is a register class; perhaps @var{class}, or perhaps
6987: another, smaller class. On many machines, the definition
6988:
6989: @example
6990: #define PREFERRED_RELOAD_CLASS(X,CLASS) CLASS
6991: @end example
6992:
6993: @noindent
6994: is safe.
6995:
6996: Sometimes returning a more restrictive class makes better code. For
6997: example, on the 68000, when @var{x} is an integer constant that is in range
6998: for a @samp{moveq} instruction, the value of this macro is always
6999: @code{DATA_REGS} as long as @var{class} includes the data registers.
7000: Requiring a data register guarantees that a @samp{moveq} will be used.
7001:
7002: If @var{x} is a @samp{const_double}, by returning @code{NO_REGS}
7003: you can force @var{x} into a memory constant. This is useful on
7004: certain machines where immediate floating values cannot be loaded into
7005: certain kinds of registers.
7006:
7007: In a shift instruction or a bitwise-and instruction, the mode of @var{x},
7008: the value being reloaded, may not be the same as the mode of the
7009: instruction's operand. (They will both be fixed-point modes, however.) In
7010: such a case, @var{class} may not be a safe value to return. @var{class} is
7011: certainly valid for the instruction, but it may not be valid for reloading
7012: @var{x}. This problem can occur on machines such as the 68000 and 80386
7013: where some registers can handle full-word values but cannot handle
7014: single-byte values.
7015:
7016: On such machines, this macro must examine the mode of @var{x} and return a
7017: subclass of @var{class} which can handle loads and stores of that mode. On
7018: the 68000, where address registers cannot handle @code{QImode}, if @var{x}
7019: has @code{QImode} then you must return @code{DATA_REGS}. If @var{class} is
7020: @code{ADDR_REGS}, then there is no correct value to return; but the shift
7021: and bitwise-and instructions don't use @code{ADDR_REGS}, so this fatal case
7022: never arises.
7023:
7024: @item CLASS_MAX_NREGS (@var{class}, @var{mode})
7025: A C expression for the maximum number of consecutive registers
7026: of class @var{class} needed to hold a value of mode @var{mode}.
7027:
7028: This is closely related to the macro @code{HARD_REGNO_NREGS}.
7029: In fact, the value of the macro @code{CLASS_MAX_NREGS (@var{class}, @var{mode})}
7030: should be the maximum value of @code{HARD_REGNO_NREGS (@var{regno}, @var{mode})}
7031: for all @var{regno} values in the class @var{class}.
7032:
7033: This macro helps control the handling of multiple-word values
7034: in the reload pass.
7035: @end table
7036:
7037: Two other special macros describe which constants fit which constraint
7038: letters.
7039:
7040: @table @code
7041: @item CONST_OK_FOR_LETTER_P (@var{value}, @var{c})
7042: A C expression that defines the machine-dependent operand constraint letters
7043: that specify particular ranges of integer values. If @var{c} is one
7044: of those letters, the expression should check that @var{value}, an integer,
7045: is in the appropriate range and return 1 if so, 0 otherwise. If @var{c} is
7046: not one of those letters, the value should be 0 regardless of @var{value}.
7047:
7048: @item CONST_DOUBLE_OK_FOR_LETTER_P (@var{value}, @var{c})
7049: A C expression that defines the machine-dependent operand constraint
7050: letters that specify particular ranges of floating values. If @var{c} is
7051: one of those letters, the expression should check that @var{value}, an RTX
7052: of code @samp{const_double}, is in the appropriate range and return 1 if
7053: so, 0 otherwise. If @var{c} is not one of those letters, the value should
7054: be 0 regardless of @var{value}.
7055: @end table
7056:
7057: @node Stack Layout, Library Names, Register Classes, Machine Macros
7058: @section Describing Stack Layout
7059:
7060: @table @code
7061: @item STACK_GROWS_DOWNWARD
7062: Define this macro if pushing a word onto the stack moves the stack
7063: pointer to a smaller address.
7064:
7065: When we say, ``define this macro if @dots{},'' it means that the
7066: compiler checks this macro only with @code{#ifdef} so the precise
7067: definition used does not matter.
7068:
7069: @item FRAME_GROWS_DOWNWARD
7070: Define this macro if the addresses of local variable slots are at negative
7071: offsets from the frame pointer.
7072:
7073: @item STARTING_FRAME_OFFSET
7074: Offset from the frame pointer to the first local variable slot to be allocated.
7075:
7076: If @code{FRAME_GROWS_DOWNWARD}, the next slot's offset is found by
7077: subtracting the length of the first slot from @code{STARTING_FRAME_OFFSET}.
7078: Otherwise, it is found by adding the length of the first slot to
7079: the value @code{STARTING_FRAME_OFFSET}.
7080:
7081: @item PUSH_ROUNDING (@var{npushed})
7082: A C expression that is the number of bytes actually pushed onto the
7083: stack when an instruction attempts to push @var{npushed} bytes.
7084:
7085: If the target machine does not have a push instruction, do not define
7086: this macro. That directs GNU CC to use an alternate strategy: to
7087: allocate the entire argument block and then store the arguments into
7088: it.
7089:
7090: On some machines, the definition
7091:
7092: @example
7093: #define PUSH_ROUNDING(BYTES) (BYTES)
7094: @end example
7095:
7096: @noindent
7097: will suffice. But on other machines, instructions that appear
7098: to push one byte actually push two bytes in an attempt to maintain
7099: alignment. Then the definition should be
7100:
7101: @example
7102: #define PUSH_ROUNDING(BYTES) (((BYTES) + 1) & ~1)
7103: @end example
7104:
7105: @item FIRST_PARM_OFFSET (@var{fundecl})
7106: Offset from the argument pointer register to the first argument's
7107: address. On some machines it may depend on the data type of the
7108: function. (In the next version of GNU CC, the argument will be
7109: changed to the function data type rather than its declaration.)
7110:
7111: @item FIRST_PARM_CALLER_OFFSET (@var{fundecl})
7112: Define this macro on machines where register parameters have shadow
7113: locations on the stack, at addresses below the nominal parameter.
7114: This matters because certain arguments cannot be passed on the stack.
7115: On these machines, such arguments must be stored into the shadow
7116: locations.
7117:
7118: This macro should expand into a C expression whose value is the offset
7119: of the first parameter's shadow location from the nominal stack
7120: pointer value. (That value is itself computed by adding the value of
7121: @code{STACK_POINTER_OFFSET} to the stack pointer register.)
7122:
7123: @item RETURN_POPS_ARGS (@var{funtype})
7124: A C expression that should be 1 if a function pops its own arguments
7125: on returning, or 0 if the function pops no arguments and the caller
7126: must therefore pop them all after the function returns.
7127:
7128: @var{funtype} is a C variable whose value is a tree node that
7129: describes the function in question. Normally it is a node of type
7130: @code{FUNCTION_TYPE} that describes the data type of the function.
7131: From this it is possible to obtain the data types of the value and
7132: arguments (if known).
7133:
7134: When a call to a library function is being considered, @var{funtype}
7135: will contain an identifier node for the library function. Thus, if
7136: you need to distinguish among various library functions, you can do so
7137: by their names. Note that ``library function'' in this context means
7138: a function used to perform arithmetic, whose name is known specially
7139: in the compiler and was not mentioned in the C code being compiled.
7140:
7141: On the Vax, all functions always pop their arguments, so the
7142: definition of this macro is 1. On the 68000, using the standard
7143: calling convention, no functions pop their arguments, so the value of
7144: the macro is always 0 in this case. But an alternative calling
7145: convention is available in which functions that take a fixed number of
7146: arguments pop them but other functions (such as @code{printf}) pop
7147: nothing (the caller pops all). When this convention is in use,
7148: @var{funtype} is examined to determine whether a function takes a
7149: fixed number of arguments.
7150:
7151: @item FUNCTION_VALUE (@var{valtype}, @var{func})
7152: A C expression to create an RTX representing the place where a
7153: function returns a value of data type @var{valtype}. @var{valtype} is
7154: a tree node representing a data type. Write @code{TYPE_MODE
7155: (@var{valtype})} to get the machine mode used to represent that type.
7156: On many machines, only the mode is relevant. (Actually, on most
7157: machines, scalar values are returned in the same place regardless of
7158: mode).@refill
7159:
7160: If the precise function being called is known, @var{func} is a tree
7161: node (@code{FUNCTION_DECL}) for it; otherwise, @var{func} is a null
7162: pointer. This makes it possible to use a different value-returning
7163: convention for specific functions when all their calls are
7164: known.@refill
7165:
7166: @item FUNCTION_OUTGOING_VALUE (@var{valtype}, @var{func})
7167: Define this macro if the target machine has ``register windows''
7168: so that the register in which a function returns its value is not
7169: the same as the one in which the caller sees the value.
7170:
7171: For such machines, @code{FUNCTION_VALUE} computes the register in
7172: which the caller will see the value, and
7173: @code{FUNCTION_OUTGOING_VALUE} should be defined in a similar fashion
7174: to tell the function where to put the value.@refill
7175:
7176: If @code{FUNCTION_OUTGOING_VALUE} is not defined,
7177: @code{FUNCTION_VALUE} serves both purposes.@refill
7178:
7179: @item LIBCALL_VALUE (@var{mode})
7180: A C expression to create an RTX representing the place where a library
7181: function returns a value of mode @var{mode}. If the precise function
7182: being called is known, @var{func} is a tree node
7183: (@code{FUNCTION_DECL}) for it; otherwise, @var{func} is a null
7184: pointer. This makes it possible to use a different value-returning
7185: convention for specific functions when all their calls are
7186: known.@refill
7187:
7188: Note that ``library function'' in this context means a compiler
7189: support routine, used to perform arithmetic, whose name is known
7190: specially by the compiler and was not mentioned in the C code being
7191: compiled.
7192:
7193: @item FUNCTION_VALUE_REGNO_P (@var{regno})
7194: A C expression that is nonzero if @var{regno} is the number of a hard
7195: register in which the values of called function may come back.
7196:
7197: A register whose use for returning values is limited to serving as the
7198: second of a pair (for a value of type @code{double}, say) need not be
7199: recognized by this macro. So for most machines, this definition
7200: suffices:
7201:
7202: @example
7203: #define FUNCTION_VALUE_REGNO_P(N) ((N) == 0)
7204: @end example
7205:
7206: If the machine has register windows, so that the caller and the called
7207: function use different registers for the return value, this macro
7208: should recognize only the caller's register numbers.
7209:
7210: @item FUNCTION_ARG (@var{cum}, @var{mode}, @var{type}, @var{named})
7211: A C expression that controls whether a function argument is passed
7212: in a register, and which register.
7213:
7214: The arguments are @var{cum}, which summarizes all the previous
7215: arguments; @var{mode}, the machine mode of the argument; @var{type},
7216: the data type of the argument as a tree node or 0 if that is not known
7217: (which happens for C support library functions); and @var{named},
7218: which is 1 for an ordinary argument and 0 for nameless arguments that
7219: correspond to @samp{...} in the called function's prototype.
7220:
7221: The value of the expression should either be a @samp{reg} RTX for the
7222: hard register in which to pass the argument, or zero to pass the
7223: argument on the stack.
7224:
7225: For the Vax and 68000, where normally all arguments are pushed, zero
7226: suffices as a definition.
7227:
7228: @item FUNCTION_INCOMING_ARG (@var{cum}, @var{mode}, @var{type}, @var{named})
7229: Define this macro if the target machine has ``register windows'', so
7230: that the register in which a function sees an arguments is not
7231: necessarily the same as the one in which the caller passed the
7232: argument.
7233:
7234: For such machines, @code{FUNCTION_ARG} computes the register in which
7235: the caller passes the value, and @code{FUNCTION_INCOMING_ARG} should
7236: be defined in a similar fashion to tell the function being called
7237: where the arguments will arrive.
7238:
7239: If @code{FUNCTION_INCOMING_ARG} is not defined, @code{FUNCTION_ARG}
7240: serves both purposes.@refill
7241:
7242: @item FUNCTION_ARG_PARTIAL_NREGS (@var{cum}, @var{mode}, @var{type}, @var{named})
7243: A C expression for the number of words, at the beginning of an
7244: argument, must be put in registers. The value must be zero for
7245: arguments that are passed entirely in registers or that are entirely
7246: pushed on the stack.
7247:
7248: On some machines, certain arguments must be passed partially in
7249: registers and partially in memory. On these machines, typically the
7250: first @var{n} words of arguments are passed in registers, and the rest
7251: on the stack. If a multi-word argument (a @code{double} or a
7252: structure) crosses that boundary, its first few words must be passed
7253: in registers and the rest must be pushed. This macro tells the
7254: compiler when this occurs, and how many of the words should go in
7255: registers.
7256:
7257: @code{FUNCTION_ARG} for these arguments should return the first
7258: register to be used by the caller for this argument; likewise
7259: @code{FUNCTION_INCOMING_ARG}, for the called function.
7260:
7261: @item CUMULATIVE_ARGS
7262: A C type for declaring a variable that is used as the first argument
7263: of @code{FUNCTION_ARG} and other related values. For some target
7264: machines, the type @code{int} suffices and can hold the number of
7265: bytes of argument so far.
7266:
7267: @item INIT_CUMULATIVE_ARGS (@var{cum}, @var{fntype})
7268: A C statement (sans semicolon) for initializing the variable @var{cum}
7269: for the state at the beginning of the argument list. The variable has
7270: type @code{CUMULATIVE_ARGS}. The value of @var{fntype} is the tree node
7271: for the data type of the function which will receive the args, or 0
7272: if the args are to a compiler support library function.
7273:
7274: @item FUNCTION_ARG_ADVANCE (@var{cum}, @var{mode}, @var{type}, @var{named})
7275: Update the summarizer variable @var{cum} to advance past an argument
7276: in the argument list. The values @var{mode}, @var{type} and
7277: @var{named} describe that argument. Once this is done, the variable
7278: @var{cum} is suitable for analyzing the @emph{following} argument
7279: with @code{FUNCTION_ARG}, etc.@refill
7280:
7281: @item FUNCTION_ARG_REGNO_P (@var{regno})
7282: A C expression that is nonzero if @var{regno} is the number of a hard
7283: register in which function arguments are sometimes passed. This does
7284: @emph{not} include implicit arguments such as the static chain and
7285: the structure-value address. On many machines, no registers can be
7286: used for this purpose since all function arguments are pushed on the
7287: stack.
7288:
7289: @item FUNCTION_ARG_PADDING (@var{mode}, @var{size})
7290: If defined, a C expression which determines whether, and in which direction,
7291: to pad out an argument with extra space. The value should be of type
7292: @code{enum direction}: either @code{upward} to pad above the argument,
7293: @code{downward} to pad below, or @code{none} to inhibit padding.
7294:
7295: The argument @var{size} is an RTX which describes the size of the
7296: argument, in bytes. It should be used only if @var{mode} is
7297: @code{BLKmode}. Otherwise, @var{size} is 0.
7298:
7299: This macro does not control the @emph{amount} of padding; that is
7300: always just enough to reach the next multiple of @code{PARM_BOUNDARY}.
7301:
7302: This macro has a default definition which is right for most systems.
7303: For little-endian machines, the default is to pad upward. For
7304: big-endian machines, the default is to pad downward for an argument of
7305: constant size shorter than an @code{int}, and upward otherwise.
7306:
7307: @item FUNCTION_PROLOGUE (@var{file}, @var{size})
7308: A C compound statement that outputs the assembler code for entry to a
7309: function. The prologue is responsible for setting up the stack frame,
7310: initializing the frame pointer register, saving registers that must be
7311: saved, and allocating @var{size} additional bytes of storage for the
7312: local variables. @var{size} is an integer. @var{file} is a stdio
7313: stream to which the assembler code should be output.
7314:
7315: The label for the beginning of the function need not be output by this
7316: macro. That has already been done when the macro is run.
7317:
7318: To determine which registers to save, the macro can refer to the array
7319: @code{regs_ever_live}: element @var{r} is nonzero if hard register
7320: @var{r} is used anywhere within the function. This implies the
7321: function prologue should save register @var{r}, but not if it is one
7322: of the call-used registers.
7323:
7324: On machines where functions may or may not have frame-pointers, the
7325: function entry code must vary accordingly; it must set up the frame
7326: pointer if one is wanted, and not otherwise. To determine whether a
7327: frame pointer is in wanted, the macro can refer to the variable
7328: @code{frame_pointer_needed}. The variable's value will be 1 at run
7329: time in a function that needs a frame pointer.
7330:
7331: @item FUNCTION_PROFILER (@var{file}, @var{labelno})
7332: A C statement or compound statement to output to @var{file} some
7333: assembler code to call the profiling subroutine @code{mcount}.
7334: Before calling, the assembler code must load the address of a
7335: counter variable into a register where @code{mcount} expects to
7336: find the address. The name of this variable is @samp{LP} followed
7337: by the number @var{labelno}, so you would generate the name using
7338: @samp{LP%d} in a @code{fprintf}.
7339:
7340: The details of how the address should be passed to @code{mcount} are
7341: determined by your operating system environment, not by GNU CC. To
7342: figure them out, compile a small program for profiling using the
7343: system's installed C compiler and look at the assembler code that
7344: results.
7345:
7346: @item EXIT_IGNORES_STACK
7347: Define this macro as a C expression that is nonzero if the return
7348: instruction or the function epilogue ignores the value of the stack
7349: pointer; in other words, if it is safe to delete an instruction to
7350: adjust the stack pointer before a return from the function.
7351:
7352: Note that this macro's value is relevant only for for which frame
7353: pointers are maintained. It is never possible to delete a final stack
7354: adjustment in a function that has no frame pointer, and the compiler
7355: knows this regardless of @code{EXIT_IGNORES_STACK}.
7356:
7357: @item FUNCTION_EPILOGUE (@var{file}, @var{size})
7358: A C compound statement that outputs the assembler code for exit from a
7359: function. The epilogue is responsible for restoring the saved
7360: registers and stack pointer to their values when the function was
7361: called, and returning control to the caller. This macro takes the
7362: same arguments as the macro @code{FUNCTION_PROLOGUE}, and the
7363: registers to restore are determined from @code{regs_ever_live} and
7364: @code{CALL_USED_REGISTERS} in the same way.
7365:
7366: On some machines, there is a single instruction that does all the work
7367: of returning from the function. On these machines, give that
7368: instruction the name @samp{return} and do not define the macro
7369: @code{FUNCTION_EPILOGUE} at all.
7370:
7371: Do not define a pattern named @samp{return} if you want the
7372: @code{FUNCTION_EPILOGUE} to be used. If you want the target switches
7373: to control whether return instructions or epilogues are used, define a
7374: @samp{return} pattern with a validity condition that tests the target
7375: switches appropriately. If the @samp{return} pattern's validity
7376: condition is false, epilogues will be used.
7377:
7378: On machines where functions may or may not have frame-pointers, the
7379: function exit code must vary accordingly. Sometimes the code for
7380: these two cases is completely different. To determine whether a frame
7381: pointer is in wanted, the macro can refer to the variable
7382: @code{frame_pointer_needed}. The variable's value will be 1 at run
7383: time in a function that needs a frame pointer.
7384:
7385: On some machines, some functions pop their arguments on exit while
7386: others leave that for the caller to do. For example, the 68020 when
7387: given @samp{-mrtd} pops arguments in functions that take a fixed
7388: number of arguments.
7389:
7390: Your definition of the macro @code{RETURN_POPS_ARGS} decides which
7391: functions pop their own arguments. @code{FUNCTION_EPILOGUE} needs to
7392: know what was decided. The variable @code{current_function_pops_args}
7393: is nonzero if the function should pop its own arguments. If so, use
7394: the variable @code{current_function_args_size} as the number of bytes
7395: to pop.
7396:
7397: @item FIX_FRAME_POINTER_ADDRESS (@var{addr}, @var{depth})
7398: A C compound statement to alter a memory address that uses the frame
7399: pointer register so that it uses the stack pointer register instead.
7400: This must be done in the instructions that load parameter values into
7401: registers, when the reload pass determines that a frame pointer is not
7402: necessary for the function. @var{addr} will be a C variable name, and
7403: the updated address should be stored in that variable. @var{depth}
7404: will be the current depth of stack temporaries (number of bytes of
7405: arguments currently pushed). The change in offset between a
7406: frame-pointer-relative address and a stack-pointer-relative address
7407: must include @var{depth}.
7408:
7409: Even if your machine description specifies there will always be a
7410: frame pointer in the frame pointer register, you must still define
7411: @code{FIX_FRAME_POINTER_ADDRESS}, but the definition will never be
7412: executed at run time, so it may be empty.
7413: @end table
7414:
7415: @node Library Names, Addressing Modes, Stack Layout, Machine Macros
7416: @section Library Subroutine Names
7417:
7418: @table @code
7419: @item UDIVSI3_LIBCALL
7420: A C string constant giving the name of the function to call for
7421: division of a full-word by a full-word. If you do not define this
7422: macro, the default name is used, which is @code{_udivsi3}, a function
7423: defined in @file{gnulib}.
7424:
7425: @item UMODSI3_LIBCALL
7426: A C string constant giving the name of the function to call for the
7427: remainder in division of a full-word by a full-word. If you do not
7428: define this macro, the default name is used, which is @code{_umodsi3},
7429: a function defined in @file{gnulib}.
7430:
7431: @item TARGET_MEM_FUNCTIONS
7432: Define this macro if GNU CC should generate calls to the System V
7433: (and ANSI C) library functions @code{memcpy} and @code{memset}
7434: rather than the BSD functions @code{bcopy} and @code{bzero}.
7435: @end table
7436:
7437: @node Addressing Modes, Misc, Library Names, Machine Macros
7438: @section Addressing Modes
7439:
7440: @table @code
7441: @item HAVE_POST_INCREMENT
7442: Define this macro if the machine supports post-increment addressing.
7443:
7444: @item HAVE_PRE_INCREMENT
7445: @itemx HAVE_POST_DECREMENT
7446: @itemx HAVE_PRE_DECREMENT
7447: Similar for other kinds of addressing.
7448:
7449: @item CONSTANT_ADDRESS_P (@var{x})
7450: A C expression that is 1 if the RTX @var{x} is a constant whose value
7451: is an integer. This includes integers whose values are not explicitly
7452: known, such as @samp{symbol_ref} and @samp{label_ref} expressions and
7453: @samp{const} arithmetic expressions.
7454:
7455: On most machines, this can be defined as @code{CONSTANT_P (@var{x})},
7456: but a few machines are more restrictive in which constant addresses
7457: are supported.
7458:
7459: @item MAX_REGS_PER_ADDRESS
7460: A number, the maximum number of registers that can appear in a valid
7461: memory address.
7462:
7463: @item GO_IF_LEGITIMATE_ADDRESS (@var{mode}, @var{x}, @var{label})
7464: A C compound statement with a conditional @code{goto @var{label};}
7465: executed if @var{x} (an RTX) is a legitimate memory address on the
7466: target machine for a memory operand of mode @var{mode}.
7467:
7468: It usually pays to define several simpler macros to serve as
7469: subroutines for this one. Otherwise it may be too complicated to
7470: understand.
7471:
7472: This macro must exist in two variants: a strict variant and a
7473: non-strict one. The strict variant is used in the reload pass. It
7474: must be defined so that any pseudo-register that has not been
7475: allocated a hard register is considered a memory reference. In
7476: contexts where some kind of register is required, a pseudo-register
7477: with no hard register must be rejected.
7478:
7479: The non-strict variant is used in other passes. It must be defined to
7480: accept all pseudo-registers in every context where some kind of
7481: register is required.
7482:
7483: Compiler source files that want to use the strict variant of this
7484: macro define the macro @code{REG_OK_STRICT}. You should use an
7485: @code{#ifdef REG_OK_STRICT} conditional to define the strict variant
7486: in that case and the non-strict variant otherwise.
7487:
7488: Typically among the subroutines used to define
7489: @code{GO_IF_LEGITIMATE_ADDRESS} are subroutines to check for
7490: acceptable registers for various purposes (one for base registers, one
7491: for index registers, and so on). Then only these subroutine macros
7492: need have two variants; the higher levels of macros may be the same
7493: whether strict or not.@refill
7494:
7495: @item REG_OK_FOR_BASE_P (@var{x})
7496: A C expression that is nonzero if @var{x} (asumed to be a @code{reg}
7497: RTX) is valid for use as a base register. For hard registers, it
7498: should always accept those which the hardware permits and reject the
7499: others. Whether the macro accepts or rejects pseudo registers must be
7500: controlled by @code{REG_OK_STRICT} as described above. This usually
7501: requires two variant definitions, of which @code{REG_OK_STRICT}
7502: controls the one actually used.
7503:
7504: @item REG_OK_FOR_INDEX_P (@var{x})
7505: A C expression that is nonzero if @var{x} (asumed to be a @code{reg}
7506: RTX) is valid for use as an index register.
7507:
7508: The difference between an index register and a base register is that
7509: the index register may be scaled. If an address involves the sum of
7510: two registers, neither one of them scaled, then either one may be
7511: labeled the ``base'' and the other the ``index''; but whichever
7512: labeling is used must fit the machine's constraints of which registers
7513: may serve in each capacity. The compiler will try both labelings,
7514: looking for one that is valid, and will reload one or both registers
7515: only if neither labeling works.
7516:
7517: @item LEGITIMIZE_ADDRESS (@var{x}, @var{oldx}, @var{mode}, @var{win})
7518: A C compound statement that attempts to replace @var{x} with a valid
7519: memory address for an operand of mode @var{mode}. @var{win} will be a
7520: C statement label elsewhere in the code; the macro definition may use
7521:
7522: @example
7523: GO_IF_LEGITIMATE_ADDRESS (@var{mode}, @var{x}, @var{win});
7524: @end example
7525:
7526: @noindent
7527: to avoid further processing if the address has become legitimate.
7528:
7529: @var{x} will always be the result of a call to @code{break_out_memory_refs},
7530: and @var{oldx} will be the operand that was given to that function to produce
7531: @var{x}.
7532:
7533: The code generated by this macro should not alter the substructure of
7534: @var{x}. If it transforms @var{x} into a more legitimate form, it
7535: should assign @var{x} (which will always be a C variable) a new value.
7536:
7537: It is not necessary for this macro to come up with a legitimate
7538: address. The compiler has standard ways of doing so in all cases. In
7539: fact, it is safe for this macro to do nothing. But often a
7540: machine-dependent strategy can generate better code.
7541:
7542: @item GO_IF_MODE_DEPENDENT_ADDRESS (@var{addr}, @var{label})
7543: A C statement or compound statement with a conditional @code{goto
7544: @var{label};} executed if memory address @var{x} (an RTX) can have
7545: different meanings depending on the machine mode of the memory
7546: reference it is used for.
7547:
7548: Autoincrement and autodecrement addresses typically have mode-dependent
7549: effects because the amount of the increment or decrement is the size
7550: of the operand being addressed. Some machines have other mode-dependent
7551: addresses. Many RISC machines have no mode-dependent addresses.
7552:
7553: You may assume that @var{addr} is a valid address for the machine.
7554:
7555: @item LEGITIMATE_CONSTANT_P (@var{x})
7556: A C expression that is nonzero if @var{x} is a legitimate constant for
7557: an immediate operand on the target machine. You can assume that
7558: either @var{x} is a @samp{const_double} or it satisfies
7559: @code{CONSTANT_P}, so you need not check these things. In fact,
7560: @samp{1} is a suitable definition for this macro on machines where any
7561: @samp{const_double} is valid and anything @code{CONSTANT_P} is valid.@refill
7562: @end table
7563:
7564: @node Misc, Condition Code, Addressing Modes, Machine Macros
7565: @section Miscellaneous Parameters
7566:
7567: @table @code
7568: @item CASE_VECTOR_MODE
7569: An alias for a machine mode name. This is the machine mode that
7570: elements of a jump-table should have.
7571:
7572: @item CASE_VECTOR_PC_RELATIVE
7573: Define this macro if jump-tables should contain relative addresses.
7574:
7575: @item CASE_DROPS_THROUGH
7576: Define this if control falls through a @code{case} insn when the index
7577: value is out of range. This means the specified default-label is
7578: actually ignored by the @code{case} insn proper.
7579:
7580: @item IMPLICIT_FIX_EXPR
7581: An alias for a tree code that should be used by default for conversion
7582: of floating point values to fixed point. Normally,
7583: @code{FIX_ROUND_EXPR} is used.@refill
7584:
7585: @item FIXUNS_TRUNC_LIKE_FIX_TRUNC
7586: Define this macro if the same instructions that convert a floating
7587: point number to a signed fixed point number also convert validly to an
7588: unsigned one.
7589:
7590: @item EASY_DIV_EXPR
7591: An alias for a tree code that is the easiest kind of division to
7592: compile code for in the general case. It may be
7593: @code{TRUNC_DIV_EXPR}, @code{FLOOR_DIV_EXPR}, @code{CEIL_DIV_EXPR} or
7594: @code{ROUND_DIV_EXPR}. These four division operators differ in how
7595: they round the result to an integer. @code{EASY_DIV_EXPR} is used
7596: when it is permissible to use any of those kinds of division and the
7597: choice should be made on the basis of efficiency.@refill
7598:
7599: @item DEFAULT_SIGNED_CHAR
7600: An expression whose value is 1 or 0, according to whether the type
7601: @code{char} should be signed or unsigned by default. The user can
7602: always override this default with the options @samp{-fsigned-char}
7603: and @samp{-funsigned-char}.
7604:
7605: @item SCCS_DIRECTIVE
7606: Define this if the preprocessor should ignore @code{#sccs} directives
7607: and print no error message.
7608:
7609: @item IDENT_DIRECTIVE
7610: Define this if the preprocessor should ignore @code{#ident} directives
7611: and print no error message.
7612:
7613: @item MOVE_MAX
7614: The maximum number of bytes that a single instruction can move quickly
7615: from memory to memory.
7616:
7617: @item INT_TYPE_SIZE
7618: A C expression for the size in bits of the type @code{int} on the
7619: target machine.
7620:
7621: @item SLOW_BYTE_ACCESS
7622: Define this macro as a C expression which is nonzero if accessing less
7623: than a word of memory (i.e. a @code{char} or a @code{short}) is slow
7624: (requires more than one instruction).
7625:
7626: @item SLOW_ZERO_EXTEND
7627: Define this macro if zero-extension (of a @code{char} or @code{short}
7628: to an @code{int}) can be done faster if the destination is a register
7629: that is known to be zero.
7630:
7631: If you define this macro, you must have instruction patterns that
7632: recognize RTL structures like this:
7633:
7634: @example
7635: (set (strict-low-part (subreg:QI (reg:SI @dots{}) 0)) @dots{})
7636: @end example
7637:
7638: @noindent
7639: and likewise for @code{HImode}.
7640:
7641: @item SHIFT_COUNT_TRUNCATED
7642: Define this macro if shift instructions ignore all but the lowest few
7643: bits of the shift count. It implies that a sign-extend or zero-extend
7644: instruction for the shift count can be omitted.
7645:
7646: @item TRULY_NOOP_TRUNCATION (@var{outprec}, @var{inprec})
7647: A C expression which is nonzero if on this machine it is safe to
7648: ``convert'' an integer of @var{inprec} bits to one of @var{outprec}
7649: bits (where @var{outprec} is smaller than @var{inprec}) by merely
7650: operating on it as if it had only @var{outprec} bits.
7651:
7652: On many machines, this expression can be 1.
7653:
7654: @item NO_FUNCTION_CSE
7655: Define this macro if it is as good or better to call a constant
7656: function address than to call an address kept in a register.
7657:
7658: @item PROMOTE_PROTOTYPES
7659: Define this macro if an argument declared as @code{char} or
7660: @code{short} in a prototype should actually be passed as an
7661: @code{int}. In addition to avoiding errors in certain cases of
7662: mismatch, it also makes for better code on certain machines.
7663:
7664: @item STORE_FLAG_VALUE
7665: A C expression for the value stored by a store-flag instruction
7666: (@code{s@var{cond}}) when the condition is true. This is usually 1 or
7667: -1; it is required to be an odd number.
7668:
7669: Do not define @code{STORE_FLAG_VALUE} if the machine has no store-flag
7670: instructions.
7671:
7672: @item Pmode
7673: An alias for the machine mode for pointers. Normally the definition
7674: can be
7675:
7676: @example
7677: #define Pmode SImode
7678: @end example
7679:
7680: @item FUNCTION_MODE
7681: An alias for the machine mode used for memory references to functions
7682: being called, in @samp{call} RTL expressions. On most machines this
7683: should be @code{QImode}.
7684:
7685: @item INSN_MACHINE_INFO
7686: This macro should expand into a C structure type to use for the
7687: machine-dependent info field specified with the optional last argument
7688: in @samp{define_insn} and @samp{define_peephole} patterns. For example,
7689: it might expand into @samp{struct machine_info}; then it would be up
7690: to you to define this structure in the @file{tm.h} file.
7691:
7692: You do not need to define this macro if you do not write the optional
7693: last argument in any of the patterns in the machine description.
7694:
7695: @item CONST_COSTS (@var{x}, @var{code})
7696: A part of a C @code{switch} statement that describes the relative
7697: costs of constant RTL expressions. It must contain @code{case} labels
7698: for expression codes @samp{const_int}, @samp{const}, @samp{symbol_ref}, @samp{label_ref}
7699: and @samp{const_double}. Each case must ultimately reach a
7700: @code{return} statement to return the relative cost of the use of that
7701: kind of constant value in an expression. The cost may depend on the
7702: precise value of the constant, which is available for examination in
7703: @var{x}.
7704:
7705: @var{code} is the expression code---redundant, since it can be
7706: obtained with @code{GET_CODE (@var{x})}.
7707:
7708: @item DOLLARS_IN_IDENTIFIERS
7709: Define this to be nonzero if the character @samp{$} should be allowed
7710: by default in identifier names.
7711: @end table
7712:
7713: @node Condition Code, Assembler Format, Misc, Machine Macros
7714: @section Condition Code Information
7715:
7716: The file @file{conditions.h} defines a variable @code{cc_status} to
7717: describe how the condition code was computed (in case the interpretation of
7718: the condition code depends on the instruction that it was set by). This
7719: variable contains the RTL expressions on which the condition code is
7720: currently based, and several standard flags.
7721:
7722: Sometimes additional machine-specific flags must be defined in the machine
7723: description header file. It can also add additional machine-specific
7724: information by defining @code{CC_STATUS_MDEP}.
7725:
7726: @table @code
7727: @item CC_STATUS_MDEP
7728: C code for a data type which is used for declaring the @code{mdep}
7729: component of @code{cc_status}. It defaults to @code{int}.
7730:
7731: @item CC_STATUS_MDEP_INIT
7732: A C expression for the initial value of the @code{mdep} field. It
7733: defaults to 0.
7734:
7735: @item NOTICE_UPDATE_CC (@var{exp}, @var{insn})
7736: A C compound statement to set the components of @code{cc_status}
7737: appropriately for an insn @var{insn} whose body is @var{exp}. It is
7738: this macro's responsibility to recognize insns that set the condition
7739: code as a byproduct of other activity as well as those that explicitly
7740: set @code{(cc0)}.
7741:
7742: If there are insn that do not set the condition code but do alter
7743: other machine registers, this macro must check to see whether they
7744: invalidate the expressions that the condition code is recorded as
7745: reflecting. For example, on the 68000, insns that store in address
7746: registers do not set the condition code, which means that usually
7747: @code{NOTICE_UPDATE_CC} can leave @code{cc_status} unaltered for such
7748: insns. But suppose that the previous insn set the condition code
7749: based on location @samp{a4@@(102)} and the current insn stores a new
7750: value in @samp{a4}. Although the condition code is not changed by
7751: this, it will no longer be true that it reflects the contents of
7752: @samp{a4@@(102)}. Therefore, @code{NOTICE_UPDATE_CC} must alter
7753: @code{cc_status} in this case to say that nothing is known about the
7754: condition code value.
7755:
7756: The definition of @code{NOTICE_UPDATE_CC} must be prepared to deal
7757: with the results of peephole optimization: insns whose patterns are
7758: @samp{parallel} RTXs containing various @samp{reg}, @samp{mem} or
7759: constants which are just the operands. The RTL structure of these
7760: insns is not sufficient to indicate what the insns actually do. What
7761: @code{NOTICE_UPDATE_CC} should do when it sees one is just to run
7762: @code{CC_STATUS_INIT}.
7763: @end table
7764:
7765: @node Assembler Format,, Condition Code, Machine Macros
7766: @section Output of Assembler Code
7767:
7768: @table @code
7769: @item ASM_SPEC
7770: A C string constant that tells the GNU CC driver program options to
7771: pass to the assembler. It can also specify how to translate options
7772: you give to GNU CC into options for GNU CC to pass to the assembler.
7773: See the file @file{tm-sun3.h} for an example of this.
7774:
7775: Do not define this macro if it does not need to do anything.
7776:
7777: @item LINK_SPEC
7778: A C string constant that tells the GNU CC driver program options to
7779: pass to the linker. It can also specify how to translate options you
7780: give to GNU CC into options for GNU CC to pass to the linker.
7781:
7782: Do not define this macro if it does not need to do anything.
7783:
7784: @item LIB_SPEC
7785: Another C string constant used much like @code{LINK_SPEC}. The difference
7786: between the two is that @code{LIBS_SPEC} is used at the end of the
7787: command given to the linker.
7788:
7789: If this macro is not defined, a default is provided that
7790: loads the standard C library from the usual place. See @file{gcc.c}.
7791:
7792: @item STARTFILE_SPEC
7793: Another C string constant used much like @code{LINK_SPEC}. The
7794: difference between the two is that @code{STARTFILE_SPEC} is used at
7795: the very beginning of the command given to the linker.
7796:
7797: If this macro is not defined, a default is provided that loads the
7798: standard C startup file from the usual place. See @file{gcc.c}.
7799:
1.1.1.4 ! root 7800: @item STANDARD_STARTFILE_PREFIX
! 7801: Define this macro as a C string constant if you wish to override the
! 7802: standard choice of @file{/lib/} as the default prefix for where to
! 7803: find the startup files such as @file{crt0.o}.
! 7804:
1.1 root 7805: @item ASM_FILE_START (@var{stream})
7806: A C expression which outputs to the stdio stream @var{stream}
7807: some appropriate text to go at the start of an assembler file.
7808:
7809: Normally this macro is defined to output a line containing
7810: @samp{#NO_APP}, which is a comment that has no effect on most
7811: assemblers but tells the GNU assembler that it can save time by not
7812: checking for certain assembler constructs.
7813:
7814: On systems that use SDB, it is necessary to output certain commands;
7815: see @file{tm-attasm.h}.
7816:
7817: @item ASM_APP_ON
7818: A C string constant for text to be output before each @code{asm}
7819: statement or group of consecutive ones. Normally this is
7820: @code{"#APP"}, which is a comment that has no effect on most
7821: assemblers but tells the GNU assembler that it must check the lines
7822: that follow for all valid assembler constructs.
7823:
7824: @item ASM_APP_OFF
7825: A C string constant for text to be output after each @code{asm}
7826: statement or group of consecutive ones. Normally this is
7827: @code{"#NO_APP"}, which tells the GNU assembler to resume making the
7828: time-saving assumptions that are valid for ordinary compiler output.
7829:
7830: @item TEXT_SECTION_ASM_OP
7831: A C string constant for the assembler operation that should precede
7832: instructions and read-only data. Normally @code{".text"} is right.
7833:
7834: @item DATA_SECTION_ASM_OP
7835: A C string constant for the assembler operation to identify the
7836: following data as writable initialized data. Normally @code{".data"}
7837: is right.
7838:
7839: @item REGISTER_NAMES
7840: A C initializer containing the assembler's names for the machine
7841: registers, each one as a C string constant. This is what translates
7842: register numbers in the compiler into assembler language.
7843:
7844: @item DBX_REGISTER_NUMBER (@var{regno})
7845: A C expression that returns the DBX register number for the compiler
7846: register number @var{regno}. In simple cases, the value of this
7847: expression may be @var{regno} itself. But sometimes there are some
7848: registers that the compiler knows about and DBX does not, or vice
7849: versa. In such cases, some register may need to have one number in
7850: the compiler and another for DBX.
7851:
7852: @item DBX_DEBUGGING_INFO
7853: Define this macro if GNU CC should produce debugging output for DBX
7854: in response to the @samp{-g} option.
7855:
7856: @item SDB_DEBUGGING_INFO
7857: Define this macro if GNU CC should produce debugging output for SDB
7858: in response to the @samp{-g} option.
7859:
7860: @item PUT_SDB_@var{op}
7861: Define these macros to override the assembler syntax for the special
7862: SDB assembler directives. See @file{sdbout.c} for a list of these
7863: macros and their arguments. If the standard syntax is used, you need
7864: not define them yourself.
7865:
7866: @item SDB_GENERATE_FAKE
7867: Define this macro to override the usual method of constructing a dummy
7868: name for anonymous structure and union types. See @file{sdbout.c} for
7869: more infomation.
7870:
7871: @item DBX_NO_XREFS
7872: Define this macro if DBX on your system does not support the construct
7873: @samp{xs@var{tagname}}. On some systems, this construct is used to
7874: describe a forward reference to a structure named @var{tagname}.
7875: On other systems, this construct is not supported at all.
7876:
7877: @item DBX_CONTIN_LENGTH
7878: A symbol name in DBX-format debugging information is normally
7879: continued (split into two separate @code{.stabs} directives) when it
7880: exceeds a certain length (by default, 80 characters). On some
7881: operating systems, DBX requires this splitting; on others, splitting
7882: must not be done. You can inhibit splitting by defining this macro
7883: with the value zero. You can override the default splitting-length by
7884: defining this macro as an expression for the length you desire.
7885:
7886: @item DBX_CONTIN_CHAR
7887: Normally continuation is indicated by adding a @samp{\} character to
7888: the end of a @code{.stabs} string when a continuation follows. To use
7889: a different character instead, define this macro as a character
7890: constant for the character you want to use. Do not define this macro
7891: if backslash is correct for your system.
7892:
7893: @item ASM_OUTPUT_LABEL (@var{stream}, @var{name})
7894: A C statement (sans semicolon) to output to the stdio stream
7895: @var{stream} the assembler definition of a label named @var{name}. Use
7896: the expression @code{assemble_name (@var{stream}, @var{name})} to output
7897: the name itself; before and after that, output the additional
7898: assembler syntax for defining the name, and a newline.
7899:
7900: @item ASM_DECLARE_FUNCTION_NAME (@var{stream}, @var{name}, @var{decl})
7901: A C statement (sans semicolon) to output to the stdio stream
7902: @var{stream} any text necessary for declaring the name @var{name} of a
7903: function which is being defined. This macro is responsible for
7904: outputting the label definition (perhaps using
7905: @code{ASM_OUTPUT_LABEL}). The argument @var{decl} is the
7906: @code{FUNCTION_DECL} tree node representing the function.
7907:
7908: If this macro is not defined, then the function name is defined in the
7909: usual manner as a label (by means of @code{ASM_OUTPUT_LABEL}).
7910:
7911: @item ASM_GLOBALIZE_LABEL (@var{stream}, @var{name})
7912: A C statement (sans semicolon) to output to the stdio stream
7913: @var{stream} some commands that will make the label @var{name} global;
7914: that is, available for reference from other files. Use the expression
7915: @code{assemble_name (@var{stream}, @var{name})} to output the name
7916: itself; before and after that, output the additional assembler syntax
7917: for making that name global, and a newline.
7918:
7919: @item ASM_OUTPUT_EXTERNAL (@var{stream}, @var{name}, @var{decl})
7920: A C statement (sans semicolon) to output to the stdio stream
7921: @var{stream} any text necessary for declaring the name of an external
7922: symbol named @var{name} which is referenced in this compilation but
7923: not defined. The value of @var{decl} is the tree node for the
7924: declaration.
7925:
7926: This macro need not be defined if it does not need to output anything.
7927: The GNU assembler and most Unix assemblers don't require anything.
7928:
7929: @item ASM_OUTPUT_LABELREF (@var{stream}, @var{name})
7930: A C statement to output to the stdio stream @var{stream} a reference in
7931: assembler syntax to a label named @var{name}. The character @samp{_}
7932: should be added to the front of the name, if that is customary on your
7933: operating system, as it is in most Berkeley Unix systems. This macro
7934: is used in @code{assemble_name}.
7935:
7936: @item ASM_GENERATE_INTERNAL_LABEL (@var{string}, @var{prefix}, @var{num})
7937: A C statement to store into the string @var{string} a label whose
7938: name is made from the string @var{prefix} and the number @var{num}.
7939:
7940: This string, when output subsequently by @code{ASM_OUTPUT_LABELREF},
7941: should produce the same output that @code{ASM_OUTPUT_INTERNAL_LABEL}
7942: would produce with the same @var{prefix} and @var{num}.
7943:
7944: @item ASM_OUTPUT_INTERNAL_LABEL (@var{stream}, @var{prefix}, @var{num})
7945: A C statement to output to the stdio stream @var{stream} a label whose
7946: name is made from the string @var{prefix} and the number @var{num}.
7947: These labels are used for internal purposes, and there is no reason
7948: for them to appear in the symbol table of the object file. On many
7949: systems, the letter @samp{L} at the beginning of a label has this
7950: effect. The usual definition of this macro is as follows:
7951:
7952: @example
7953: fprintf (@var{stream}, "L%s%d:\n", @var{prefix}, @var{num})
7954: @end example
7955:
7956: @item ASM_OUTPUT_CASE_LABEL (@var{stream}, @var{prefix}, @var{num}, @var{table})
7957: Define this if the label before a jump-table needs to be output
7958: specially. The first three arguments are the same as for
7959: @code{ASM_OUTPUT_INTERNAL_LABEL}; the fourth argument is the
7960: jump-table which follows (a @samp{jump_insn} containing an
7961: @samp{addr_vec} or @samp{addr_diff_vec}).
7962:
7963: This feature is used on system V to output a @code{swbeg} statement
7964: for the table.
7965:
7966: If this macro is not defined, these labels are output with
7967: @code{ASM_OUTPUT_INTERNAL_LABEL}.
7968:
7969: @item ASM_OUTPUT_CASE_END (@var{stream}, @var{num}, @var{table})
7970: Define this if something special must be output at the end of a jump-table.
7971: The definition should be a C statement to be executed after the assembler
7972: code for the table is written. It should write the appropriate code to
7973: stdio stream @var{stream}. The argument @var{table} is the jump-table
7974: insn, and @var{num} is the label-number of the preceding label.
7975:
7976: If this macro is not defined, nothing special is output at the end of
7977: the jump-table.
7978:
1.1.1.4 ! root 7979: @item ASM_OUTPUT_ALIGN_CODE (@var{file})
! 7980: A C expression to output text to align the location counter in the way
! 7981: that is desirable at a point in the code that is reached only by
! 7982: jumping.
! 7983:
! 7984: This macro need not be defined if you don't want any special alignment
! 7985: to be done at such a time. Most machine descriptions do not currently
! 7986: define the macro.
! 7987:
1.1 root 7988: @item ASM_FORMAT_PRIVATE_NAME (@var{outvar}, @var{name}, @var{number})
7989: A C expression to assign to @var{outvar} (which is a variable of type
7990: @code{char *}) a newly allocated string made from the string
7991: @var{name} and the number @var{number}, with some suitable punctuation
7992: added. Use @code{alloca} to get space for the string.
7993:
7994: This string will be used as the argument to @code{ASM_OUTPUT_LABELREF}
7995: to produce an assembler label for an internal static variable whose
7996: name is @var{name}. Therefore, the string must be such as to result
7997: in valid assembler code. The argument @var{number} is different each
7998: time this macro is executed; it prevents conflicts between
7999: similarly-named internal static variables in different scopes.
8000:
8001: Ideally this string should not be a valid C identifier, to prevent any
8002: conflict with the user's own symbols. Most assemblers allow periods
8003: or percent signs in assembler symbols; putting at least one of these
8004: between the name and the number will suffice.
8005:
8006: @item ASM_OUTPUT_REG_PUSH (@var{stream}, @var{regno})
8007: A C expression to output to @var{stream} some assembler code
8008: which will push hard register number @var{regno} onto the stack.
8009: The code need not be optimal, since this macro is used only when
8010: profiling.
8011:
8012: @item ASM_OUTPUT_REG_POP (@var{stream}, @var{regno})
8013: A C expression to output to @var{stream} some assembler code
8014: which will pop hard register number @var{regno} off of the stack.
8015: The code need not be optimal, since this macro is used only when
8016: profiling.
8017:
8018: @item ASM_OUTPUT_ADDR_DIFF_ELT (@var{stream}, @var{value}, @var{rel})
8019: This macro should be provided on machines where the addresses
8020: in a dispatch table are relative to the table's own address.
8021:
8022: The definition should be a C statement to output to the stdio stream
8023: @var{stream} an assembler pseudo-instruction to generate a difference
8024: between two labels. @var{value} and @var{rel} are the numbers of two
8025: internal labels. The definitions of these labels are output using
8026: @code{ASM_OUTPUT_INTERNAL_LABEL}, and they must be printed in the same
8027: way here. For example,
8028:
8029: @example
8030: fprintf (@var{stream}, "\t.word L%d-L%d\n",
8031: @var{value}, @var{rel})
8032: @end example
8033:
8034: @item ASM_OUTPUT_ADDR_VEC_ELT (@var{stream}, @var{value})
8035: This macro should be provided on machines where the addresses
8036: in a dispatch table are absolute.
8037:
8038: The definition should be a C statement to output to the stdio stream
8039: @var{stream} an assembler pseudo-instruction to generate a reference to
8040: a label. @var{value} is the number of an internal label whose
8041: definition is output using @code{ASM_OUTPUT_INTERNAL_LABEL}.
8042: For example,
8043:
8044: @example
8045: fprintf (@var{stream}, "\t.word L%d\n", @var{value})
8046: @end example
8047:
8048: @item ASM_OUTPUT_DOUBLE (@var{stream}, @var{value})
8049: A C statement to output to the stdio stream @var{stream} an assembler
8050: instruction to assemble a @code{double} constant whose value is
8051: @var{value}. @var{value} will be a C expression of type
8052: @code{double}.
8053:
8054: @item ASM_OUTPUT_FLOAT (@var{stream}, @var{value})
8055: A C statement to output to the stdio stream @var{stream} an assembler
8056: instruction to assemble a @code{float} constant whose value is
8057: @var{value}. @var{value} will be a C expression of type @code{float}.
8058:
8059: @item ASM_OUTPUT_INT (@var{stream}, @var{exp})
8060: @itemx ASM_OUTPUT_SHORT (@var{stream}, @var{exp})
8061: @itemx ASM_OUTPUT_CHAR (@var{stream}, @var{exp})
8062: A C statement to output to the stdio stream @var{stream} an assembler
8063: instruction to assemble a @code{int}, @code{short} or @code{char}
8064: constant whose value is @var{value}. The argument @var{exp} will be
8065: an RTL expression which represents a constant value. Use
8066: @samp{output_addr_const (@var{exp})} to output this value as an
8067: assembler expression.@refill
8068:
8069: @item ASM_OUTPUT_BYTE (@var{stream}, @var{value})
8070: A C statement to output to the stdio stream @var{stream} an assembler
8071: instruction to assemble a single byte containing the number @var{value}.
8072:
8073: @item ASM_OUTPUT_ASCII (@var{stream}, @var{ptr}, @var{len})
8074: A C statement to output to the stdio stream @var{stream} an assembler
8075: instruction to assemble a string constant containing the @var{len}
8076: bytes at @var{ptr}. @var{ptr} will be a C expression of type
8077: @code{char *} and @var{len} a C expression of type @code{int}.
8078:
8079: If the assembler has a @code{.ascii} pseudo-op as found in the
8080: Berkeley Unix assembler, do not define the macro
8081: @code{ASM_OUTPUT_ASCII}.
8082:
8083: @item ASM_OUTPUT_SKIP (@var{stream}, @var{nbytes})
8084: A C statement to output to the stdio stream @var{stream} an assembler
8085: instruction to advance the location counter by @var{nbytes} bytes.
8086: @var{nbytes} will be a C expression of type @code{int}.
8087:
8088: @item ASM_OUTPUT_ALIGN (@var{stream}, @var{power})
8089: A C statement to output to the stdio stream @var{stream} an assembler
8090: instruction to advance the location counter to a multiple of 2 to the
8091: @var{power} bytes. @var{power} will be a C expression of type @code{int}.
8092:
8093: @item ASM_OUTPUT_COMMON (@var{stream}, @var{name}, @var{size})
8094: A C statement (sans semicolon) to output to the stdio stream
8095: @var{stream} the assembler definition of a common-label named @var{name}
8096: whose size is @var{size} bytes. Use the expression
8097: @code{assemble_name (@var{stream}, @var{name})} to output the name
8098: itself; before and after that, output the additional assembler syntax
8099: for defining the name, and a newline.
8100:
8101: This macro controls how the assembler definitions of uninitialized
8102: global variables are output.
8103:
8104: @item ASM_OUTPUT_LOCAL (@var{stream}, @var{name}, @var{size})
8105: A C statement (sans semicolon) to output to the stdio stream
8106: @var{stream} the assembler definition of a local-common-label named
8107: @var{name} whose size is @var{size} bytes. Use the expression
8108: @code{assemble_name (@var{stream}, @var{name})} to output the name
8109: itself; before and after that, output the additional assembler syntax
8110: for defining the name, and a newline.
8111:
8112: This macro controls how the assembler definitions of uninitialized
8113: static variables are output.
8114:
8115: @item ASM_OUTPUT_SOURCE_LINE (@var{stream}, @var{line})
8116: A C statment to output DBX or SDB debugging information before code
8117: for line number @var{line} of the current source file to the
8118: stdio stream @var{stream}.
8119:
8120: This macro need not be defined if the standard form of debugging
8121: information for the debugger in use is appropriate.
8122:
8123: @item ASM_OUTPUT_IDENT (@var{stream}, @var{string})
8124: A C statement to output something to the assembler file to handle a
8125: @samp{#ident} directive containing the text @var{string}. If this
8126: macro is not defined, the assembler code @samp{.ident "@var{string}"}
8127: will be output by default.
8128:
8129: This macro is significant only if @code{IDENT_DIRECTIVE} is defined.
8130:
8131: @item TARGET_BELL
8132: A C constant expression for the integer value for escape sequence
8133: @samp{\a}.
8134:
8135: @item TARGET_BS
8136: @itemx TARGET_TAB
8137: @itemx TARGET_NEWLINE
8138: C constant expressions for the integer values for escape sequences
8139: @samp{\b}, @samp{\t} and @samp{\n}.
8140:
8141: @item TARGET_VT
8142: @itemx TARGET_FF
8143: @itemx TARGET_CR
8144: C constant expressions for the integer values for escape sequences
8145: @samp{\v}, @samp{\f} and @samp{\r}.
8146:
8147: @item ASM_OUTPUT_OPCODE (@var{stream}, @var{ptr})
8148: Define this macro if you are using an unusual assembler that
8149: requires different names for the machine instructions.
8150:
8151: The definition is a C statement or statements which output an
8152: assembler instruction opcode to the stdio stream @var{stream}. The
8153: macro-operand @var{ptr} is a variable of type @code{char *} which
8154: points to the opcode name in its ``internal'' form---the form that is
8155: written in the machine description. The definition should output the
8156: opcode name to @var{stream}, performing any translation you desire, and
8157: increment the variable @var{ptr} to point at the end of the opcode
8158: so that it will not be output twice.
8159:
8160: In fact, your macro definition may process less than the entire opcode
8161: name, or more than the opcode name; but if you want to process text
8162: that includes @samp{%}-sequences to substitute operands, you must take
8163: care of the substitution yourself. Just be sure to increment
8164: @var{ptr} over whatever text should not be output normally.
8165:
8166: If the macro definition does nothing, the instruction is output
8167: in the usual way.
8168:
8169: @item FINAL_PRESCAN_INSN (@var{insn}, @var{opvec}, @var{noperands})
8170: If defined, a C statement to be executed just prior to the output of
8171: assembler code for @var{insn}, to modify the extracted operands so
8172: they will be output differently.
8173:
8174: Here the argument @var{opvec} is the vector containing the operands
8175: extracted from @var{insn}, and @var{noperands} is the number of
8176: elements of the vector which contain meaningful data for this insn.
8177: The contents of this vector are what will be used to convert the insn
8178: template into assembler code, so you can change the assembler output
8179: by changing the contents of the vector.
8180:
8181: This macro is useful when various assembler syntaxes share a single
8182: file of instruction patterns; by defining this macro differently, you
8183: can cause a large class of instructions to be output differently (such
8184: as with rearranged operands). Naturally, variations in assembler
8185: syntax affecting individual insn patterns ought to be handled by
8186: writing conditional output routines in those patterns.
8187:
8188: If this macro is not defined, it is equivalent to a null statement.
8189:
8190: @item PRINT_OPERAND (@var{stream}, @var{x}, @var{code})
8191: A C compound statement to output to stdio stream @var{stream} the
8192: assembler syntax for an instruction operand @var{x}. @var{x} is an
8193: RTL expression.
8194:
8195: @var{code} is a value that can be used to specify one of several ways
8196: of printing the operand. It is used when identical operands must be
8197: printed differently depending on the context. @var{code} comes from
8198: the @samp{%} specification that was used to request printing of the
8199: operand. If the specification was just @samp{%@var{digit}} then
8200: @var{code} is 0; if the specification was @samp{%@var{ltr}
8201: @var{digit}} then @var{code} is the ASCII code for @var{ltr}.
8202:
8203: If @var{x} is a register, this macro should print the register's name.
8204: The names can be found in an array @code{reg_names} whose type is
8205: @code{char *[]}. @code{reg_names} is initialized from
8206: @code{REGISTER_NAMES}.
8207:
8208: When the machine description has a specification @samp{%@var{punct}}
8209: (a @samp{%} followed by a punctuation character), this macro is called
8210: with a null pointer for @var{x} and the punctuation character for
8211: @var{code}.
8212:
8213: @item PRINT_OPERAND_ADDRESS (@var{stream}, @var{x})
8214: A C compound statement to output to stdio stream @var{stream} the
8215: assembler syntax for an instruction operand that is a memory reference
8216: whose address is @var{x}. @var{x} is an RTL expression.
8217:
8218: @item ASM_OPEN_PAREN
8219: @itemx ASM_CLOSE_PAREN
8220: These macros are defined as C string constant, describing the syntax
8221: in the assembler for grouping arithmetic expressions. The following
8222: definitions are correct for most assemblers:
8223:
8224: @example
8225: #define ASM_OPEN_PAREN "("
8226: #define ASM_CLOSE_PAREN ")"
8227: @end example
8228: @end table
8229:
8230: @node Config,, Machine Macros, Top
8231: @chapter The Configuration File
8232:
1.1.1.3 root 8233: The configuration file @file{xm-@var{machine}.h} contains macro definitions
8234: that describe the machine and system on which the compiler is running.
8235: Most of the values in it are actually the same on all machines that GNU CC
8236: runs on, so large parts of all configuration files are identical. But
1.1 root 8237: there are some macros that vary:
8238:
8239: @table @code
8240: @item FAILURE_EXIT_CODE
8241: A C expression for the status code to be returned when the compiler
8242: exits after serious errors.
8243:
8244: @item SUCCESS_EXIT_CODE
8245: A C expression for the status code to be returned when the compiler
8246: exits without serious errors.
8247: @end table
8248:
1.1.1.3 root 8249: In addition, configuration files for system V define @code{bcopy},
8250: @code{bzero} and @code{bcmp} as aliases. Some files define @code{alloca}
8251: as a macro when compiled with GNU CC, in order to take advantage of the
8252: benefit of GNU CC's built-in @code{alloca}.
8253:
1.1 root 8254: @contents
8255: @bye
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.