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