|
|
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:
1.1.1.10 root 9: Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.
1.1 root 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
1.1.1.9 root 24: sections entitled ``GNU General Public License'' and ``Protect Your
25: Freedom---Fight `Look And Feel'@w{}'' are included exactly as in the
26: original, and provided that the entire resulting derived work is
27: distributed under the terms of a permission notice identical to this
28: one.
1.1 root 29:
30: Permission is granted to copy and distribute translations of this manual
31: into another language, under the above conditions for modified versions,
1.1.1.9 root 32: except that the sections entitled ``GNU General Public License'' and
33: ``Protect Your Freedom---Fight `Look And Feel'@w{}'' and this permission
34: notice may be included in translations approved by the Free Software
35: Foundation instead of in the original English.
1.1 root 36: @end ifinfo
37:
38: @setchapternewpage odd
39:
40: @titlepage
41: @center @titlefont{Using and Porting GNU CC}
42: @sp 2
43: @center Richard M. Stallman
44: @sp 3
1.1.1.13! root 45: @center last updated 24 Aug 1992
1.1 root 46: @sp 1
1.1.1.13! root 47: @center for version 1.41
1.1 root 48: @page
49: @vskip 0pt plus 1filll
1.1.1.13! root 50: Copyright @copyright{} 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
1.1 root 51:
52: Permission is granted to make and distribute verbatim copies of
53: this manual provided the copyright notice and this permission notice
54: are preserved on all copies.
55:
56: Permission is granted to copy and distribute modified versions of this
57: manual under the conditions for verbatim copying, provided also that the
1.1.1.9 root 58: sections entitled ``GNU General Public License'' and ``Protect Your
59: Freedom---Fight `Look And Feel'@w{}'' are included exactly as in the
60: original, and provided that the entire resulting derived work is
61: distributed under the terms of a permission notice identical to this
62: one.
1.1 root 63:
64: Permission is granted to copy and distribute translations of this manual
65: into another language, under the above conditions for modified versions,
1.1.1.9 root 66: except that the sections entitled ``GNU General Public License'' and
67: ``Protect Your Freedom---Fight `Look And Feel'@w{}'' and this permission
68: notice may be included in translations approved by the Free Software
69: Foundation instead of in the original English.
1.1 root 70: @end titlepage
71: @page
72:
73: @ifinfo
74: @node Top, Copying,, (DIR)
75: @ichapter Introduction
76:
77: This manual documents how to run, install and port the GNU C compiler, as
78: well as its new features and incompatibilities, and how to report bugs.
79:
80: @end ifinfo
81: @menu
1.1.1.6 root 82: * Copying:: GNU General Public License says
1.1 root 83: how you can copy and share GNU CC.
84: * Contributors:: People who have contributed to GNU CC.
1.1.1.9 root 85: * Boycott:: Protect your freedom---fight ``look and feel''.
1.1 root 86: * Options:: Command options supported by @samp{gcc}.
87: * Installation:: How to configure, compile and install GNU CC.
88: * Trouble:: If you have trouble installing GNU CC.
1.1.1.10 root 89: * Service:: How to find suppliers of services for GNU CC users.
1.1 root 90: * Incompatibilities:: Incompatibilities of GNU CC.
91: * Extensions:: GNU extensions to the C language.
92: * Bugs:: How to report bugs (if you want to get them fixed).
93: * Portability:: Goals of GNU CC's portability features.
94: * Interface:: Function-call interface of GNU CC output.
95: * Passes:: Order of passes, what they do, and what each file is for.
96: * RTL:: The intermediate representation that most passes work on.
97: * Machine Desc:: How to write machine description instruction patterns.
98: * Machine Macros:: How to write the machine description C macros.
1.1.1.8 root 99: * Config:: Writing the @file{xm-@var{machine}.h} file.
1.1 root 100: @end menu
101:
102: @node Copying, Contributors, Top, Top
1.1.1.6 root 103: @unnumbered GNU GENERAL PUBLIC LICENSE
104: @center Version 1, February 1989
1.1 root 105:
1.1.1.6 root 106: @display
107: Copyright @copyright{} 1989 Free Software Foundation, Inc.
108: 675 Mass Ave, Cambridge, MA 02139, USA
109:
110: Everyone is permitted to copy and distribute verbatim copies
111: of this license document, but changing it is not allowed.
112: @end display
113:
114: @unnumberedsec Preamble
115:
116: The license agreements of most software companies try to keep users
117: at the mercy of those companies. By contrast, our General Public
118: License is intended to guarantee your freedom to share and change free
119: software---to make sure the software is free for all its users. The
120: General Public License applies to the Free Software Foundation's
121: software and to any other program whose authors commit to using it.
122: You can use it for your programs, too.
123:
124: When we speak of free software, we are referring to freedom, not
125: price. Specifically, the General Public License is designed to make
126: sure that you have the freedom to give away or sell copies of free
127: software, that you receive source code or can get it if you want it,
128: that you can change the software or use pieces of it in new free
129: programs; and that you know you can do these things.
130:
131: To protect your rights, we need to make restrictions that forbid
132: anyone to deny you these rights or to ask you to surrender the rights.
133: These restrictions translate to certain responsibilities for you if you
134: distribute copies of the software, or if you modify it.
135:
136: For example, if you distribute copies of a such a program, whether
137: gratis or for a fee, you must give the recipients all the rights that
138: you have. You must make sure that they, too, receive or can get the
1.1 root 139: source code. And you must tell them their rights.
140:
1.1.1.6 root 141: We protect your rights with two steps: (1) copyright the software, and
142: (2) offer you this license which gives you legal permission to copy,
143: distribute and/or modify the software.
144:
145: Also, for each author's protection and ours, we want to make certain
146: that everyone understands that there is no warranty for this free
147: software. If the software is modified by someone else and passed on, we
148: want its recipients to know that what they have is not the original, so
149: that any problems introduced by others will not reflect on the original
150: authors' reputations.
1.1 root 151:
1.1.1.6 root 152: The precise terms and conditions for copying, distribution and
153: modification follow.
1.1 root 154:
1.1.1.6 root 155: @iftex
156: @unnumberedsec TERMS AND CONDITIONS
157: @end iftex
158: @ifinfo
159: @center TERMS AND CONDITIONS
160: @end ifinfo
1.1 root 161:
1.1.1.6 root 162: @enumerate
1.1 root 163: @item
1.1.1.6 root 164: This License Agreement applies to any program or other work which
165: contains a notice placed by the copyright holder saying it may be
166: distributed under the terms of this General Public License. The
167: ``Program'', below, refers to any such program or work, and a ``work based
168: on the Program'' means either the Program or any work containing the
169: Program or a portion of it, either verbatim or with modifications. Each
170: licensee is addressed as ``you''.
171:
172: @item
173: You may copy and distribute verbatim copies of the Program's source
174: code as you receive it, in any medium, provided that you conspicuously and
175: appropriately publish on each copy an appropriate copyright notice and
176: disclaimer of warranty; keep intact all the notices that refer to this
177: General Public License and to the absence of any warranty; and give any
178: other recipients of the Program a copy of this General Public License
179: along with the Program. You may charge a fee for the physical act of
180: transferring a copy.
181:
182: @item
183: You may modify your copy or copies of the Program or any portion of
184: it, and copy and distribute such modifications under the terms of Paragraph
185: 1 above, provided that you also do the following:
1.1 root 186:
187: @itemize @bullet
188: @item
1.1.1.6 root 189: cause the modified files to carry prominent notices stating that
190: you changed the files and the date of any change; and
1.1 root 191:
192: @item
193: cause the whole of any work that you distribute or publish, that
1.1.1.6 root 194: in whole or in part contains the Program or any part thereof, either
195: with or without modifications, to be licensed at no charge to all
196: third parties under the terms of this General Public License (except
197: that you may choose to grant warranty protection to some or all
198: third parties, at your option).
199:
200: @item
201: If the modified program normally reads commands interactively when
202: run, you must cause it, when started running for such interactive use
203: in the simplest and most usual way, to print or display an
204: announcement including an appropriate copyright notice and a notice
205: that there is no warranty (or else, saying that you provide a
206: warranty) and that users may redistribute the program under these
207: conditions, and telling the user how to view a copy of this General
208: Public License.
209:
210: @item
211: You may charge a fee for the physical act of transferring a
212: copy, and you may at your option offer warranty protection in
213: exchange for a fee.
1.1 root 214: @end itemize
215:
1.1.1.6 root 216: Mere aggregation of another independent work with the Program (or its
1.1 root 217: derivative) on a volume of a storage or distribution medium does not bring
1.1.1.6 root 218: the other work under the scope of these terms.
1.1 root 219:
220: @item
1.1.1.6 root 221: You may copy and distribute the Program (or a portion or derivative of
222: it, under Paragraph 2) in object code or executable form under the terms of
223: Paragraphs 1 and 2 above provided that you also do one of the following:
1.1 root 224:
225: @itemize @bullet
226: @item
227: accompany it with the complete corresponding machine-readable
228: source code, which must be distributed under the terms of
229: Paragraphs 1 and 2 above; or,
230:
231: @item
232: accompany it with a written offer, valid for at least three
1.1.1.6 root 233: years, to give any third party free (except for a nominal charge
234: for the cost of distribution) a complete machine-readable copy of the
1.1 root 235: corresponding source code, to be distributed under the terms of
236: Paragraphs 1 and 2 above; or,
237:
238: @item
239: accompany it with the information you received as to where the
240: corresponding source code may be obtained. (This alternative is
241: allowed only for noncommercial distribution and only if you
242: received the program in object code or executable form alone.)
243: @end itemize
244:
1.1.1.6 root 245: Source code for a work means the preferred form of the work for making
246: modifications to it. For an executable file, complete source code means
247: all the source code for all modules it contains; but, as a special
248: exception, it need not include source code for modules which are standard
249: libraries that accompany the operating system on which the executable
250: file runs, or for standard header files or definitions files that
251: accompany that operating system.
252:
253: @item
254: You may not copy, modify, sublicense, distribute or transfer the
255: Program except as expressly provided under this General Public License.
256: Any attempt otherwise to copy, modify, sublicense, distribute or transfer
257: the Program is void, and will automatically terminate your rights to use
258: the Program under this License. However, parties who have received
259: copies, or rights to use copies, from you under this General Public
260: License will not have their licenses terminated so long as such parties
261: remain in full compliance.
262:
263: @item
264: By copying, distributing or modifying the Program (or any work based
265: on the Program) you indicate your acceptance of this license to do so,
266: and all its terms and conditions.
267:
268: @item
269: Each time you redistribute the Program (or any work based on the
270: Program), the recipient automatically receives a license from the original
271: licensor to copy, distribute or modify the Program subject to these
272: terms and conditions. You may not impose any further restrictions on the
273: recipients' exercise of the rights granted herein.
274:
275: @item
276: The Free Software Foundation may publish revised and/or new versions
277: of the General Public License from time to time. Such new versions will
278: be similar in spirit to the present version, but may differ in detail to
279: address new problems or concerns.
280:
281: Each version is given a distinguishing version number. If the Program
282: specifies a version number of the license which applies to it and ``any
283: later version'', you have the option of following the terms and conditions
284: either of that version or of any later version published by the Free
285: Software Foundation. If the Program does not specify a version number of
286: the license, you may choose any version ever published by the Free Software
287: Foundation.
288:
289: @item
290: If you wish to incorporate parts of the Program into other free
291: programs whose distribution conditions are different, write to the author
292: to ask for permission. For software which is copyrighted by the Free
293: Software Foundation, write to the Free Software Foundation; we sometimes
294: make exceptions for this. Our decision will be guided by the two goals
295: of preserving the free status of all derivatives of our free software and
296: of promoting the sharing and reuse of software generally.
297:
298: @iftex
299: @heading NO WARRANTY
300: @end iftex
301: @ifinfo
302: @center NO WARRANTY
303: @end ifinfo
304:
305: @item
306: BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
307: FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
308: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
309: PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
310: OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
311: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
312: TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
313: PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
314: REPAIR OR CORRECTION.
315:
316: @item
317: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
318: ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
319: REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
320: INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
321: ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
322: LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
323: SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
324: WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
325: ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
1.1 root 326: @end enumerate
327:
1.1.1.6 root 328: @iftex
329: @heading END OF TERMS AND CONDITIONS
330: @end iftex
331: @ifinfo
332: @center END OF TERMS AND CONDITIONS
333: @end ifinfo
334:
335: @page
336: @unnumberedsec Appendix: How to Apply These Terms to Your New Programs
337:
338: If you develop a new program, and you want it to be of the greatest
339: possible use to humanity, the best way to achieve this is to make it
340: free software which everyone can redistribute and change under these
341: terms.
342:
343: To do so, attach the following notices to the program. It is safest to
344: attach them to the start of each source file to most effectively convey
345: the exclusion of warranty; and each file should have at least the
346: ``copyright'' line and a pointer to where the full notice is found.
347:
348: @smallexample
349: @var{one line to give the program's name and a brief idea of what it does.}
350: Copyright (C) 19@var{yy} @var{name of author}
351:
352: This program is free software; you can redistribute it and/or modify
353: it under the terms of the GNU General Public License as published by
354: the Free Software Foundation; either version 1, or (at your option)
355: any later version.
356:
357: This program is distributed in the hope that it will be useful,
358: but WITHOUT ANY WARRANTY; without even the implied warranty of
359: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
360: GNU General Public License for more details.
361:
362: You should have received a copy of the GNU General Public License
363: along with this program; if not, write to the Free Software
364: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
365: @end smallexample
366:
367: Also add information on how to contact you by electronic and paper mail.
368:
369: If the program is interactive, make it output a short notice like this
370: when it starts in an interactive mode:
371:
372: @smallexample
373: Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
374: Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
375: This is free software, and you are welcome to redistribute it
376: under certain conditions; type `show c' for details.
377: @end smallexample
378:
379: The hypothetical commands `show w' and `show c' should show the
380: appropriate parts of the General Public License. Of course, the
381: commands you use may be called something other than `show w' and `show
382: c'; they could even be mouse-clicks or menu items---whatever suits your
383: program.
384:
385: You should also get your employer (if you work as a programmer) or your
386: school, if any, to sign a ``copyright disclaimer'' for the program, if
387: necessary. Here a sample; alter the names:
388:
389: @example
390: Yoyodyne, Inc., hereby disclaims all copyright interest in the
391: program `Gnomovision' (a program to direct compilers to make passes
392: at assemblers) written by James Hacker.
393:
394: @var{signature of Ty Coon}, 1 April 1989
395: Ty Coon, President of Vice
396: @end example
397:
398: That's all there is to it!
1.1 root 399:
1.1.1.9 root 400: @node Contributors, Boycott, Copying, Top
1.1 root 401: @unnumbered Contributors to GNU CC
402:
403: In addition to Richard Stallman, several people have written parts
404: of GNU CC.
405:
406: @itemize @bullet
407: @item
408: The idea of using RTL and some of the optimization ideas came from the
409: U. of Arizona Portable Optimizer, written by Jack Davidson and
410: Christopher Fraser. See ``Register Allocation and Exhaustive Peephole
411: Optimization'', Software Practice and Experience 14 (9), Sept. 1984,
412: 857-866.
413:
414: @item
415: Paul Rubin wrote most of the preprocessor.
416:
417: @item
1.1.1.6 root 418: Leonard Tower wrote parts of the parser, RTL generator, and RTL
1.1 root 419: definitions, and of the Vax machine description.
420:
421: @item
422: Ted Lemon wrote parts of the RTL reader and printer.
423:
424: @item
425: Jim Wilson implemented loop strength reduction and some other
426: loop optimizations.
427:
428: @item
429: Nobuyuki Hikichi of Software Research Associates, Tokyo, contributed
1.1.1.8 root 430: the support for the Sony NEWS machine.
1.1 root 431:
432: @item
433: Charles LaBrec contributed the support for the Integrated Solutions
434: 68020 system.
435:
436: @item
437: Michael Tiemann of MCC wrote most of the description of the National
438: Semiconductor 32000 series cpu. He also wrote the code for inline
439: function integration and for the SPARC cpu and Motorola 88000 cpu
440: and part of the Sun FPA support.
441:
442: @item
443: Jan Stein of the Chalmers Computer Society provided support for
444: Genix, as well as part of the 32000 machine description.
445:
446: @item
447: Randy Smith finished the Sun FPA support.
448:
449: @item
450: Robert Brown implemented the support for Encore 32000 systems.
451:
452: @item
453: David Kashtan of SRI adapted GNU CC to the Vomit-Making System.
454:
455: @item
456: Alex Crain provided changes for the 3b1.
457:
458: @item
459: Greg Satz and Chris Hanson assisted in making GNU CC work on HP-UX for
460: the 9000 series 300.
461:
462: @item
463: William Schelter did most of the work on the Intel 80386 support.
1.1.1.5 root 464:
465: @item
466: Christopher Smith did the port for Convex machines.
467:
468: @item
469: Paul Petersen wrote the machine description for the Alliant FX/8.
1.1.1.7 root 470:
471: @item
1.1.1.8 root 472: Alain Lichnewsky ported GNU CC to the Mips cpu.
473:
474: @item
475: Devon Bowen, Dale Wiles and Kevin Zachmann ported GNU CC to the Tahoe.
476:
477: @item
478: Jonathan Stone wrote the machine description for the Pyramid computer.
1.1 root 479: @end itemize
480:
1.1.1.9 root 481: @node Boycott, Options, Contributors, Top
482: @chapter Protect Your Freedom---Fight ``Look And Feel''
483:
1.1.1.10 root 484: @quotation
485: @i{This section is a political message from the League for Programming
486: Freedom to the users of GNU CC. It is included here as an expression
487: of support for the League on the part of the Free Software Foundation
488: and Richard Stallman.}
489: @end quotation
490:
1.1.1.9 root 491: Ashton-Tate, Apple, Lotus and Xerox are trying to create a new form of
492: legal monopoly: a copyright on a class of user interfaces. These
493: monopolies would cause serious problems for users and developers of
494: computer software and systems.
495:
1.1.1.10 root 496: Until a few years ago, the law seemed clear: no one could restrict
1.1.1.9 root 497: others from using a user interface; programmers were free to implement
498: any interface they chose. Imitating interfaces, sometimes with changes,
499: was standard practice in the computer field. The interfaces we know
500: evolved gradually in this way; for example, the Macintosh user interface
501: drew ideas from the Xerox interface, which in turn drew on work done at
1.1.1.10 root 502: Stanford and SRI. 1-2-3 imitated VisiCalc, and dBase imitated a
503: database program from JPL.
1.1.1.9 root 504:
505: Most computer companies, and nearly all computer users, were happy with
506: this state of affairs. The companies that are suing say it does not
507: offer ``enough incentive'' to develop their products, but they must have
508: considered it ``enough'' when they made their decision to do so. It
509: seems they are not satisfied with the opportunity to continue to compete
510: in the marketplace---not even with a head start.
511:
512: If Xerox, Lotus, Apple and Ashton-Tate are permitted to make law through
513: the courts, the precedent will hobble the software industry:
514:
515: @itemize @bullet
516: @item
1.1.1.11 root 517: Gratuitous incompatibilities will burden users. Imagine if each
1.1.1.9 root 518: car manufacturer had to arrange the pedals in a different order.
519:
520: @item
521: Software will become and remain more expensive. Users will be
522: ``locked in'' to proprietary interfaces, for which there is no real
523: competition.
524:
525: @item
526: Large companies have an unfair advantage wherever lawsuits become
527: commonplace. Since they can easily afford to sue, they can intimidate
528: small companies with threats even when they don't really have a case.
529:
530: @item
531: User interface improvements will come slower, since incremental
532: evolution through creative imitation will no longer be permitted.
533:
534: @item
535: Even Apple, etc., will find it harder to make improvements if
536: they can no longer adapt the good ideas that others introduce, for
537: fear of weakening their own legal positions. Some users suggest that
538: this stagnation may already have started.
1.1.1.10 root 539:
540: @item
541: If you use GNU software, you might find it of some concern that user
542: interface copyright will make it hard for the Free Software Foundation
543: to develop programs compatible with the interfaces that you already
544: know.
1.1.1.9 root 545: @end itemize
546:
1.1.1.10 root 547: To protect our freedom from lawsuits like these, a group of programmers
548: and users have formed a new grass-roots political organization, the
549: League for Programming Freedom.
550:
551: The purpose of the League is to oppose new monopolistic practices such
552: as user-interface copyright and software patents; it calls for a return
553: to the legal policies of the recent past, in which these practices were
554: not allowed. The League is not concerned with free software as an
555: issue, and not affiliated with the Free Software Foundation.
556:
557: The League's membership rolls include John McCarthy, inventor of Lisp,
558: Marvin Minsky, founder of the Artificial Intelligence lab, Guy L.
559: Steele, Jr., author of well-known books on Lisp and C, as well as
560: Richard Stallman, the developer of GNU CC. Please join and add your
561: name to the list. Membership dues in the League are $42 per year for
562: programmers, managers and professionals; $10.50 for students; $21 for
563: others.
564:
565: The League needs both activist members and members who only pay their
566: dues.
567:
568: To join, or for more information, phone (617) 492-0023 or write to:
569:
570: @example
571: League for Programming Freedom
572: 1 Kendall Square #143
573: P.O. Box 9171
574: Cambridge, MA 02139 league@@prep.ai.mit.edu
575: @end example
576:
577: Here are some suggestions from the League for how you can protect your
578: freedom to write programs:
1.1.1.9 root 579:
580: @itemize @bullet
581: @item
582: Don't buy from Xerox, Lotus, Apple or Ashton-Tate. Buy from their
583: competitors or from the defendants they are suing.
584:
585: @item
586: Don't develop software to work with the systems made by these companies.
587:
588: @item
589: Port your existing software to competing systems, so that you encourage
590: users to switch.
591:
592: @item
593: Write letters to company presidents to let them know their conduct
594: is unacceptable.
595:
596: @item
597: Tell your friends and colleagues about this issue and how it threatens
598: to ruin the computer industry.
599:
600: @item
601: Above all, don't work for the look-and-feel plaintiffs, and don't
602: accept contracts from them.
603:
604: @item
1.1.1.11 root 605: Write to Congress to explain the importance of this issue.
1.1.1.9 root 606:
607: @example
1.1.1.11 root 608: House Subcommittee on Intellectual Property
609: 2137 Rayburn Bldg
610: Washington, DC 20515
1.1.1.9 root 611:
1.1.1.11 root 612: Senate Subcommittee on Patents, Trademarks and Copyrights
613: United States Senate
614: Washington, DC 20510
615: @end example
1.1.1.9 root 616: @end itemize
617:
618: Express your opinion! You can make a difference.
619:
620: @node Options, Installation, Boycott, Top
1.1 root 621: @chapter GNU CC Command Options
622:
623: The GNU C compiler uses a command syntax much like the Unix C compiler.
624: The @code{gcc} program accepts options and file names as operands.
625: Multiple single-letter options may @emph{not} be grouped: @samp{-dr} is
1.1.1.8 root 626: very different from @w{@samp{-d -r}}.
1.1 root 627:
628: When you invoke GNU CC, it normally does preprocessing, compilation,
629: assembly and linking. File names which end in @samp{.c} are taken as C
1.1.1.5 root 630: source to be preprocessed and compiled; file names ending in @samp{.i}
631: are taken as preprocessor output to be compiled; compiler output files
632: plus any input files with names ending in @samp{.s} are assembled; then
633: the resulting object files, plus any other input files, are linked
634: together to produce an executable.
1.1 root 635:
636: Command options allow you to stop this process at an intermediate stage.
637: For example, the @samp{-c} option says not to run the linker. Then the
638: output consists of object files output by the assembler.
639:
1.1.1.5 root 640: Other command options are passed on to one stage of processing. Some
641: options control the preprocessor and others the compiler itself. Yet
642: other options control the assembler and linker; these are not documented
643: here, but you rarely need to use any of them.
1.1 root 644:
645: Here are the options to control the overall compilation process, including
646: those that say whether to link, whether to assemble, and so on.
647:
648: @table @samp
649: @item -o @var{file}
650: Place output in file @var{file}. This applies regardless to whatever
651: sort of output is being produced, whether it be an executable file,
652: an object file, an assembler file or preprocessed C code.
653:
654: If @samp{-o} is not specified, the default is to put an executable file
655: in @file{a.out}, the object file @file{@var{source}.c} in
656: @file{@var{source}.o}, an assembler file in @file{@var{source}.s}, and
657: preprocessed C on standard output.@refill
658:
659: @item -c
660: Compile or assemble the source files, but do not link. Produce object
661: files with names made by replacing @samp{.c} or @samp{.s} with
662: @samp{.o} at the end of the input file names. Do nothing at all for
663: object files specified as input.
664:
665: @item -S
666: Compile into assembler code but do not assemble. The assembler output
667: file name is made by replacing @samp{.c} with @samp{.s} at the end of
668: the input file name. Do nothing at all for assembler source files or
669: object files specified as input.
670:
671: @item -E
672: Run only the C preprocessor. Preprocess all the C source files
673: specified and output the results to standard output.
674:
675: @item -v
676: Compiler driver program prints the commands it executes as it runs
677: the preprocessor, compiler proper, assembler and linker. Some of
678: these are directed to print their own version numbers.
679:
1.1.1.5 root 680: @item -pipe
681: Use pipes rather than temporary files for communication between the
682: various stages of compilation. This fails to work on some systems
683: where the assembler is unable to read from a pipe; but the GNU
684: assembler has no trouble.
685:
1.1 root 686: @item -B@var{prefix}
687: Compiler driver program tries @var{prefix} as a prefix for each
688: program it tries to run. These programs are @file{cpp}, @file{cc1},
689: @file{as} and @file{ld}.
690:
691: For each subprogram to be run, the compiler driver first tries the
692: @samp{-B} prefix, if any. If that name is not found, or if @samp{-B}
693: was not specified, the driver tries two standard prefixes, which are
694: @file{/usr/lib/gcc-} and @file{/usr/local/lib/gcc-}. If neither of
695: those results in a file name that is found, the unmodified program
696: name is searched for using the directories specified in your
697: @samp{PATH} environment variable.
698:
699: The run-time support file @file{gnulib} is also searched for using
700: the @samp{-B} prefix, if needed. If it is not found there, the two
701: standard prefixes above are tried, and that is all. The file is left
702: out of the link if it is not found by those means. Most of the time,
703: on most machines, you can do without it.
1.1.1.5 root 704:
705: You can get a similar result from the environment variable;
706: @code{GCC_EXEC_PREFIX} if it is defined, its value is used as a prefix
707: in the same way. If both the @samp{-B} option and the
708: @code{GCC_EXEC_PREFIX} variable are present, the @samp{-B} option is
709: used first and the environment variable value second.
1.1.1.8 root 710:
711: @item -b@var{prefix}
712: The argument @var{prefix} is used as a second prefix for the compiler
713: executables and libraries. This prefix is optional: the compiler tries
714: each file first with it, then without it. This prefix follows the
715: prefix specified with @samp{-B} or the default prefixes.
716:
717: Thus, @samp{-bvax- -Bcc/} in the presence of environment variable
718: @code{GCC_EXEC_PREFIX} with definition @file{/u/foo/} causes GNU CC to
719: try the following file names for the preprocessor executable:
720:
721: @example
722: cc/vax-cpp
723: cc/cpp
724: /u/foo/vax-cpp
725: /u/foo/cpp
726: /usr/local/lib/gcc-vax-cpp
727: /usr/local/lib/gcc-cpp
728: /usr/lib/gcc-vax-cpp
729: /usr/lib/gcc-cpp
730: @end example
1.1 root 731: @end table
732:
733: These options control the details of C compilation itself.
734:
735: @table @samp
736: @item -ansi
737: Support all ANSI standard C programs.
738:
739: This turns off certain features of GNU C that are incompatible with
740: ANSI C, such as the @code{asm}, @code{inline} and @code{typeof}
741: keywords, and predefined macros such as @code{unix} and @code{vax}
742: that identify the type of system you are using. It also enables the
743: undesirable and rarely used ANSI trigraph feature.
744:
1.1.1.8 root 745: The alternate keywords @code{__asm__}, @code{__inline__} and
746: @code{__typeof__} continue to work despite @samp{-ansi}. You would not
1.1.1.7 root 747: want to use them in an ANSI C program, of course, but it useful to put
748: them in header files that might be included in compilations done with
1.1.1.8 root 749: @samp{-ansi}. Alternate predefined macros such as @code{__unix__} and
750: @code{__vax__} are also available, with or without @samp{-ansi}.
1.1.1.7 root 751:
1.1 root 752: The @samp{-ansi} option does not cause non-ANSI programs to be
753: rejected gratuitously. For that, @samp{-pedantic} is required in
754: addition to @samp{-ansi}.
755:
756: The macro @code{__STRICT_ANSI__} is predefined when the @samp{-ansi}
757: option is used. Some header files may notice this macro and refrain
758: from declaring certain functions or defining certain macros that the
1.1.1.7 root 759: ANSI standard doesn't call for; this is to avoid interfering with any
760: programs that might use these names for other things.
1.1 root 761:
762: @item -traditional
763: Attempt to support some aspects of traditional C compilers.
764: Specifically:
765:
766: @itemize @bullet
767: @item
768: All @code{extern} declarations take effect globally even if they
769: are written inside of a function definition. This includes implicit
770: declarations of functions.
771:
772: @item
773: The keywords @code{typeof}, @code{inline}, @code{signed}, @code{const}
1.1.1.10 root 774: and @code{volatile} are not recognized. (You can still use the alternative
775: keywords such as @code{__typeof__}, @code{__inline__}, and so on.)
1.1 root 776:
777: @item
778: Comparisons between pointers and integers are always allowed.
779:
780: @item
781: Integer types @code{unsigned short} and @code{unsigned char} promote
782: to @code{unsigned int}.
783:
784: @item
785: Out-of-range floating point literals are not an error.
786:
787: @item
1.1.1.8 root 788: String ``constants'' are not necessarily constant; they are stored in
789: writable space, and identical looking constants are allocated
790: separately.
791:
792: @item
1.1.1.2 root 793: All automatic variables not declared @code{register} are preserved by
794: @code{longjmp}. Ordinarily, GNU C follows ANSI C: automatic variables
795: not declared @code{volatile} may be clobbered.
796:
797: @item
1.1 root 798: In the preprocessor, comments convert to nothing at all, rather than
799: to a space. This allows traditional token concatenation.
800:
801: @item
802: In the preprocessor, macro arguments are recognized within string
803: constants in a macro definition (and their values are stringified,
804: though without additional quote marks, when they appear in such a
805: context). The preprocessor always considers a string constant to end
806: at a newline.
807:
808: @item
809: The predefined macro @code{__STDC__} is not defined when you use
810: @samp{-traditional}, but @code{__GNUC__} is (since the GNU extensions
811: which @code{__GNUC__} indicates are not affected by
812: @samp{-traditional}). If you need to write header files that work
813: differently depending on whether @samp{-traditional} is in use, by
814: testing both of these predefined macros you can distinguish four
815: situations: GNU C, traditional GNU C, other ANSI C compilers, and
816: other old C compilers.
817: @end itemize
818:
819: @item -O
820: Optimize. Optimizing compilation takes somewhat more time, and a lot
821: more memory for a large function.
822:
823: Without @samp{-O}, the compiler's goal is to reduce the cost of
824: compilation and to make debugging produce the expected results.
825: Statements are independent: if you stop the program with a breakpoint
826: between statements, you can then assign a new value to any variable or
827: change the program counter to any other statement in the function and
828: get exactly the results you would expect from the source code.
829:
830: Without @samp{-O}, only variables declared @code{register} are
831: allocated in registers. The resulting compiled code is a little worse
832: than produced by PCC without @samp{-O}.
833:
834: With @samp{-O}, the compiler tries to reduce code size and execution
835: time.
836:
837: Some of the @samp{-f} options described below turn specific kinds of
838: optimization on or off.
839:
840: @item -g
841: Produce debugging information in the operating system's native format
842: (for DBX or SDB). GDB also can work with this debugging information.
843:
844: Unlike most other C compilers, GNU CC allows you to use @samp{-g} with
845: @samp{-O}. The shortcuts taken by optimized code may occasionally
846: produce surprising results: some variables you declared may not exist
847: at all; flow of control may briefly move where you did not expect it;
848: some statements may not be executed because they compute constant
849: results or their values were already at hand; some statements may
850: execute in different places because they were moved out of loops.
851: Nevertheless it proves possible to debug optimized output. This makes
852: it reasonable to use the optimizer for programs that might have bugs.
853:
854: @item -gg
1.1.1.8 root 855: Produce debugging information in the old GDB format. This is obsolete.
1.1 root 856:
857: @item -w
858: Inhibit all warning messages.
859:
860: @item -W
861: Print extra warning messages for these events:
862:
863: @itemize @bullet
864: @item
865: An automatic variable is used without first being initialized.
866:
867: These warnings are possible only in optimizing compilation,
868: because they require data flow information that is computed only
1.1.1.6 root 869: when optimizing. If you don't specify @samp{-O}, you simply won't
870: get these warnings.
871:
872: These warnings occur only for variables that are candidates for
873: register allocation. Therefore, they do not occur for a variable that
874: is declared @code{volatile}, or whose address is taken, or whose size
875: is other than 1, 2, 4 or 8 bytes. Also, they do not occur for
876: structures, unions or arrays, even when they are in registers.
877:
878: Note that there may be no warning about a variable that is used only
879: to compute a value that itself is never used, because such
880: computations may be deleted by data flow analysis before the warnings
881: are printed.
1.1 root 882:
883: These warnings are made optional because GNU CC is not smart
884: enough to see all the reasons why the code might be correct
885: despite appearing to have an error. Here is one example of how
886: this can happen:
887:
888: @example
889: @{
890: int x;
891: switch (y)
892: @{
893: case 1: x = 1;
894: break;
895: case 2: x = 4;
896: break;
897: case 3: x = 5;
898: @}
899: foo (x);
900: @}
901: @end example
902:
903: @noindent
904: If the value of @code{y} is always 1, 2 or 3, then @code{x} is
905: always initialized, but GNU CC doesn't know this. Here is
906: another common case:
907:
908: @example
909: @{
910: int save_y;
911: if (change_y) save_y = y, y = new_y;
912: @dots{}
913: if (change_y) y = save_y;
914: @}
915: @end example
916:
917: @noindent
918: This has no bug because @code{save_y} is used only if it is set.
919:
1.1.1.5 root 920: Some spurious warnings can be avoided if you declare as
921: @code{volatile} all the functions you use that never return.
922: @xref{Function Attributes}.
923:
1.1 root 924: @item
925: A nonvolatile automatic variable might be changed by a call to
926: @code{longjmp}. These warnings as well are possible only in
927: optimizing compilation.
928:
929: The compiler sees only the calls to @code{setjmp}. It cannot know
930: where @code{longjmp} will be called; in fact, a signal handler could
931: call it at any point in the code. As a result, you may get a warning
932: even when there is in fact no problem because @code{longjmp} cannot
933: in fact be called at the place which would cause a problem.
934:
935: @item
936: A function can return either with or without a value. (Falling
937: off the end of the function body is considered returning without
1.1.1.6 root 938: a value.) For example, this function would evoke such a
1.1 root 939: warning:
940:
941: @example
942: foo (a)
943: @{
944: if (a > 0)
945: return a;
946: @}
947: @end example
948:
949: Spurious warnings can occur because GNU CC does not realize that
950: certain functions (including @code{abort} and @code{longjmp})
951: will never return.
1.1.1.4 root 952:
953: @item
954: An expression-statement contains no side effects.
1.1 root 955: @end itemize
956:
957: In the future, other useful warnings may also be enabled by this
958: option.
959:
960: @item -Wimplicit
961: Warn whenever a function is implicitly declared.
962:
963: @item -Wreturn-type
964: Warn whenever a function is defined with a return-type that defaults
965: to @code{int}. Also warn about any @code{return} statement with no
966: return-value in a function whose return-type is not @code{void}.
967:
968: @item -Wunused
1.1.1.5 root 969: Warn whenever a local variable is unused aside from its declaration,
1.1.1.8 root 970: whenever a function is declared static but never defined, and whenever
971: a statement computes a result that is explicitly not used.
1.1.1.7 root 972:
973: @item -Wswitch
974: Warn whenever a @code{switch} statement has an index of enumeral type
975: and lacks a @code{case} for one or more of the named codes of that
976: enumeration. (The presence of a @code{default} label prevents this
977: warning.) @code{case} labels outside the enumeration range also
978: provoke warnings when this option is used.
979:
1.1 root 980: @item -Wcomment
981: Warn whenever a comment-start sequence @samp{/*} appears in a comment.
982:
1.1.1.7 root 983: @item -Wtrigraphs
984: Warn if any trigraphs are encountered (assuming they are enabled).
985:
1.1 root 986: @item -Wall
1.1.1.8 root 987: All of the above @samp{-W} options combined. These are all the
988: options which pertain to usage that we recommend avoiding and that we
989: believe is easy to avoid, even in conjunction with macros.
990:
991: The other @samp{-W@dots{}} options below are not implied by @samp{-Wall}
992: because certain kinds of useful macros are almost impossible to write
993: without causing those warnings.
994:
995: @item -Wshadow
996: Warn whenever a local variable shadows another local variable.
997:
998: @item -Wid-clash-@var{len}
999: Warn whenever two distinct identifiers match in the first @var{len}
1000: characters. This may help you prepare a program that will compile
1001: with certain obsolete, brain-damaged compilers.
1002:
1003: @item -Wpointer-arith
1004: Warn about anything that depends on the ``size of'' a function type or
1005: of @code{void}. GNU C assigns these types a size of 1, for
1006: convenience in calculations with @code{void *} pointers and pointers
1007: to functions.
1.1 root 1008:
1.1.1.6 root 1009: @item -Wcast-qual
1010: Warn whenever a pointer is cast so as to remove a type qualifier from
1011: the target type. For example, warn if a @code{const char *} is cast
1012: to an ordinary @code{char *}.
1013:
1.1 root 1014: @item -Wwrite-strings
1015: Give string constants the type @code{const char[@var{length}]} so that
1016: copying the address of one into a non-@code{const} @code{char *}
1017: pointer will get a warning. These warnings will help you find at
1018: compile time code that can try to write into a string constant, but
1019: only if you have been very careful about using @code{const} in
1020: declarations and prototypes. Otherwise, it will just be a nuisance;
1021: this is why we did not make @samp{-Wall} request these warnings.
1022:
1023: @item -p
1024: Generate extra code to write profile information suitable for the
1025: analysis program @code{prof}.
1026:
1027: @item -pg
1028: Generate extra code to write profile information suitable for the
1029: analysis program @code{gprof}.
1030:
1.1.1.6 root 1031: @item -a
1.1.1.8 root 1032: Generate extra code to write profile information for basic blocks, which
1033: will record the number of times each basic block is executed. This data
1034: could be analyzed by a program like @code{tcov}. Note, however, that
1035: the format of the data is not what @code{tcov} expects. Eventually GNU
1.1.1.6 root 1036: @code{gprof} should be extended to process this data.
1037:
1.1 root 1038: @item -l@var{library}
1039: Search a standard list of directories for a library named
1040: @var{library}, which is actually a file named
1041: @file{lib@var{library}.a}. The linker uses this file as if it
1042: had been specified precisely by name.
1043:
1044: The directories searched include several standard system directories
1045: plus any that you specify with @samp{-L}.
1046:
1047: Normally the files found this way are library files---archive files
1048: whose members are object files. The linker handles an archive file by
1049: scanning through it for members which define symbols that have so far
1050: been referenced but not defined. But if the file that is found is an
1051: ordinary object file, it is linked in the usual fashion. The only
1052: difference between using an @samp{-l} option and specifying a file name
1053: is that @samp{-l} searches several directories.
1054:
1055: @item -L@var{dir}
1056: Add directory @var{dir} to the list of directories to be searched
1057: for @samp{-l}.
1058:
1059: @item -nostdlib
1.1.1.9 root 1060: Don't use the standard system libraries and startup files when linking.
1061: Only the files you specify will be passed to the linker.
1.1 root 1062:
1063: @item -m@var{machinespec}
1064: Machine-dependent option specifying something about the type of target
1065: machine. These options are defined by the macro
1066: @code{TARGET_SWITCHES} in the machine description. The default for
1067: the options is also defined by that macro, which enables you to change
1068: the defaults.@refill
1069:
1070: These are the @samp{-m} options defined in the 68000 machine
1071: description:
1072:
1073: @table @samp
1074: @item -m68020
1075: @itemx -mc68020
1076: Generate output for a 68020 (rather than a 68000). This is the
1077: default if you use the unmodified sources.
1078:
1079: @item -m68000
1080: @item -mc68000
1081: Generate output for a 68000 (rather than a 68020).
1082:
1083: @item -m68881
1084: Generate output containing 68881 instructions for floating point.
1085: This is the default if you use the unmodified sources.
1086:
1087: @item -mfpa
1088: Generate output containing Sun FPA instructions for floating point.
1089:
1090: @item -msoft-float
1091: Generate output containing library calls for floating point.
1092:
1093: @item -mshort
1094: Consider type @code{int} to be 16 bits wide, like @code{short int}.
1095:
1096: @item -mnobitfield
1097: Do not use the bit-field instructions. @samp{-m68000} implies
1098: @samp{-mnobitfield}.
1099:
1100: @item -mbitfield
1101: Do use the bit-field instructions. @samp{-m68020} implies
1102: @samp{-mbitfield}. This is the default if you use the unmodified
1103: sources.
1104:
1105: @item -mrtd
1106: Use a different function-calling convention, in which functions
1107: that take a fixed number of arguments return with the @code{rtd}
1108: instruction, which pops their arguments while returning. This
1109: saves one instruction in the caller since there is no need to pop
1110: the arguments there.
1111:
1112: This calling convention is incompatible with the one normally
1113: used on Unix, so you cannot use it if you need to call libraries
1114: compiled with the Unix compiler.
1115:
1116: Also, you must provide function prototypes for all functions that
1117: take variable numbers of arguments (including @code{printf});
1118: otherwise incorrect code will be generated for calls to those
1119: functions.
1120:
1121: In addition, seriously incorrect code will result if you call a
1122: function with too many arguments. (Normally, extra arguments are
1123: harmlessly ignored.)
1124:
1125: The @code{rtd} instruction is supported by the 68010 and 68020
1126: processors, but not by the 68000.
1127: @end table
1128:
1129: These @samp{-m} options are defined in the Vax machine description:
1130:
1131: @table @samp
1132: @item -munix
1133: Do not output certain jump instructions (@code{aobleq} and so on)
1134: that the Unix assembler for the Vax cannot handle across long
1135: ranges.
1136:
1137: @item -mgnu
1138: Do output those jump instructions, on the assumption that you
1139: will assemble with the GNU assembler.
1140:
1141: @item -mg
1142: Output code for g-format floating point numbers instead of d-format.
1143: @end table
1144:
1.1.1.5 root 1145: These @samp{-m} switches are supported on the Sparc:
1146:
1147: @table @samp
1148: @item -mfpu
1149: Generate output containing floating point instructions. This is the
1150: default if you use the unmodified sources.
1151:
1.1.1.9 root 1152: @ignore
1.1.1.5 root 1153: @item -msoft-float
1154: Generate output containing library calls for floating point.
1155:
1.1.1.9 root 1156: @end ignore
1.1.1.5 root 1157: @item -mno-epilogue
1.1.1.6 root 1158: Generate separate return instructions for @code{return} statements.
1159: This has both advantages and disadvantages; I don't recall what they
1160: are.
1.1.1.5 root 1161: @end table
1162:
1163: These @samp{-m} options are defined in the Convex machine description:
1164:
1165: @table @samp
1166: @item -mc1
1167: Generate output for a C1. This is the default when the compiler is
1168: configured for a C1.
1169:
1170: @item -mc2
1171: Generate output for a C2. This is the default when the compiler is
1172: configured for a C2.
1173:
1174: @item -margcount
1175: Generate code which puts an argument count in the word preceding each
1176: argument list. Some nonportable Convex and Vax programs need this
1177: word. (Debuggers don't; this info is in the symbol table.)
1178:
1179: @item -mnoargcount
1180: Omit the argument count word. This is the default if you use the
1181: unmodified sources.
1182: @end table
1183:
1.1 root 1184: @item -f@var{flag}
1.1.1.4 root 1185: Specify machine-independent flags. Most flags have both positive and
1186: negative forms; the negative form of @samp{-ffoo} would be
1187: @samp{-fno-foo}. In the table below, only one of the forms is
1188: listed---the one which is not the default. You can figure out the
1189: other form by either removing @samp{no-} or adding it.
1.1 root 1190:
1191: @table @samp
1.1.1.6 root 1192: @item -fpcc-struct-return
1193: Use the same convention for returning @code{struct} and @code{union}
1194: values that is used by the usual C compiler on your system. This
1195: convention is less efficient for small structures, and on many
1196: machines it fails to be reentrant; but it has the advantage of
1197: allowing intercallability between GCC-compiled code and PCC-compiled
1198: code.
1199:
1.1 root 1200: @item -ffloat-store
1201: Do not store floating-point variables in registers. This
1202: prevents undesirable excess precision on machines such as the
1203: 68000 where the floating registers (of the 68881) keep more
1204: precision than a @code{double} is supposed to have.
1205:
1206: For most programs, the excess precision does only good, but a few
1207: programs rely on the precise definition of IEEE floating point.
1208: Use @samp{-ffloat-store} for such programs.
1209:
1210: @item -fno-asm
1211: Do not recognize @code{asm}, @code{inline} or @code{typeof} as a
1.1.1.7 root 1212: keyword. These words may then be used as identifiers. You can
1.1.1.8 root 1213: use @code{__asm__}, @code{__inline__} and @code{__typeof__} instead.
1.1 root 1214:
1215: @item -fno-defer-pop
1216: Always pop the arguments to each function call as soon as that
1217: function returns. Normally the compiler (when optimizing) lets
1218: arguments accumulate on the stack for several function calls and
1219: pops them all at once.
1220:
1221: @item -fstrength-reduce
1222: Perform the optimizations of loop strength reduction and
1223: elimination of iteration variables.
1224:
1225: @item -fcombine-regs
1226: Allow the combine pass to combine an instruction that copies one
1227: register into another. This might or might not produce better
1228: code when used in addition to @samp{-O}. I am interested in
1229: hearing about the difference this makes.
1230:
1231: @item -fforce-mem
1232: Force memory operands to be copied into registers before doing
1233: arithmetic on them. This may produce better code by making all
1234: memory references potential common subexpressions. When they are
1235: not common subexpressions, instruction combination should
1236: eliminate the separate register-load. I am interested in hearing
1237: about the difference this makes.
1238:
1239: @item -fforce-addr
1240: Force memory address constants to be copied into registers before
1241: doing arithmetic on them. This may produce better code just as
1242: @samp{-fforce-mem} may. I am interested in hearing about the
1243: difference this makes.
1244:
1245: @item -fomit-frame-pointer
1246: Don't keep the frame pointer in a register for functions that
1247: don't need one. This avoids the instructions to save, set up and
1248: restore frame pointers; it also makes an extra register available
1249: in many functions. @strong{It also makes debugging impossible.}
1250:
1251: On some machines, such as the Vax, this flag has no effect,
1252: because the standard calling sequence automatically handles the
1253: frame pointer and nothing is saved by pretending it doesn't
1254: exist. The machine-description macro
1255: @code{FRAME_POINTER_REQUIRED} controls whether a target machine
1256: supports this flag. @xref{Registers}.@refill
1257:
1258: @item -finline-functions
1259: Integrate all simple functions into their callers. The compiler
1260: heuristically decides which functions are simple enough to be
1261: worth integrating in this way.
1262:
1263: If all calls to a given function are integrated, and the function
1264: is declared @code{static}, then the function is normally not
1265: output as assembler code in its own right.
1266:
1.1.1.6 root 1267: @item -fcaller-saves
1268: Enable values to be allocated in registers that will be clobbered by
1269: function calls, by emitting extra instructions to save and restore the
1270: registers around such calls. Such allocation is done only when it
1271: seems to result in better code than would otherwise be produced.
1272:
1273: This option is enabled by default on certain machines, usually those
1274: which have no call-preserved registers to use instead.
1275:
1.1.1.13! root 1276: Don't use @samp{-fcaller-saves} together with
! 1277: @samp{-fomit-frame-pointer}. This combination does not work.
! 1278:
1.1 root 1279: @item -fkeep-inline-functions
1280: Even if all calls to a given function are integrated, and the
1281: function is declared @code{static}, nevertheless output a
1282: separate run-time callable version of the function.
1283:
1284: @item -fwritable-strings
1.1.1.8 root 1285: Store string constants in the writable data segment and don't uniquize
1286: them. This is for compatibility with old programs which assume they can
1287: write into string constants. @samp{-traditional} also has this effect.
1288:
1289: Writing into string constants is a very bad idea; ``constants'' should
1290: be constant.
1.1 root 1291:
1.1.1.4 root 1292: @item -fcond-mismatch
1293: Allow conditional expressions with mismatched types in the second and
1294: third arguments. The value of such an expression is void.
1295:
1.1 root 1296: @item -fno-function-cse
1297: Do not put function addresses in registers; make each instruction
1298: that calls a constant function contain the function's address
1299: explicitly.
1300:
1301: This option results in less efficient code, but some strange
1302: hacks that alter the assembler output may be confused by the
1303: optimizations performed when this option is not used.
1304:
1305: @item -fvolatile
1306: Consider all memory references through pointers to be volatile.
1307:
1.1.1.4 root 1308: @item -fshared-data
1309: Requests that the data and non-@code{const} variables of this
1310: compilation be shared data rather than private data. The distinction
1311: makes sense only on certain operating systems, where shared data is
1312: shared between processes running the same program, while private data
1313: exists in one copy per process.
1314:
1.1 root 1315: @item -funsigned-char
1.1.1.4 root 1316: Let the type @code{char} be the unsigned, like @code{unsigned char}.
1.1 root 1317:
1318: Each kind of machine has a default for what @code{char} should
1319: be. It is either like @code{unsigned char} by default or like
1320: @code{signed char} by default. (Actually, at present, the
1321: default is always signed.)
1322:
1323: The type @code{char} is always a distinct type from either
1324: @code{signed char} or @code{unsigned char}, even though its
1325: behavior is always just like one of those two.
1326:
1.1.1.4 root 1327: Note that this is equivalent to @samp{-fno-signed-char}, which is the
1328: negative form of @samp{-fsigned-char}.
1329:
1.1 root 1330: @item -fsigned-char
1331: Let the type @code{char} be signed, like @code{signed char}.
1332:
1.1.1.4 root 1333: Note that this is equivalent to @samp{-fno-unsigned-char}, which is
1334: the negative form of @samp{-funsigned-char}.
1335:
1.1.1.8 root 1336: @item -fdelayed-branch
1337: If supported for the target machine, attempt to reorder instructions
1338: to exploit instruction slots available after delayed branch
1339: instructions.
1340:
1.1 root 1341: @item -ffixed-@var{reg}
1342: Treat the register named @var{reg} as a fixed register; generated
1343: code should never refer to it (except perhaps as a stack pointer,
1344: frame pointer or in some other fixed role).
1345:
1346: @var{reg} must be the name of a register. The register names
1347: accepted are machine-specific and are defined in the
1348: @code{REGISTER_NAMES} macro in the machine description macro
1349: file.
1350:
1.1.1.4 root 1351: This flag does not have a negative form, because it specifies a
1352: three-way choice.
1353:
1.1 root 1354: @item -fcall-used-@var{reg}
1355: Treat the register named @var{reg} as an allocatable register
1356: that is clobbered by function calls. It may be allocated for
1357: temporaries or variables that do not live across a call.
1358: Functions compiled this way will not save and restore the
1359: register @var{reg}.
1360:
1361: Use of this flag for a register that has a fixed pervasive role
1362: in the machine's execution model, such as the stack pointer or
1363: frame pointer, will produce disastrous results.
1364:
1.1.1.4 root 1365: This flag does not have a negative form, because it specifies a
1366: three-way choice.
1367:
1.1 root 1368: @item -fcall-saved-@var{reg}
1369: Treat the register named @var{reg} as an allocatable register
1370: saved by functions. It may be allocated even for temporaries or
1371: variables that live across a call. Functions compiled this way
1372: will save and restore the register @var{reg} if they use it.
1373:
1374: Use of this flag for a register that has a fixed pervasive role
1375: in the machine's execution model, such as the stack pointer or
1376: frame pointer, will produce disastrous results.
1377:
1378: A different sort of disaster will result from the use of this
1379: flag for a register in which function values may be returned.
1.1.1.4 root 1380:
1381: This flag does not have a negative form, because it specifies a
1382: three-way choice.
1.1 root 1383: @end table
1384:
1385: @item -d@var{letters}
1386: Says to make debugging dumps at times specified by @var{letters}.
1387: Here are the possible letters:
1388:
1389: @table @samp
1390: @item r
1391: Dump after RTL generation.
1392: @item j
1393: Dump after first jump optimization.
1394: @item s
1395: Dump after CSE (including the jump optimization that sometimes
1396: follows CSE).
1397: @item L
1398: Dump after loop optimization.
1399: @item f
1400: Dump after flow analysis.
1401: @item c
1402: Dump after instruction combination.
1403: @item l
1404: Dump after local register allocation.
1405: @item g
1406: Dump after global register allocation.
1.1.1.8 root 1407: @item d
1408: Dump after delayed branch scheduling.
1409: @item J
1410: Dump after last jump optimization.
1.1 root 1411: @item m
1412: Print statistics on memory usage, at the end of the run.
1413: @end table
1414:
1415: @item -pedantic
1416: Issue all the warnings demanded by strict ANSI standard C; reject
1417: all programs that use forbidden extensions.
1418:
1419: Valid ANSI standard C programs should compile properly with or without
1420: this option (though a rare few will require @samp{-ansi}). However,
1421: without this option, certain GNU extensions and traditional C features
1422: are supported as well. With this option, they are rejected. There is
1423: no reason to @i{use} this option; it exists only to satisfy pedants.
1.1.1.5 root 1424:
1.1.1.8 root 1425: @samp{-pedantic} does not cause warning messages for use of the
1426: alternate keywords whose names begin and end with @samp{__}.
1427: @xref{Alternate Keywords}.
1428:
1.1.1.5 root 1429: @item -static
1430: On Suns running version 4, this prevents linking with the shared
1431: libraries. (@samp{-g} has the same effect.)
1.1 root 1432: @end table
1433:
1434: These options control the C preprocessor, which is run on each C source
1435: file before actual compilation. If you use the @samp{-E} option, nothing
1436: is done except C preprocessing. Some of these options make sense only
1437: together with @samp{-E} because they request preprocessor output that is
1438: not suitable for actual compilation.
1439:
1440: @table @samp
1441: @item -C
1442: Tell the preprocessor not to discard comments. Used with the
1443: @samp{-E} option.
1444:
1445: @item -I@var{dir}
1446: Search directory @var{dir} for include files.
1447:
1448: @item -I-
1449: Any directories specified with @samp{-I} options before the @samp{-I-}
1450: option are searched only for the case of @samp{#include "@var{file}"};
1451: they are not searched for @samp{#include <@var{file}>}.
1452:
1453: If additional directories are specified with @samp{-I} options after
1454: the @samp{-I-}, these directories are searched for all @samp{#include}
1455: directives. (Ordinarily @emph{all} @samp{-I} directories are used
1456: this way.)
1457:
1458: In addition, the @samp{-I-} option inhibits the use of the current
1.1.1.8 root 1459: directory (where the current input file came from) as the first search
1460: directory for @samp{#include "@var{file}"}. There is no way to override
1461: this effect of @samp{-I-}. With @samp{-I.} you can specify searching
1462: the directory which was current when the compiler was invoked. That is
1463: not exactly the same as what the preprocessor does by default, but it is
1464: often satisfactory.
1465:
1466: @samp{-I-} does not inhibit the use of the standard system directories
1467: for header files. Thus, @samp{-I-} and @samp{-nostdinc} are
1468: independent.
1469:
1470: @item -i @var{file}
1471: Process @var{file} as input, discarding the resulting output, before
1472: processing the regular input file. Because the output generated from
1473: @var{file} is discarded, the only effect of @samp{-i @var{file}} is to
1474: make the macros defined in @var{file} available for use in the main
1475: input.
1.1 root 1476:
1477: @item -nostdinc
1478: Do not search the standard system directories for header files. Only
1479: the directories you have specified with @samp{-I} options (and the
1480: current directory, if appropriate) are searched.
1481:
1482: Between @samp{-nostdinc} and @samp{-I-}, you can eliminate all
1483: directories from the search path except those you specify.
1484:
1485: @item -M
1486: Tell the preprocessor to output a rule suitable for @code{make}
1.1.1.10 root 1487: describing the dependencies of each object file. For each source
1.1 root 1488: file, the preprocessor outputs one @code{make}-rule whose target is
1489: the object file name for that source file and whose dependencies are
1490: all the files @samp{#include}d in it. This rule may be a single line
1491: or may be continued with @samp{\}-newline if it is long.
1492:
1493: @samp{-M} implies @samp{-E}.
1494:
1495: @item -MM
1496: Like @samp{-M} but the output mentions only the user-header files
1497: included with @samp{#include "@var{file}"}. System header files
1498: included with @samp{#include <@var{file}>} are omitted.
1499:
1500: @samp{-MM} implies @samp{-E}.
1501:
1502: @item -D@var{macro}
1.1.1.8 root 1503: Define macro @var{macro} with the string @samp{1} as its definition.
1.1 root 1504:
1505: @item -D@var{macro}=@var{defn}
1506: Define macro @var{macro} as @var{defn}.
1507:
1508: @item -U@var{macro}
1509: Undefine macro @var{macro}.
1510:
1.1.1.7 root 1511: @item -trigraphs
1.1 root 1512: Support ANSI C trigraphs. You don't want to know about this
1513: brain-damage. The @samp{-ansi} option also has this effect.
1514: @end table
1515:
1516: @node Installation, Trouble, Options, Top
1517: @chapter Installing GNU CC
1518:
1519: Here is the procedure for installing GNU CC on a Unix system.
1.1.1.8 root 1520:
1.1 root 1521: @menu
1.1.1.8 root 1522: * Other Dir:: Compiling in a separate directory (not where the source is).
1523: * Sun Install:: See below for installation on the Sun.
1524: * 3B1 Install:: See below for installation on the 3B1.
1.1.1.11 root 1525: * SCO Install:: See below for installation on SCO System V 3.2. (Or ESIX.)
1.1 root 1526: * VMS Install:: See below for installation on VMS.
1.1.1.9 root 1527: * HPUX Install:: See below for installation on HPUX.
1.1.1.11 root 1528: * Tower Install:: See below for installation on an NCR Tower.
1.1 root 1529: @end menu
1530: @iftex
1.1.1.9 root 1531: See below for VMS systems, and modified procedures needed on Sun
1532: systems, 3b1 machines and HPUX. The following section says how to
1533: compile in a separate directory on Unix; here we assume you compile in
1534: the same directory that contains the source files.
1.1 root 1535: @end iftex
1536:
1537: @enumerate
1538: @item
1539: Edit @file{Makefile}. If you are using HPUX, or any form of system V,
1540: you must make a few changes described in comments at the beginning of
1.1.1.9 root 1541: the file. Genix requires changes also, and so does the Pyramid.
1.1 root 1542:
1543: @item
1544: On a Sequent system, go to the Berkeley universe.
1545:
1546: @item
1.1.1.2 root 1547: Choose configuration files. The easy way to do this is to run the
1.1.1.8 root 1548: command file @file{config.gcc} with a single argument, which specifies
1549: the type of machine (and in some cases which operating system).
1.1.1.4 root 1550:
1551: Here is a list of the possible arguments:
1552:
1553: @table @samp
1554: @item vax
1555: Vaxes running BSD.
1556: @item vms
1557: Vaxes running VMS.
1558: @item vax-sysv
1559: Vaxes running system V.
1560: @item i386-sysv
1561: Intel 386 PCs running system V.
1.1.1.5 root 1562: @item i386-sysv-gas
1563: Intel 386 PCs running system V, using the GNU assembler and GNU
1564: linker.
1.1.1.13! root 1565: @item i386-sysv4
! 1566: Intel 386 PCs running system V.4. You must run the shell script
! 1567: @file{fixincludes-V4} in order for GNU CC to work properly. You must
! 1568: also uncomment some lines in @file{Makefile}.
1.1.1.6 root 1569: @item sequent-i386
1.1.1.4 root 1570: Sequent with Intel 386 processors.
1.1.1.8 root 1571: @item i386-aix
1572: Intel 386 PCs or PS/2s running AIX.
1.1.1.4 root 1573: @item sun2
1574: Sun 2 running system version 2 or 3.
1575: @item sun3
1.1.1.12 root 1576: Sun 3 running system version 4, with 68881.
1.1.1.7 root 1577: Note there we do not provide a configuration file to use an FPA
1.1.1.8 root 1578: by default, because programs that establish signal handlers for
1.1.1.7 root 1579: floating point traps inherently cannot work with the FPA.
1.1.1.5 root 1580: @item sun3-nfp
1.1.1.12 root 1581: Sun 3 running system version 4, without 68881.
1.1.1.4 root 1582: @item sun4
1.1.1.12 root 1583: Sun 4 running system version 4. @xref{Incompatibilities},
1.1.1.8 root 1584: for calling convention incompatibilities on the Sun 4 (sparc).
1.1.1.4 root 1585: @item sun2-os4
1586: Sun 2 running system version 4.
1.1.1.12 root 1587: @item sun3-os3
1588: Sun 3 running system version 2 or 3, with 68881.
1589: @item sun3-nfp-os3
1590: Sun 3 running system version 2 or 3, without 68881.
1591: @item sun4-os3
1592: Sun 4 running system version 2 or 3. @xref{Incompatibilities},
1.1.1.8 root 1593: for calling convention incompatibilities on the Sun 4 (sparc).
1.1.1.4 root 1594: @item sun386
1595: Sun 386 (``roadrunner'').
1.1.1.5 root 1596: @item alliant
1.1.1.8 root 1597: Alliant FX/8 computer. Note that the standard installed C compiler in
1598: Concentrix 5.0 has a bug which prevent it from compiling GNU CC
1599: correctly. You can patch the compiler bug as follows:
1600:
1601: @example
1602: cp /bin/pcc ./pcc
1.1.1.9 root 1603: adb -w ./pcc - << EOF
1.1.1.8 root 1604: 15f6?w 6610
1605: EOF
1606: @end example
1607:
1608: Then you must use the @samp{-ip12} option when compiling GNU CC
1609: with the patched compiler, as shown here:
1610:
1611: @example
1612: make CC="./pcc -ip12" CFLAGS=-w
1613: @end example
1614:
1615: Note also that Alliant's version of DBX does not manage to work with the
1616: output from GNU CC.
1617: @item tahoe
1618: The tahoe computer (running BSD, and using DBX).
1619: @item decstation
1620: The DEC 3100 Mips machine (``pmax''). Note that GNU CC cannot generate
1621: debugging information in the unusual format used on the Mips.
1.1.1.13! root 1622: @item mips-sysv-os5
! 1623: The Mips computer, RS series, with the System V environment
! 1624: running on revision 5.00 of RISC-OS as default.
! 1625: Note that GNU CC cannot generate debugging information in the unusual
! 1626: format used on the Mips, and also cannot be used to create
! 1627: programs that use shared libraries.
1.1.1.8 root 1628: @item mips-sysv
1629: The Mips computer, RS series, with the System V environment as default.
1630: Note that GNU CC cannot generate debugging information in the unusual
1631: format used on the Mips.
1.1.1.13! root 1632: @item mips-bsd43-os5
! 1633: The Mips computer, RS series, with the BSD 4.3 environment
! 1634: running revision 5.00 of RISC-OS as default.
! 1635: Note that GNU CC cannot generate debugging information in the unusual
! 1636: format used on the Mips, and also cannot be used to create
! 1637: programs that use shared libraries.
1.1.1.8 root 1638: @item mips-bsd43
1639: The Mips computer, RS series, with the BSD 4.3 environment as default.
1640: Note that GNU CC cannot generate debugging information in the unusual
1641: format used on the Mips.
1.1.1.13! root 1642: @item mips-os5
! 1643: The Mips computer, M series running revision 5.00 of RISC-OS.
! 1644: Note that GNU CC cannot generate debugging information in the
! 1645: unusual format used on the Mips, and also cannot be used to
! 1646: create programs that use shared libraries.
1.1.1.7 root 1647: @item mips
1.1.1.8 root 1648: The Mips computer, M series. Note that GNU CC cannot generate debugging
1649: information in the unusual format used on the Mips.
1650: @item iris
1.1.1.10 root 1651: Another variant of the Mips computer, the Silicon Graphics Iris 4D.
1652: Note that GNU CC cannot generate debugging information in the unusual
1653: format used on the Mips.
1.1.1.5 root 1654: @item convex-c1
1.1.1.12 root 1655: Convex C1 computer. With operating system version 9, use @samp{cc -pcc}
1656: as the compilation command when building stage 1 of GNU CC.
1.1.1.5 root 1657: @item convex-c2
1.1.1.12 root 1658: Convex C2 computer. With operating system version 9, use @samp{cc -pcc}
1659: as the compilation command when building stage 1 of GNU CC.
1.1.1.8 root 1660: @item pyramid
1661: Pyramid computer.
1.1.1.4 root 1662: @item hp9k320
1.1.1.7 root 1663: HP 9000 series 300 using HPUX assembler. Note there is no
1664: support in GNU CC for HP's debugger; thus, @samp{-g} is not
1665: available in this configuration.
1.1.1.8 root 1666: @item hp9k320-gas
1.1.1.4 root 1667: HP 9000 series 300 using GNU assembler, linker and debugger.
1.1.1.7 root 1668: This requires the HP-adapt package, which is available along with
1669: the GNU linker as part of the ``binutils'' distribution.
1670: This is on the GNU CC distribution tape.
1.1.1.8 root 1671: @item hp9k320-old
1672: HP 9000 series 300 using HPUX assembler, in operating system versions
1673: older than 6.5. Note there is no support in GNU CC for HP's debugger;
1674: thus, @samp{-g} is not available in this configuration.
1675: @item hp9k320-bsd
1676: HP 9000 series 300 running BSD.
1.1.1.12 root 1677: @item hp9k200-bsd
1678: HP 9000 series 200 running BSD. Note that the C compiler that comes
1679: with this system cannot compile GNU CC; contact @code{law@@super.org} to
1680: get binaries of GNU CC for bootstrapping. Additionally, a minor patch
1681: is necessary if you wish to build kernels with GNU CC; contact
1682: @code{law@@super.org} to get a copy of the patch.
1.1.1.4 root 1683: @item isi68
1.1.1.8 root 1684: ISI 68000 or 68020 system with a 68881.
1685: @item isi68-nfp
1686: ISI 68000 or 68020 system without a 68881.
1.1.1.4 root 1687: @item news800
1688: Sony NEWS 68020 system.
1.1.1.6 root 1689: @item next
1690: NeXT system.
1.1.1.10 root 1691: @item tower
1692: NCR Tower 32 system.
1.1.1.7 root 1693: @item altos
1694: Altos 3068. Note that you must use the GNU assembler, linker and
1695: debugger, with COFF-encapsulation. Also, you must fix a kernel
1696: bug. Details in the file @file{ALTOS-README}.
1.1.1.4 root 1697: @item 3b1
1.1.1.8 root 1698: AT&T 3b1, a.k.a. 7300 PC. Note that special procedures are needed
1699: to compile GNU CC with this machine's standard C compiler, due to
1700: bugs in that compiler. @xref{3b1 Install}. You can bootstrap it
1701: more easily with previous versions of GNU CC if you have them.
1.1.1.9 root 1702: @item 3b1-gas
1703: AT&T 3b1 using the GNU assembler.
1.1.1.4 root 1704: @item sequent-ns32k
1705: Sequent containing ns32000 processors.
1706: @item encore
1707: Encore ns32000 system.
1708: @item genix
1709: National Semiconductor ns32000 system.
1710: @item 88000
1711: Motorola 88000 processor. This port is not finished.
1712: @end table
1.1.1.2 root 1713:
1.1.1.4 root 1714: Here we spell out what files need to be set up:
1.1 root 1715:
1716: @itemize @bullet
1717: @item
1718: Make a symbolic link named @file{config.h} to the top-level
1719: config file for the machine you are using (@pxref{Config}). This
1720: file is responsible for defining information about the host
1721: machine. It includes @file{tm.h}.
1722:
1.1.1.7 root 1723: The file is located in the subdirectory @file{config}. Its name
1724: should be @file{xm-@var{machine}.h}, with these exceptions:
1.1 root 1725:
1726: @table @file
1.1.1.3 root 1727: @item xm-vms.h
1.1 root 1728: for vaxen running VMS.
1.1.1.3 root 1729: @item xm-vaxv.h
1.1 root 1730: for vaxen running system V.
1.1.1.3 root 1731: @item xm-i386v.h
1.1 root 1732: for Intel 80386's running system V.
1.1.1.3 root 1733: @item xm-sun386i.h
1734: for Sun roadrunner running any version of the operating system.
1735: @item xm-hp9k320.h
1.1 root 1736: for the HP 9000 series 300.
1.1.1.4 root 1737: @item xm-genix.h
1.1 root 1738: for the ns32000 running Genix
1739: @end table
1740:
1741: If your system does not support symbolic links, you might want to
1742: set up @file{config.h} to contain a @samp{#include} command which
1743: refers to the appropriate file.
1744:
1745: @item
1746: Make a symbolic link named @file{tm.h} to the machine-description
1.1.1.7 root 1747: macro file for your machine. It should be in the subdirectory
1748: @file{config} and its name should be @file{tm-@var{machine}.h}.
1.1 root 1749:
1750: If your system is a 68000, don't use the file @file{tm-m68k.h}
1751: directly. Instead, use one of these files:
1752:
1753: @table @file
1754: @item tm-sun3.h
1.1.1.5 root 1755: for Sun 3 machines with 68881.
1756: @item tm-sun3-nfp.h
1757: for Sun 3 machines with no hardware floating point.
1.1.1.8 root 1758: @item tm-sun3os3.h
1759: for Sun 3 machines with 68881, running Sunos version 3.
1760: @item tm-sun3os3nf.h
1761: for Sun 3 machines with no hardware floating point, running Sunos
1762: version 3.
1.1 root 1763: @item tm-sun2.h
1764: for Sun 2 machines.
1765: @item tm-3b1.h
1766: for AT&T 3b1 (aka 7300 Unix PC).
1767: @item tm-isi68.h
1.1.1.3 root 1768: for Integrated Solutions systems. This file assumes you
1769: use the GNU assembler.
1.1.1.8 root 1770: @item tm-isi68-nfp.h
1771: for Integrated Solutions systems without a 68881. This file assumes you
1772: use the GNU assembler.
1.1 root 1773: @item tm-news800.h
1.1.1.8 root 1774: for Sony NEWS systems.
1.1 root 1775: @item tm-hp9k320.h
1776: for HPUX systems, if you are using GNU CC with the system's
1777: assembler and linker.
1778: @item tm-hp9k320g.h
1779: for HPUX systems, if you are using the GNU assembler, linker and
1780: other utilities. Not all of the pieces of GNU software needed
1781: for this mode of operation are as yet in distribution; full
1782: instructions will appear here in the future.@refill
1.1.1.10 root 1783: @item tm-tower-as.h
1784: for NCR Tower 32 systems, using the standard system assembler.
1.1 root 1785: @end table
1786:
1787: For the vax, use @file{tm-vax.h} on BSD Unix, @file{tm-vaxv.h} on
1788: system V, or @file{tm-vms.h} on VMS.@refill
1789:
1790: For the Motorola 88000, use @file{tm-m88k.h}. The support for the
1.1.1.9 root 1791: 88000 does not currently work; it requires extensive changes which
1792: we hope to reconcile in version 2.
1.1 root 1793:
1794: For the 80386, don't use @file{tm-i386.h} directly. Use
1795: @file{tm-i386v.h} if the target machine is running system V,
1.1.1.5 root 1796: @file{tm-i386gas.h} if it is running system V but you are using the
1797: GNU assembler and linker, @file{tm-seq386.h} for a Sequent 386 system,
1798: or @file{tm-compaq.h} for a Compaq, or @file{tm-sun386i.h} for a Sun
1799: 386 system.
1.1 root 1800:
1.1.1.8 root 1801: For the Mips computer, there are five choices: @file{tm-mips.h} for the
1802: M series, @file{tm-mips-bsd.h} for the RS series with BSD,
1803: @file{tm-mips-sysv.h} for the RS series with System V, @file{tm-iris.h}
1804: for the Iris version of the machine, and @file{tm-decstatn.h} for the
1805: Decstation.
1806:
1.1 root 1807: For the 32000, use @file{tm-sequent.h} if you are using a Sequent
1808: machine, or @file{tm-encore.h} for an Encore machine, or
1.1.1.4 root 1809: @file{tm-genix.h} if you are using Genix version 3; otherwise, perhaps
1.1 root 1810: @file{tm-ns32k.h} will work for you.
1811:
1812: Note that Genix has bugs in @code{alloca} and @code{malloc}; you must
1813: get the compiled versions of these from GNU Emacs and edit GNU CC's
1814: @file{Makefile} to use them.
1815:
1816: Note that Encore systems are supported only under BSD.
1817:
1.1.1.6 root 1818: For Sparc (Sun 4) machines, use @file{tm-sparc.h} with operating system
1819: version 4, and @file{tm-sun4os3.h} with system version 3.
1820:
1.1.1.10 root 1821: For Convex systems before version 8.1, use @file{tm-conv1os7.h} or
1822: @file{tm-conv2os7.h}. For versions 8.1 and greater, use @file{tm-convex1.h}
1823: or @file{tm-convex2.h}. You should also bootstrap GCC with @code{pcc}
1824: rather than @code{cc}; one way to do this is with the following commands.
1825:
1826: @example
1827: ln -s /bin/pcc ./cc
1828: set path = (. $path)
1829: @end example
1830:
1.1 root 1831: @item
1832: Make a symbolic link named @file{md} to the machine description
1.1.1.7 root 1833: pattern file. It should be in the @file{config} subdirectory and its
1834: name should be @file{@var{machine}.md}; but @var{machine} is often not
1835: the same as the name used in the @file{tm.h} file because the
1836: @file{md} files are more general.
1.1 root 1837:
1838: @item
1839: Make a symbolic link named @file{aux-output.c} to the output
1.1.1.7 root 1840: subroutine file for your machine. It should be in the @file{config}
1841: subdirectory and its name should be @file{out-@var{machine}.c}.
1.1 root 1842: @end itemize
1843:
1844: @item
1845: Make sure the Bison parser generator is installed. (This is
1846: unnecessary if the Bison output files @file{c-parse.tab.c} and
1847: @file{cexp.c} are more recent than @file{c-parse.y} and @file{cexp.y}
1848: and you do not plan to change the @samp{.y} files.)
1849:
1.1.1.9 root 1850: Bison versions older than Sept 8, 1988 will produce incorrect output
1.1 root 1851: for @file{c-parse.tab.c}.
1852:
1853: @item
1.1.1.10 root 1854: If you have a previous version of GCC installed, then chances are
1855: you can compile the new version with that. Do the following:
1856:
1857: @example
1858: make CC="gcc -O"
1859: @end example
1860:
1861: @noindent
1862: Since this produces an optimized executable right away, there is no need
1863: to bootstrap the result with itself except to test it. Therefore, you can
1864: skip directly to the @samp{make install} step below.
1865:
1866: @item
1.1 root 1867: Build the compiler. Just type @samp{make} in the compiler directory.
1868:
1.1.1.2 root 1869: Ignore any warnings you may see about ``statement not reached'' in the
1870: @file{insn-emit.c}; they are normal. Any other compilation errors may
1871: represent bugs in the port to your machine or operating system, and
1872: should be investigated and reported (@pxref{Bugs}).
1873:
1.1.1.9 root 1874: Some commercial compilers fail to compile GNU CC because they have bugs
1875: or limitations. For example, the Microsoft compiler is said to run out
1876: of macro space. Some Ultrix compilers run out of expression space; then
1877: you need to break up the statement where the problem happens.
1.1.1.7 root 1878:
1879: @item
1.1.1.5 root 1880: If you are using COFF-encapsulation, you must convert @file{gnulib} to
1881: a GNU-format library at this point. See the file @file{README-ENCAP}
1882: in the directory containing the GNU binary file utilities, for
1883: directions.
1884:
1885: @item
1.1 root 1886: Move the first-stage object files and executables into a subdirectory
1887: with this command:
1888:
1889: @example
1890: make stage1
1891: @end example
1892:
1893: The files are moved into a subdirectory named @file{stage1}.
1894: Once installation is complete, you may wish to delete these files
1895: with @code{rm -r stage1}.
1896:
1897: @item
1898: Recompile the compiler with itself, with this command:
1899:
1900: @example
1901: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/"
1902: @end example
1903:
1.1.1.10 root 1904: This is called making the stage 2 compiler.
1905:
1.1 root 1906: On a 68000 or 68020 system lacking floating point hardware,
1907: unless you have selected a @file{tm.h} file that expects by default
1908: that there is no such hardware, do this instead:
1909:
1910: @example
1911: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/ -msoft-float"
1912: @end example
1913:
1914: @item
1915: If you wish to test the compiler by compiling it with itself one more
1.1.1.7 root 1916: time, do this (in C shell):
1.1 root 1917:
1918: @example
1919: make stage2
1920: make CC=stage2/gcc CFLAGS="-g -O -Bstage2/"
1921: foreach file (*.o)
1922: cmp $file stage2/$file
1923: end
1924: @end example
1925:
1.1.1.7 root 1926: @noindent
1.1.1.10 root 1927: This is called making the stage 3 compiler. Aside from the @samp{-B}
1928: option, the options should be the same as when you made the stage 2
1929: compiler.
1.1 root 1930:
1.1.1.7 root 1931: The @code{foreach} command (written in C shell) will notify you if any of
1932: these stage 3 object files differs from those of stage 2. On BSD systems,
1933: any difference, no matter how innocuous, indicates that the stage 2
1934: compiler has compiled GNU CC incorrectly, and is therefore a potentially
1935: serious bug which you should investigate and report (@pxref{Bugs}).
1936:
1937: On systems that use COFF object files, bytes 5 to 8 will always be
1938: different, since it is a timestamp. On these systems, you can do the
1939: comparison as follows (in Bourne shell):
1940:
1941: @example
1942: for file in *.o; do
1943: echo $file
1.1.1.10 root 1944: tail +10c $file > foo1
1945: tail +10c stage2/$file > foo2
1.1.1.7 root 1946: cmp foo1 foo2
1947: done
1948: @end example
1949:
1.1.1.10 root 1950: On MIPS machines, you should use the shell script @file{ecoff-cmp}
1951: to compare two object files.
1952:
1.1 root 1953: @item
1954: Install the compiler driver, the compiler's passes and run-time support.
1955: You can use the following command:
1956:
1957: @example
1958: make install
1959: @end example
1960:
1961: @noindent
1962: This copies the files @file{cc1}, @file{cpp} and @file{gnulib} to
1963: files @file{gcc-cc1}, @file{gcc-cpp} and @file{gcc-gnulib} in
1964: directory @file{/usr/local/lib}, which is where the compiler driver
1965: program looks for them. It also copies the driver program @file{gcc}
1.1.1.6 root 1966: into the directory @file{/usr/local/bin}, so that it appears in typical
1.1 root 1967: execution search paths.@refill
1968:
1969: @strong{Warning: there is a bug in @code{alloca} in the Sun library.
1970: To avoid this bug, install the binaries of GNU CC that were compiled
1971: by GNU CC. They use @code{alloca} as a built-in function and never
1972: the one in the library.}
1973:
1974: @strong{Warning: the GNU CPP may not work for @file{ioctl.h},
1975: @file{ttychars.h} and other system header files unless the
1976: @samp{-traditional} option is used.} The bug is in the header files:
1977: at least on some machines, they rely on behavior that is incompatible
1978: with ANSI C. This behavior consists of substituting for macro
1979: argument names when they appear inside of character constants. The
1980: @samp{-traditional} option tells GNU CC to behave the way these
1981: headers expect.
1982:
1983: Because of this problem, you might prefer to configure GNU CC to use
1984: the system's own C preprocessor. To do so, make the file
1985: @file{/usr/local/lib/gcc-cpp} a link to @file{/lib/cpp}.
1986:
1987: Alternatively, on Sun systems and 4.3BSD at least, you can correct the
1988: include files by running the shell script @file{fixincludes}. This
1989: installs modified, corrected copies of the files @file{ioctl.h},
1990: @file{ttychars.h} and many others, in a special directory where only
1.1.1.2 root 1991: GNU CC will normally look for them. This script will work on various
1.1.1.6 root 1992: systems because it chooses the files by searching all the system
1.1.1.2 root 1993: headers for the problem cases that we know about.
1.1.1.10 root 1994:
1995: Use the following command to do this:
1996:
1997: @example
1998: make includes
1999: @end example
2000:
2001: @noindent
2002: If you selected a different directory for GNU CC installation when you
2003: installed it, by specifying the Make variable @code{prefix} or
2004: @code{libdir}, specify it the same way in this command.
2005:
2006: Note that some systems are starting to come with ANSI C system header
2007: files. On these systems, don't run @file{fixincludes}; it may not work,
2008: and is certainly not necessary.
1.1.1.12 root 2009:
2010: @strong{Warning:} @file{fixincludes} does not work on many MIPS systems,
2011: because those systems come with circular symbolic links which cause
2012: @samp{ls -lR} to go into an infinite loop.
1.1 root 2013: @end enumerate
2014:
2015: If you cannot install the compiler's passes and run-time support in
2016: @file{/usr/local/lib}, you can alternatively use the @samp{-B} option to
2017: specify a prefix by which they may be found. The compiler concatenates
2018: the prefix with the names @file{cpp}, @file{cc1} and @file{gnulib}.
2019: Thus, you can put the files in a directory @file{/usr/foo/gcc} and
2020: specify @samp{-B/usr/foo/gcc/} when you run GNU CC.
2021:
2022: Also, you can specify an alternative default directory for these files
2023: by setting the Make variable @code{libdir} when you make GNU CC.
2024:
1.1.1.8 root 2025: @node Other Dir, Sun Install, Installation, Installation
2026: @section Compilation in a Separate Directory
1.1 root 2027:
1.1.1.8 root 2028: If you wish to build the object files and executables in a directory
2029: other than the one containing the source files, here is what you must
2030: do differently:
2031:
2032: @enumerate
2033: @item
2034: Go to that directory before running @file{config.gcc}:
2035:
2036: @example
2037: mkdir gcc-sun3
2038: cd gcc-sun3
2039: @end example
1.1.1.4 root 2040:
1.1.1.8 root 2041: On systems that do not support symbolic links, this directory must be
2042: on the same file system as the source code directory.
2043:
2044: @item
2045: Specify where to find @file{config.gcc} when you run it:
2046:
2047: @example
2048: ../gcc-1.36/config.gcc @dots{}
2049: @end example
2050:
2051: @item
2052: Specify where to find the sources, as an argument to @file{config.gcc}:
2053:
2054: @example
2055: ../gcc-1.36/config.gcc -srcdir=../gcc-1.36 sun3
2056: @end example
2057:
2058: The @samp{-srcdir=@var{dir}} option is not needed when the source
2059: directory is the parent of the current directory, because
2060: @file{config.gcc} detects that case automatically.
2061: @end enumerate
2062:
2063: Now, you can run @code{make} in that directory. You need not repeat the
2064: configuration steps shown above, when ordinary source files change. You
2065: must, however, run @code{config.gcc} again when the configuration files
2066: change, if your system does not support symbolic links.
2067:
2068: @node Sun Install, 3b1 Install, Other Dir, Installation
2069: @section Installing GNU CC on the Sun
2070:
2071: Make sure the environment variable @code{FLOAT_OPTION} is not set when
2072: you compile @file{gnulib}. If this option were set to @code{f68881}
2073: when @file{gnulib} is compiled, the resulting code would demand to be
2074: linked with a special startup file and would not link properly without
2075: special pains.
2076:
2077: There is a bug in @code{alloca} in certain versions of the Sun library.
2078: To avoid this bug, install the binaries of GNU CC that were compiled by
2079: GNU CC. They use @code{alloca} as a built-in function and never the one
2080: in the library.
2081:
1.1.1.11 root 2082: Some versions of the Sun compiler crash when compiling GNU CC, with a
2083: segmentation fault in cpp. This can sometimes be due to the bulk of
2084: data in the environment variables. You may be able to avoid it by using
2085: the following command to compile GNU CC with Sun CC:
1.1.1.8 root 2086:
2087: @example
2088: make CC="TERMCAP=x OBJS=x LIBFUNCS=x STAGESTUFF=x cc"
2089: @end example
2090:
1.1.1.11 root 2091: Another problem that often happens on Suns is that you get a crash when
2092: building stage 2, when @code{genflags} is run.
2093:
2094: One reason for such as crash is if you configured GNU CC for the wrong
2095: version of SunOS. Starting with version 1.38, configurations @code{sun3}
2096: and @code{sun4} are for SunOS 4, so this problem should no longer happen.
2097:
2098: Another cause of the same symptom is having installed the GNU linker
2099: with an earlier version of SunOS. The version that worked before
2100: stopped working due to a change in the format of executables in SunOS
2101: 4.1. Many sites have installed the GNU linker as
2102: @file{/usr/local/lib/gcc-ld}, often as part of installing GNU C++. So
2103: if you get such crashes and you have used the proper configuration, try
2104: deleting @file{/usr/local/lib/gcc-ld}.
2105:
2106: The current version of the GNU linker, found in the current binutils
2107: release, does work with SunOS 4.1.
2108:
1.1.1.10 root 2109: @node 3b1 Install, SCO Install, Sun Install, Installation
1.1.1.8 root 2110: @section Installing GNU CC on the 3b1
2111:
2112: Installing GNU CC on the 3b1 is difficult if you do not already have
2113: GNU CC running, due to bugs in the installed C compiler. However,
2114: the following procedure might work. We are unable to test it.
1.1 root 2115:
2116: @enumerate
2117: @item
1.1.1.8 root 2118: Comment out the @samp{#include "config.h"} line on line 37 of
2119: @file{cccp.c} and do @samp{make cpp}. This makes a preliminary version
2120: of GNU cpp.
1.1 root 2121:
2122: @item
1.1.1.8 root 2123: Save the old @file{/lib/cpp} and copy the preliminary GNU cpp to that
2124: file name.
1.1.1.5 root 2125:
1.1.1.8 root 2126: @item
2127: Undo your change in @file{cccp.c}, or reinstall the original version,
2128: and do @samp{make cpp} again.
2129:
2130: @item
2131: Copy this final version of GNU cpp into @file{/lib/cpp}.
2132:
2133: @item
1.1.1.9 root 2134: Replace every occurrence of @code{obstack_free} in @file{tree.c}
1.1.1.8 root 2135: with @code{_obstack_free}.
2136:
2137: @item
2138: Run @code{make} to get the first-stage GNU CC.
2139:
2140: @item
2141: Reinstall the original version of @file{/lib/cpp}.
2142:
2143: @item
2144: Now you can compile GNU CC with itself and install it in the normal
2145: fashion.
1.1 root 2146: @end enumerate
2147:
1.1.1.9 root 2148: If you have installed an earlier version of GCC, you can compile the
2149: newer version with that. However, you will run into trouble compiling
2150: @file{gnulib}, since that is normally compiled with CC. To solve the
2151: problem, uncomment this line in @file{Makefile}:
2152:
2153: @example
2154: CCLIBFLAGS = -B/usr/local/lib/gcc- -tp -Wp,-traditional
2155: @end example
2156:
1.1.1.10 root 2157: @node SCO Install, VMS Install, 3B1 Install, Installation
2158: @section Installing GNU CC on SCO System V 3.2
2159: @cindex Installation on SCO systems
2160:
2161: The compiler that comes with this system does not work properly with
2162: @samp{-O}. Therefore, you should redefine the Make variable
2163: @code{CCLIBFLAGS} not to use @samp{-O}.
2164:
1.1.1.11 root 2165: You should also edit @file{Makefile} to enable the lines that set
2166: @code{CLIB} to @code{-lPW}, and the ones specifically labeled as being
2167: for SCO, that set @code{RANLIB}, and that set @code{CC} and @code{OLDCC}
1.1.1.13! root 2168: to @samp{rcc -Di386 -DM_UNIX -DM_I386 -DM_SYSV -DM_COFF}.
1.1.1.10 root 2169:
1.1.1.11 root 2170: Also, edit the definition of @code{USER_H} to remove the file @file{limits.h}.
1.1.1.10 root 2171:
1.1.1.11 root 2172: Then you can run @samp{config.gcc i386-sco} and finish building GNU CC
2173: normally.
1.1.1.10 root 2174:
1.1.1.13! root 2175: Note that the function @code{memmove} is broken in 3.2v2; it clobbers
! 2176: register @code{%ebx}. See the file @file{sco-memmove.s}.
! 2177:
1.1.1.11 root 2178: The same recipe should work on ESIX, but use @samp{config.gcc i386-esix}
2179: instead.
1.1.1.10 root 2180:
2181: @node VMS Install, HPUX Install, SCO Install, Installation
1.1.1.8 root 2182: @section Installing GNU CC on VMS
2183:
2184: The VMS version of GNU CC is distributed in a backup saveset containing
2185: both source code and precompiled binaries.
2186:
2187: To install the @file{gcc} command so you can use the compiler easily, in
1.1 root 2188: the same manner as you use the VMS C compiler, you must install the VMS CLD
2189: file for GNU CC as follows:
2190:
2191: @enumerate
2192: @item
2193: Define the VMS logical names @samp{GNU_CC} and @samp{GNU_CC_INCLUDE}
2194: to point to the directories where the GNU CC executables
1.1.1.8 root 2195: (@file{gcc-cpp}, @file{gcc-cc1}, etc.) and the C include files are
1.1 root 2196: kept. This should be done with the commands:@refill
2197:
2198: @example
1.1.1.8 root 2199: $ assign /super /system disk:[gcc.] gnu_cc
2200: $ assign /super /system disk:[gcc.include.] gnu_cc_include
1.1 root 2201: @end example
2202:
2203: @noindent
2204: with the appropriate disk and directory names. These commands can be
2205: placed in your system startup file so they will be executed whenever
1.1.1.8 root 2206: the machine is rebooted. You may, if you choose, do this via the
2207: @file{GCC_INSTALL.COM} script in the @file{[GCC]} directory.
1.1 root 2208:
2209: @item
1.1.1.8 root 2210: Install the @file{GCC} command with the command line:
1.1 root 2211:
2212: @example
1.1.1.8 root 2213: $ set command /table=sys$library:dcltables gnu_cc:[000000]gcc
1.1 root 2214: @end example
2215:
1.1.1.7 root 2216: @item
2217: To install the help file, do the following:
2218:
2219: @example
2220: $ lib/help sys$library:helplib.hlb gcc.hlp
2221: @end example
2222:
1.1 root 2223: @noindent
2224: Now you can invoke the compiler with a command like @samp{gcc /verbose
2225: file.c}, which is equivalent to the command @samp{gcc -v -c file.c} in
2226: Unix.
2227: @end enumerate
2228:
1.1.1.8 root 2229: We try to put corresponding binaries and sources on the VMS distribution
2230: tape. But sometimes the binaries will be from an older version that the
2231: sources, because we don't always have time to update them. (Use the
2232: @samp{/verbose} option to determine the version number of the binaries and
2233: compare it with the source file @file{version.c} to tell whether this is
2234: so.) In this case, you should use the binaries you get to recompile the
2235: sources. If you must recompile, here is how:
2236:
2237: @enumerate
2238: @item
2239: Copy the file @file{tm-vms.h} to @file{tm.h}, @file{xm-vms.h} to
2240: @file{config.h}, @file{vax.md} to @file{md.} and @file{out-vax.c}
2241: to @file{aux-output.c}. The files to be copied are found in the
2242: subdirectory named @file{config}; they should be copied to the
2243: main directory of GNU CC.@refill
2244:
2245: @item
2246: Setup the logical names and command tables as defined above. In
2247: addition, define the vms logical name @samp{GNU_BISON} to point at the
2248: to the directories where the Bison executable is kept. This should be
2249: done with the command:@refill
2250:
2251: @example
2252: $ assign /super /system disk:[bison.] gnu_bison
2253: @end example
2254:
2255: You may, if you choose, use the @file{INSTALL_BISON.COM} script in the
2256: @file{[BISON]} directory.
2257:
2258: @item
2259: Install the @samp{BISON} command with the command line:@refill
2260:
2261: @example
2262: $ set command /table=sys$library:dcltables gnu_bison:[000000]bison
2263: @end example
2264:
2265: @item
2266: Type @samp{@@make} to do recompile everything.
2267:
2268: If you are compiling with a version of GNU CC older than 1.33, specify
2269: @samp{/DEFINE=("inline=")} as an option in all the compilations. This
2270: requires editing all the @code{gcc} commands in @file{make-cc1.com}.
2271: (The older versions had problems supporting @code{inline}.) Once you
2272: have a working 1.33 or newer GNU CC, you can change this file back.
2273: @end enumerate
2274:
1.1.1.12 root 2275: Due to the differences between the filesystems of Unix and VMS, the
2276: preprocessor attempts to translate the names of include files into
2277: something that VMS will understand. The basic strategy is to prepend a
2278: prefix to the specification of the include file, convert the whole
2279: filename to a VMS filename, and then try to open the file. The
2280: preprocessor tries various prefixes until one of them succeeds.
2281:
2282: The first prefix is the @samp{GNU_CC_INCLUDE:} logical name: this is
2283: where GNU_C header files are traditionally stored. If a header file is
2284: not found there, @samp{SYS$SYSROOT:[SYSLIB.]} is tried next. If the
2285: preprocessor is still unable to locate the file, it then assumes that
2286: the include file specification is a valid VMS filename all by itself,
2287: and it uses this filename to attempt to open the include file. If none
2288: of these strategies succeeds, the preprocessor reports an error.
2289:
2290: If you wish to store header files in non-standard locations, then you
2291: can assign the logical @samp{GNU_CC_INCLUDE} to be a search list, where
2292: each element of the list is suitable for use with a rooted logical.
2293:
1.1.1.10 root 2294: With this version of GNU CC, @code{const} global variables now work
2295: properly. Unless, however, the @code{const} modifier is also specified
2296: in every external declaration of the variable in all of the source files
2297: that use that variable, the linker will issue warnings about conflicting
2298: attributes for the variable, since the linker does not know if the
2299: variable should be read-only. The program will still work, but the
2300: variable will be placed in writable storage.
2301:
1.1.1.12 root 2302: Due to an assembler bug, offsets to static constants are sometimes
2303: incorrectly evaluated. This bug is present in GAS 1.38.1, and should be
2304: fixed in the next version.
2305:
1.1.1.10 root 2306: Under previous versions of GNU CC, the generated code would occasionally
2307: give strange results when linked to the sharable @file{VAXCRTL} library.
2308: Now this should work.
2309:
1.1.1.12 root 2310: Even with this version, however, GNU CC itself should not be linked to the
2311: sharable @file{VAXCRTL}. The @file{qsort} routine supplied with @file{VAXCRTL}
2312: has a bug which can cause a compiler crash.
2313:
2314: Similarly, the preprocessor should not be linked to the sharable
2315: @file{VAXCRTL}. The @code{strncat} routine supplied with @file{VAXCRTL} has a
2316: bug which can cause the preprocessor to go into an infinite loop.
2317:
2318: It should be pointed out that if you attempt to link to the sharable
2319: @file{VAXCRTL}, the VMS linker will strongly resist any effort to force
2320: it to use the @code{qsort} and @code{strncat} routines from
2321: @file{gcclib}. Until the bugs in @file{VAXCRTL} have been fixed,
2322: linking any of the compiler components to the sharable VAXCRTL is not
2323: recommended. (These routines can be bypassed by placing duplicate copies
2324: of @code{qsort} and @code{strncat} in @file{gcclib} under different
2325: names, and patching the compiler sources to use these routines). Both
2326: of the bugs in @file{VAXCRTL} are still present in VMS version 5.4-1,
2327: which is the most recent version as of this writing.
2328:
2329: The executables that are generated by @file{make-cc1.com} and
2330: @file{make-cccp.com} use the non-shared version of @file{VAXCRTL} (and
2331: thus use the @code{qsort} and @code{strncat} routines from
2332: @file{gcclib.olb}).
1.1.1.10 root 2333:
2334: Note that GNU CC on VMS now generates debugging information to describe
2335: the programs symbols to the VMS debugger. However, you need version 1.37
2336: or later of GAS in order to output them properly in the object file.
1.1.1.7 root 2337:
1.1.1.12 root 2338: The VMS linker does not distinguish between upper and lower case letters
2339: in function and variable names. However, usual practice in C is to
2340: distinguish case. Normally GNU C (by means of the assembler GAS)
2341: implements usual C behavior by augmenting each name that is not all
2342: lower-case. A name is augmented by truncating it to at most 23
2343: characters and then adding more characters at the end which encode the
2344: case pattern the rest.
2345:
2346: Name augmentation yields bad results for programs that use precompiled
2347: libraries (such as Xlib) which were generated by another compiler. Use
2348: the compiler option @samp{/NOCASE_HACK} to inhibits augmentation; it
2349: makes external C functions and variables case-independent as is usual on
2350: VMS. Alternatively, you could write all references to the functions and
2351: variables in such libraries using lower case; this will work on VMS, but
2352: is not portable to other systems. In cases where you need to
2353: selectively inhibit augmentation, you can define a macro for each mixed
2354: case symbol for which you wish to inhibit augmentation, where the macro
2355: expands into the lower case equivalent of the name.
2356:
2357: @node HPUX Install, Tower Install, VMS Install, Installation
1.1.1.9 root 2358: @section Installing GNU CC on HPUX
2359:
2360: To install GNU CC on HPUX, you must start by editing the file
2361: @file{Makefile}. Search for the string @samp{HPUX} to find comments
2362: saying what to change. You need to change some variable definitions and
2363: (if you are using GAS) some lines in the rule for the target
2364: @samp{gnulib}.
2365:
1.1.1.10 root 2366: To avoid errors when linking programs with @samp{-g}, create an empty
2367: library named @file{libg.a}. An easy way to do this is:
2368:
2369: @example
2370: ar rc /usr/local/lib/libg.a
2371: @end example
2372:
1.1.1.9 root 2373: To compile with the HPUX C compiler, you must specify get the file
2374: @file{alloca.c} from GNU Emacs. Then, when you run @code{make}, use
2375: this argument:
2376:
2377: @example
2378: make ALLOCA=alloca.o
2379: @end example
2380:
2381: When recompiling GNU CC with itself, do not define @code{ALLOCA}.
2382: Instead, an @samp{-I} option needs to be added to @code{CFLAGS} as
2383: follows:
2384:
2385: @example
2386: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/ -I../binutils/hp-include"
2387: @end example
2388:
1.1.1.12 root 2389: @node Tower Install,, HPUX Install, Installation
1.1.1.11 root 2390: @section Installing GNU CC on an NCR Tower
2391:
2392: On an NCR Tower model 4x0 or 6x0, you may have trouble because the
2393: default maximum virtual address size of a process is just 1 Mb. Most
2394: often you will find this problem while compiling GNU CC with itself.
2395:
2396: The only way to solve the problem is to reconfigure the kernel.
2397: Add a line such as this to the configuration file:
2398:
2399: @example
2400: MAXUMEM = 4096
2401: @end example
2402:
2403: @noindent
2404: and then relink the kernel and reboot the machine.
2405:
2406:
1.1.1.10 root 2407: @node Trouble, Service, Installation, Top
2408: @chapter Known Causes of Trouble with GNU CC
1.1 root 2409:
2410: Here are some of the things that have caused trouble for people installing
2411: or using GNU CC.
2412:
2413: @itemize @bullet
2414: @item
2415: On certain systems, defining certain environment variables such as
1.1.1.8 root 2416: @code{CC} can interfere with the functioning of @code{make}.
1.1 root 2417:
2418: @item
2419: Cross compilation can run into trouble for certain machines because
2420: some target machines' assemblers require floating point numbers to be
2421: written as @emph{integer} constants in certain contexts.
2422:
2423: The compiler writes these integer constants by examining the floating
2424: point value as an integer and printing that integer, because this is
2425: simple to write and independent of the details of the floating point
2426: representation. But this does not work if the compiler is running on
2427: a different machine with an incompatible floating point format, or
2428: even a different byte-ordering.
2429:
1.1.1.5 root 2430: In addition, correct constant folding of floating point values
2431: requires representing them in the target machine's format.
2432: (The C standard does not quite require this, but in practice
2433: it is the only way to win.)
2434:
2435: It is now possible to overcome these problems by defining macros such
2436: as @code{REAL_VALUE_TYPE}. But doing so is a substantial amount of
2437: work for each target machine. @xref{Cross-compilation}.
1.1 root 2438:
2439: @item
1.1.1.2 root 2440: Users often think it is a bug when GNU CC reports an error for code
2441: like this:
2442:
2443: @example
2444: int foo (short);
2445:
2446: int foo (x)
2447: short x;
2448: @{@dots{}@}
2449: @end example
2450:
1.1.1.4 root 2451: The error message is correct: this code really is erroneous, because the
2452: old-style non-prototype definition passes subword integers in their
2453: promoted types. In other words, the argument is really an @code{int},
2454: not a @code{short}. The correct prototype is this:
1.1.1.2 root 2455:
2456: @example
2457: int foo (int);
2458: @end example
2459:
2460: @item
2461: Users often think it is a bug when GNU CC reports an error for code
2462: like this:
2463:
2464: @example
2465: int foo (struct mumble *);
2466:
2467: struct mumble @{ @dots{} @};
2468:
2469: int foo (struct mumble *x)
2470: @{ @dots{} @}
2471: @end example
2472:
2473: This code really is erroneous, because the scope of @code{struct
2474: mumble} the prototype is limited to the argument list containing it.
2475: It does not refer to the @code{struct mumble} defined with file scope
2476: immediately below---they are two unrelated types with similar names in
2477: different scopes.
2478:
2479: But in the definition of @code{foo}, the file-scope type is used
2480: because that is available to be inherited. Thus, the definition and
2481: the prototype do not match, and you get an error.
2482:
2483: This behavior may seem silly, but it's what the ANSI standard
2484: specifies. It is easy enough for you to make your code work by moving
2485: the definition of @code{struct mumble} above the prototype. I don't
2486: think it's worth being incompatible for.
1.1 root 2487: @end itemize
2488:
1.1.1.12 root 2489: Additional problems are described in @ref{Incompatibilities}.
2490:
1.1.1.10 root 2491: @node Service, Incompatibilities, Trouble, Top
2492: @chapter How To Get Help with GNU CC
2493:
2494: If you need help installing, using or changing GNU CC, there are two
2495: ways to find it:
2496:
2497: @itemize @bullet
2498: @item
2499: Send a message to a suitable network mailing list. First try
2500: @code{bug-gcc@@prep.ai.mit.edu}, and if that brings no response, try
1.1.1.12 root 2501: @code{help-gcc@@prep.ai.mit.edu}.
1.1.1.10 root 2502:
2503: @item
2504: Look in the service directory for someone who might help you for a fee.
2505: The service directory is found in the file named @file{SERVICE} in the
2506: GNU CC distribution.
2507: @end itemize
2508:
2509: @node Incompatibilities, Extensions, Service, Top
1.1 root 2510: @chapter Incompatibilities of GNU CC
2511:
2512: There are several noteworthy incompatibilities between GNU C and most
1.1.1.9 root 2513: existing (non-ANSI) versions of C. The @samp{-traditional} option
2514: eliminates most of these incompatibilities, @emph{but not all}, by
2515: telling GNU C to behave like older C compilers.
1.1 root 2516:
2517: @itemize @bullet
2518: @item
2519: GNU CC normally makes string constants read-only. If several
2520: identical-looking string constants are used, GNU CC stores only one
2521: copy of the string.
2522:
2523: One consequence is that you cannot call @code{mktemp} with a string
2524: constant argument. The function @code{mktemp} always alters the
2525: string its argument points to.
2526:
2527: Another consequence is that @code{sscanf} does not work on some
2528: systems when passed a string constant as its format control string.
2529: This is because @code{sscanf} incorrectly tries to write into the
1.1.1.4 root 2530: string constant. Likewise @code{fscanf} and @code{scanf}.
1.1 root 2531:
2532: The best solution to these problems is to change the program to use
2533: @code{char}-array variables with initialization strings for these
2534: purposes instead of string constants. But if this is not possible,
2535: you can use the @samp{-fwritable-strings} flag, which directs GNU CC
2536: to handle string constants the same way most C compilers do.
1.1.1.8 root 2537: @samp{-traditional} also has this effect, among others.
1.1 root 2538:
2539: @item
2540: GNU CC does not substitute macro arguments when they appear inside of
2541: string constants. For example, the following macro in GNU CC
2542:
2543: @example
2544: #define foo(a) "a"
2545: @end example
2546:
2547: @noindent
1.1.1.8 root 2548: will produce output @code{"a"} regardless of what the argument @var{a} is.
1.1 root 2549:
2550: The @samp{-traditional} option directs GNU CC to handle such cases
2551: (among others) in the old-fashioned (non-ANSI) fashion.
2552:
2553: @item
2554: When you use @code{setjmp} and @code{longjmp}, the only automatic
2555: variables guaranteed to remain valid are those declared
2556: @code{volatile}. This is a consequence of automatic register
2557: allocation. Consider this function:
2558:
2559: @example
2560: jmp_buf j;
2561:
2562: foo ()
2563: @{
2564: int a, b;
2565:
2566: a = fun1 ();
2567: if (setjmp (j))
2568: return a;
2569:
2570: a = fun2 ();
2571: /* @r{@code{longjmp (j)} may be occur in @code{fun3}.} */
2572: return a + fun3 ();
2573: @}
2574: @end example
2575:
2576: Here @code{a} may or may not be restored to its first value when the
2577: @code{longjmp} occurs. If @code{a} is allocated in a register, then
2578: its first value is restored; otherwise, it keeps the last value stored
2579: in it.
2580:
2581: If you use the @samp{-W} option with the @samp{-O} option, you will
2582: get a warning when GNU CC thinks such a problem might be possible.
2583:
1.1.1.2 root 2584: The @samp{-traditional} option directs GNU C to put variables in
2585: the stack by default, rather than in registers, in functions that
2586: call @code{setjmp}. This results in the behavior found in
2587: traditional C compilers.
2588:
1.1 root 2589: @item
2590: Declarations of external variables and functions within a block apply
2591: only to the block containing the declaration. In other words, they
2592: have the same scope as any other declaration in the same place.
2593:
2594: In some other C compilers, a @code{extern} declaration affects all the
2595: rest of the file even if it happens within a block.
2596:
2597: The @samp{-traditional} option directs GNU C to treat all @code{extern}
2598: declarations as global, like traditional compilers.
2599:
2600: @item
2601: In traditional C, you can combine @code{long}, etc., with a typedef name,
2602: as shown here:
2603:
2604: @example
2605: typedef int foo;
2606: typedef long foo bar;
2607: @end example
2608:
2609: In ANSI C, this is not allowed: @code{long} and other type modifiers
2610: require an explicit @code{int}. Because this criterion is expressed
2611: by Bison grammar rules rather than C code, the @samp{-traditional}
2612: flag cannot alter it.
2613:
2614: @item
2615: PCC allows typedef names to be used as function parameters. The
2616: difficulty described immediately above applies here too.
2617:
2618: @item
2619: PCC allows whitespace in the middle of compound assignment operators
2620: such as @samp{+=}. GNU CC, following the ANSI standard, does not
2621: allow this. The difficulty described immediately above applies here
2622: too.
2623:
2624: @item
2625: GNU CC will flag unterminated character constants inside of preprocessor
2626: conditionals that fail. Some programs have English comments enclosed in
2627: conditionals that are guaranteed to fail; if these comments contain
2628: apostrophes, GNU CC will probably report an error. For example,
2629: this code would produce an error:
2630:
2631: @example
2632: #if 0
2633: You can't expect this to work.
2634: #endif
2635: @end example
2636:
2637: The best solution to such a problem is to put the text into an actual
2638: C comment delimited by @samp{/*@dots{}*/}. However,
2639: @samp{-traditional} suppresses these error messages.
2640:
2641: @item
2642: When compiling functions that return @code{float}, PCC converts it to
2643: a double. GNU CC actually returns a @code{float}. If you are concerned
2644: with PCC compatibility, you should declare your functions to return
2645: @code{double}; you might as well say what you mean.
2646:
2647: @item
2648: When compiling functions that return structures or unions, GNU CC
1.1.1.6 root 2649: output code normally uses a method different from that used on most
2650: versions of Unix. As a result, code compiled with GNU CC cannot call
2651: a structure-returning function compiled with PCC, and vice versa.
1.1 root 2652:
1.1.1.6 root 2653: The method used by GNU CC is as follows: a structure or union which is 1,
1.1 root 2654: 2, 4 or 8 bytes long is returned like a scalar. A structure or union
2655: with any other size is stored into an address supplied by the caller
2656: in a special, fixed register.
2657:
2658: PCC usually handles all sizes of structures and unions by returning
2659: the address of a block of static storage containing the value. This
1.1.1.6 root 2660: method is not used in GNU CC because it is slower and nonreentrant.
1.1.1.5 root 2661:
1.1.1.6 root 2662: You can tell GNU CC to use the PCC convention with the option
2663: @samp{-fpcc-struct-return}.
1.1.1.12 root 2664: @end itemize
1.1.1.8 root 2665:
1.1.1.12 root 2666: There are also system-specific incompatibilities.
2667:
2668: @itemize @bullet
1.1.1.8 root 2669: @item
2670: On the Sparc, GNU CC uses an incompatible calling convention for
1.1.1.13! root 2671: structures and unions. It passes them by including their contents in
! 2672: the argument list, whereas the standard compiler passes them effectively
! 2673: by reference.
! 2674:
! 2675: This is hard to fix in GCC version 1. GNU CC version 2 will use a
! 2676: compatible calling convention.
! 2677:
! 2678: The convention for structure or union returning is also incompatible,
! 2679: and @samp{-fpcc-struct-return} does not help.
! 2680:
! 2681: System functions which can't be called properly from code compiled with
! 2682: GCC include @code{fetch}, @code{store}, @code{delete}, @code{firstkey},
! 2683: @code{nextkey}, @code{inet_makeaddr}, @code{inet_lnaof},
! 2684: @code{inet_netof}, @code{inet_ntoa}, @code{mallinfo},
! 2685: @code{pmap_rmtcall}, @code{clnt_call}, @code{clntudp_bufcreate} and
! 2686: @code{clntudp_create}.
1.1.1.8 root 2687:
1.1.1.13! root 2688: @item
! 2689: One consequence of the unusual calling convention used on the Sparc
! 2690: is that structures with less than word alignment do not work right
! 2691: when passed as arguments to varargs functions.
! 2692:
! 2693: It's not easy to fix this problem. In any case, it will be gone in
! 2694: version 2 as a result of the changed calling convention.
1.1.1.10 root 2695:
1.1.1.12 root 2696: @item
2697: The Sparc version of @code{setjmp} interacts badly with unexpected stack
2698: adjustments. With rare exceptions, you cannot use @code{setjmp} in a
2699: function which moves the stack pointer.
2700:
2701: In the current version of GNU CC, there are three ways that the stack
2702: pointer can change value: (1) calls to @code{alloca}, (2) use of
2703: variable-sized objects, and (3) calls to functions with parameters that
2704: do not all fit in the argument-passing registers (e.g., more than 6
2705: parameters). You should avoid all three in functions that call
2706: @code{setjmp}.
2707:
2708: The cause of the problem is the way that Sun implemented register
2709: windows. The 64 bytes at addresses @code{%sp} through @code{%sp+63}
2710: correspond to the register window save area. When a register window
2711: must be spilled, its stack pointer is located, and the registers are
2712: dumped starting at that address. Similarly, when a register window must
2713: be restored, its stack pointer is located, and the registers are
2714: restored from that address.
2715:
2716: When @code{setjmp} is called, the current register window's registers
2717: are saved into the register save area, and when @code{longjmp} is
2718: called, they are restored (actually, @emph{all} register windows are
2719: restored from all valid register windows at the time @code{longjmp} is
2720: called). If there is a change in the value of the stack pointer bewteen
2721: the @code{setjmp} and @code{longjmp} calls, when the registers are
2722: restored, they are restored with random values.
2723:
1.1.1.10 root 2724: @item
2725: On Ultrix, the Fortran compiler expects registers 2 through 5 to be saved
1.1.1.13! root 2726: by function calls. However, the C compiler uses conventions compatible
! 2727: with BSD Unix: registers 2 through 5 may be clobbered by function calls.
! 2728:
! 2729: GNU CC uses the same convention as the Ultrix C compiler. You can use
! 2730: these options to produce code compatible with the Fortran compiler:
1.1.1.10 root 2731:
2732: @example
2733: -fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
2734: @end example
1.1.1.12 root 2735:
2736: @item
2737: DBX rejects some files produced by GNU CC, though it accepts similar
2738: constructs in output from PCC. Until someone can supply a coherent
2739: description of what is valid DBX input and what is not, there is
2740: nothing I can do about these problems. You are on your own.
1.1 root 2741: @end itemize
2742:
2743: @node Extensions, Bugs, Incompatibilities, Top
2744: @chapter GNU Extensions to the C Language
2745:
2746: GNU C provides several language features not found in ANSI standard C.
2747: (The @samp{-pedantic} option directs GNU CC to print a warning message if
2748: any of these features is used.) To test for the availability of these
2749: features in conditional compilation, check for a predefined macro
2750: @code{__GNUC__}, which is always defined under GNU CC.
2751:
2752: @menu
2753: * Statement Exprs:: Putting statements and declarations inside expressions.
2754: * Naming Types:: Giving a name to the type of some expression.
1.1.1.9 root 2755: * Typeof:: @code{typeof}: referring to the type of an expression.
2756: * Lvalues:: Using @samp{?:}, @samp{,} and casts in lvalues.
2757: * Conditionals:: Omitting the middle operand of a @samp{?:} expression.
2758: * Zero-Length:: Zero-length arrays.
2759: * Variable-Length:: Arrays whose length is computed at run time.
2760: * Subscripting:: Any array can be subscripted, even if not an lvalue.
2761: * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers.
2762: * Initializers:: Non-constant initializers.
2763: * Constructors:: Constructor expressions give structures, unions
2764: or arrays as values.
1.1.1.5 root 2765: * Function Attributes:: Declaring that functions have no side effects,
1.1.1.9 root 2766: or that they can never return.
1.1 root 2767: * Dollar Signs:: Dollar sign is allowed in identifiers.
2768: * Alignment:: Inquiring about the alignment of a type or variable.
2769: * Inline:: Defining inline functions (as fast as macros).
1.1.1.9 root 2770: * Extended Asm:: Assembler instructions with C expressions as operands.
2771: (With them you can define ``built-in'' functions.)
2772: * Asm Labels:: Specifying the assembler name to use for a C symbol.
1.1.1.8 root 2773: * Explicit Reg Vars:: Defining variables residing in specified registers.
2774: * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files.
1.1 root 2775: @end menu
2776:
2777: @node Statement Exprs, Naming Types, Extensions, Extensions
2778: @section Statements and Declarations inside of Expressions
2779:
2780: A compound statement in parentheses may appear inside an expression in GNU
2781: C. This allows you to declare variables within an expression. For
2782: example:
2783:
2784: @example
2785: (@{ int y = foo (); int z;
2786: if (y > 0) z = y;
2787: else z = - y;
2788: z; @})
2789: @end example
2790:
2791: @noindent
2792: is a valid (though slightly more complex than necessary) expression
2793: for the absolute value of @code{foo ()}.
2794:
2795: This feature is especially useful in making macro definitions ``safe'' (so
2796: that they evaluate each operand exactly once). For example, the
2797: ``maximum'' function is commonly defined as a macro in standard C as
2798: follows:
2799:
2800: @example
2801: #define max(a,b) ((a) > (b) ? (a) : (b))
2802: @end example
2803:
2804: @noindent
2805: But this definition computes either @var{a} or @var{b} twice, with bad
2806: results if the operand has side effects. In GNU C, if you know the
2807: type of the operands (here let's assume @code{int}), you can define
2808: the macro safely as follows:
2809:
2810: @example
2811: #define maxint(a,b) \
2812: (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
2813: @end example
2814:
2815: Embedded statements are not allowed in constant expressions, such as
2816: the value of an enumeration constant, the width of a bit field, or
2817: the initial value of a static variable.
2818:
2819: If you don't know the type of the operand, you can still do this, but you
2820: must use @code{typeof} (@pxref{Typeof}) or type naming (@pxref{Naming
2821: Types}).
2822:
2823: @node Naming Types, Typeof, Statement Exprs, Extensions
2824: @section Naming an Expression's Type
2825:
2826: You can give a name to the type of an expression using a @code{typedef}
2827: declaration with an initializer. Here is how to define @var{name} as a
2828: type name for the type of @var{exp}:
2829:
2830: @example
2831: typedef @var{name} = @var{exp};
2832: @end example
2833:
2834: This is useful in conjunction with the statements-within-expressions
2835: feature. Here is how the two together can be used to define a safe
2836: ``maximum'' macro that operates on any arithmetic type:
2837:
2838: @example
2839: #define max(a,b) \
2840: (@{typedef _ta = (a), _tb = (b); \
2841: _ta _a = (a); _tb _b = (b); \
2842: _a > _b ? _a : _b; @})
2843: @end example
2844:
2845: The reason for using names that start with underscores for the local
2846: variables is to avoid conflicts with variable names that occur within the
2847: expressions that are substituted for @code{a} and @code{b}. Eventually we
2848: hope to design a new form of declaration syntax that allows you to declare
2849: variables whose scopes start only after their initializers; this will be a
2850: more reliable way to prevent such conflicts.
2851:
2852: @node Typeof, Lvalues, Naming Types, Extensions
2853: @section Referring to a Type with @code{typeof}
2854:
2855: Another way to refer to the type of an expression is with @code{typeof}.
2856: The syntax of using of this keyword looks like @code{sizeof}, but the
2857: construct acts semantically like a type name defined with @code{typedef}.
2858:
2859: There are two ways of writing the argument to @code{typeof}: with an
2860: expression or with a type. Here is an example with an expression:
2861:
2862: @example
2863: typeof (x[0](1))
2864: @end example
2865:
2866: @noindent
2867: This assumes that @code{x} is an array of functions; the type described
2868: is that of the values of the functions.
2869:
2870: Here is an example with a typename as the argument:
2871:
2872: @example
2873: typeof (int *)
2874: @end example
2875:
2876: @noindent
2877: Here the type described is that of pointers to @code{int}.
2878:
1.1.1.7 root 2879: If you are writing a header file that must work when included in ANSI C
1.1.1.8 root 2880: programs, write @code{__typeof__} instead of @code{typeof}.
1.1.1.7 root 2881: @xref{Alternate Keywords}.
2882:
1.1 root 2883: A @code{typeof}-construct can be used anywhere a typedef name could be
2884: used. For example, you can use it in a declaration, in a cast, or inside
2885: of @code{sizeof} or @code{typeof}.
2886:
2887: @itemize @bullet
2888: @item
2889: This declares @code{y} with the type of what @code{x} points to.
2890:
2891: @example
2892: typeof (*x) y;
2893: @end example
2894:
2895: @item
2896: This declares @code{y} as an array of such values.
2897:
2898: @example
2899: typeof (*x) y[4];
2900: @end example
2901:
2902: @item
2903: This declares @code{y} as an array of pointers to characters:
2904:
2905: @example
2906: typeof (typeof (char *)[4]) y;
2907: @end example
2908:
2909: @noindent
2910: It is equivalent to the following traditional C declaration:
2911:
2912: @example
2913: char *y[4];
2914: @end example
2915:
2916: To see the meaning of the declaration using @code{typeof}, and why it
2917: might be a useful way to write, let's rewrite it with these macros:
2918:
2919: @example
2920: #define pointer(T) typeof(T *)
2921: #define array(T, N) typeof(T [N])
2922: @end example
2923:
2924: @noindent
2925: Now the declaration can be rewritten this way:
2926:
2927: @example
2928: array (pointer (char), 4) y;
2929: @end example
2930:
2931: @noindent
1.1.1.8 root 2932: Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
1.1 root 2933: pointers to @code{char}.
2934: @end itemize
2935:
2936: @node Lvalues, Conditionals, Typeof, Extensions
2937: @section Generalized Lvalues
2938:
2939: Compound expressions, conditional expressions and casts are allowed as
2940: lvalues provided their operands are lvalues. This means that you can take
2941: their addresses or store values into them.
2942:
2943: For example, a compound expression can be assigned, provided the last
2944: expression in the sequence is an lvalue. These two expressions are
2945: equivalent:
2946:
2947: @example
2948: (a, b) += 5
2949: a, (b += 5)
2950: @end example
2951:
2952: Similarly, the address of the compound expression can be taken. These two
2953: expressions are equivalent:
2954:
2955: @example
2956: &(a, b)
2957: a, &b
2958: @end example
2959:
2960: A conditional expression is a valid lvalue if its type is not void and the
2961: true and false branches are both valid lvalues. For example, these two
2962: expressions are equivalent:
2963:
2964: @example
2965: (a ? b : c) = 5
2966: (a ? b = 5 : (c = 5))
2967: @end example
2968:
1.1.1.13! root 2969: A cast is a valid lvalue if its operand is an lvalue. A simple
! 2970: assignment whose left-hand side is a cast works by converting the
! 2971: right-hand side first to the specified type, then to the type of the
! 2972: inner left-hand side expression. After this is stored, the value is
! 2973: converted back to the specified type to become the value of the
! 2974: assignment. Thus, if @code{a} has type @code{char *}, the following two
! 2975: expressions are equivalent:
1.1 root 2976:
2977: @example
2978: (int)a = 5
1.1.1.13! root 2979: (int)(a = (char *)(int)5)
1.1 root 2980: @end example
2981:
2982: An assignment-with-arithmetic operation such as @samp{+=} applied to a cast
2983: performs the arithmetic using the type resulting from the cast, and then
2984: continues as in the previous case. Therefore, these two expressions are
2985: equivalent:
2986:
2987: @example
2988: (int)a += 5
1.1.1.13! root 2989: (int)(a = (char *)(int) ((int)a + 5))
! 2990: @end example
! 2991:
! 2992: You cannot take the address of an lvalue cast, because the use of its
! 2993: address would not work out coherently. Suppose that @code{&(int)f} were
! 2994: permitted, where @code{f} has type @code{float}. Then the following
! 2995: statement would try to store an integer bit-pattern where a floating
! 2996: point number belongs:
! 2997:
! 2998: @example
! 2999: *&(int)f = 1;
1.1 root 3000: @end example
3001:
1.1.1.13! root 3002: This is quite different from what @code{(int)f = 1} would do---that
! 3003: would convert 1 to floating point and store it. Rather than cause this
! 3004: inconsistancy, we think it is better to prohibit use of @samp{&} on a cast.
! 3005:
! 3006: If you really do want an @code{int *} pointer with the address of
! 3007: @code{f}, you can simply write @code{(int *)&f}.
! 3008:
1.1 root 3009: @node Conditionals, Zero-Length, Lvalues, Extensions
3010: @section Conditional Expressions with Omitted Middle-Operands
3011:
3012: The middle operand in a conditional expression may be omitted. Then
3013: if the first operand is nonzero, its value is the value of the conditional
3014: expression.
3015:
3016: Therefore, the expression
3017:
3018: @example
3019: x ? : y
3020: @end example
3021:
3022: @noindent
3023: has the value of @code{x} if that is nonzero; otherwise, the value of
3024: @code{y}.
3025:
3026: This example is perfectly equivalent to
3027:
3028: @example
3029: x ? x : y
3030: @end example
3031:
3032: @noindent
3033: In this simple case, the ability to omit the middle operand is not
3034: especially useful. When it becomes useful is when the first operand does,
3035: or may (if it is a macro argument), contain a side effect. Then repeating
3036: the operand in the middle would perform the side effect twice. Omitting
3037: the middle operand uses the value already computed without the undesirable
3038: effects of recomputing it.
3039:
3040: @node Zero-Length, Variable-Length, Conditionals, Extensions
3041: @section Arrays of Length Zero
3042:
3043: Zero-length arrays are allowed in GNU C. They are very useful as the last
3044: element of a structure which is really a header for a variable-length
3045: object:
3046:
3047: @example
3048: struct line @{
3049: int length;
3050: char contents[0];
3051: @};
3052:
3053: @{
3054: struct line *thisline
3055: = (struct line *) malloc (sizeof (struct line) + this_length);
3056: thisline->length = this_length;
3057: @}
3058: @end example
3059:
3060: In standard C, you would have to give @code{contents} a length of 1, which
3061: means either you waste space or complicate the argument to @code{malloc}.
3062:
3063: @node Variable-Length, Subscripting, Zero-Length, Extensions
3064: @section Arrays of Variable Length
3065:
3066: Variable-length automatic arrays are allowed in GNU C. These arrays are
3067: declared like any other automatic arrays, but with a length that is not a
3068: constant expression. The storage is allocated at that time and
3069: deallocated when the brace-level is exited. For example:
3070:
3071: @example
3072: FILE *concat_fopen (char *s1, char *s2, char *mode)
3073: @{
3074: char str[strlen (s1) + strlen (s2) + 1];
3075: strcpy (str, s1);
3076: strcat (str, s2);
3077: return fopen (str, mode);
3078: @}
3079: @end example
3080:
1.1.1.7 root 3081: You can also use variable-length arrays as arguments to functions:
1.1 root 3082:
3083: @example
3084: struct entry
1.1.1.7 root 3085: tester (int len, char data[len])
1.1 root 3086: @{
1.1.1.7 root 3087: @dots{}
1.1 root 3088: @}
3089: @end example
3090:
3091: The length of an array is computed on entry to the brace-level where the
3092: array is declared and is remembered for the scope of the array in case you
3093: access it with @code{sizeof}.
3094:
3095: Jumping or breaking out of the scope of the array name will also deallocate
3096: the storage. Jumping into the scope is not allowed; you will get an error
3097: message for it.
3098:
3099: You can use the function @code{alloca} to get an effect much like
3100: variable-length arrays. The function @code{alloca} is available in
3101: many other C implementations (but not in all). On the other hand,
3102: variable-length arrays are more elegant.
3103:
3104: There are other differences between these two methods. Space allocated
3105: with @code{alloca} exists until the containing @emph{function} returns.
3106: The space for a variable-length array is deallocated as soon as the array
3107: name's scope ends. (If you use both variable-length arrays and
3108: @code{alloca} in the same function, deallocation of a variable-length array
3109: will also deallocate anything more recently allocated with @code{alloca}.)
3110:
3111: @node Subscripting, Pointer Arith, Variable-Length, Extensions
3112: @section Non-Lvalue Arrays May Have Subscripts
3113:
3114: Subscripting is allowed on arrays that are not lvalues, even though the
3115: unary @samp{&} operator is not. For example, this is valid in GNU C though
3116: not valid in other C dialects:
3117:
3118: @example
3119: struct foo @{int a[4];@};
3120:
3121: struct foo f();
3122:
3123: bar (int index)
3124: @{
3125: return f().a[index];
3126: @}
3127: @end example
3128:
3129: @node Pointer Arith, Initializers, Subscripting, Extensions
3130: @section Arithmetic on @code{void}-Pointers and Function Pointers
3131:
3132: In GNU C, addition and subtraction operations are supported on pointers to
3133: @code{void} and on pointers to functions. This is done by treating the
3134: size of a @code{void} or of a function as 1.
3135:
3136: A consequence of this is that @code{sizeof} is also allowed on @code{void}
3137: and on function types, and returns 1.
3138:
1.1.1.8 root 3139: The option @samp{-Wpointer-arith} requests a warning if these extensions
3140: are used.
3141:
1.1 root 3142: @node Initializers, Constructors, Pointer Arith, Extensions
3143: @section Non-Constant Initializers
3144:
1.1.1.8 root 3145: The elements of an aggregate initializer for an automatic variable are
3146: not required to be constant expressions in GNU C. Here is an example of
3147: an initializer with run-time varying elements:
1.1 root 3148:
3149: @example
3150: foo (float f, float g)
3151: @{
3152: float beat_freqs[2] = @{ f-g, f+g @};
3153: @dots{}
3154: @}
3155: @end example
3156:
1.1.1.5 root 3157: @node Constructors, Function Attributes, Initializers, Extensions
1.1 root 3158: @section Constructor Expressions
3159:
3160: GNU C supports constructor expressions. A constructor looks like a cast
3161: containing an initializer. Its value is an object of the type specified in
3162: the cast, containing the elements specified in the initializer. The type
3163: must be a structure, union or array type.
3164:
3165: Assume that @code{struct foo} and @code{structure} are declared as shown:
3166:
3167: @example
3168: struct foo @{int a; char b[2];@} structure;
3169: @end example
3170:
3171: @noindent
1.1.1.8 root 3172: Here is an example of constructing a @code{struct foo} with a constructor:
1.1 root 3173:
3174: @example
3175: structure = ((struct foo) @{x + y, 'a', 0@});
3176: @end example
3177:
3178: @noindent
3179: This is equivalent to writing the following:
3180:
3181: @example
3182: @{
3183: struct foo temp = @{x + y, 'a', 0@};
3184: structure = temp;
3185: @}
3186: @end example
3187:
3188: You can also construct an array. If all the elements of the constructor
3189: are (made up of) simple constant expressions, suitable for use in
3190: initializers, then the constructor is an lvalue and can be coerced to a
3191: pointer to its first element, as shown here:
3192:
3193: @example
3194: char **foo = (char *[]) @{ "x", "y", "z" @};
3195: @end example
3196:
3197: Array constructors whose elements are not simple constants are not very
3198: useful, because the constructor is not an lvalue. There are only two valid
3199: ways to use it: to subscript it, or initialize an array variable with it.
3200: The former is probably slower than a @code{switch} statement, while the
3201: latter does the same thing an ordinary C initializer would do.
3202:
3203: @example
3204: output = ((int[]) @{ 2, x, 28 @}) [input];
3205: @end example
3206:
1.1.1.8 root 3207: @node Function Attributes, Dollar Signs, Constructors, Extensions
1.1.1.5 root 3208: @section Declaring Attributes of Functions
3209:
3210: In GNU C, you declare certain things about functions called in your program
3211: which help the compiler optimize function calls.
3212:
3213: A few functions, such as @code{abort} and @code{exit}, cannot return.
3214: These functions should be declared @code{volatile}. For example,
3215:
3216: @example
3217: extern volatile void abort ();
3218: @end example
3219:
3220: @noindent
3221: tells the compiler that it can assume that @code{abort} will not return.
3222: This makes slightly better code, but more importantly it helps avoid
3223: spurious warnings of uninitialized variables.
3224:
3225: Many functions do not examine any values except their arguments, and
3226: have no effects except the return value. Such a function can be subject
3227: to common subexpression elimination and loop optimization just as an
3228: arithmetic operator would be. These functions should be declared
3229: @code{const}. For example,
3230:
3231: @example
1.1.1.13! root 3232: extern const int square ();
1.1.1.5 root 3233: @end example
3234:
3235: @noindent
3236: says that the hypothetical function @code{square} is safe to call
3237: fewer times than the program says.
3238:
3239: Note that a function that has pointer arguments and examines the data
3240: pointed to must @emph{not} be declared @code{const}. Likewise, a
1.1.1.10 root 3241: function that calls a non-@code{const} function usually must not be
1.1.1.5 root 3242: @code{const}.
3243:
3244: Some people object to this feature, claiming that ANSI C's @code{#pragma}
3245: should be used instead. There are two reasons I did not do this.
3246:
3247: @enumerate
3248: @item
3249: It is impossible to generate @code{#pragma} commands from a macro.
3250:
3251: @item
3252: The @code{#pragma} command is just as likely as these keywords to mean
3253: something else in another compiler.
3254: @end enumerate
3255:
3256: These two reasons apply to @emph{any} application whatever: as far as
3257: I can see, @code{#pragma} is never useful.
3258:
3259: @node Dollar Signs, Alignment, Function Attributes, Extensions
1.1 root 3260: @section Dollar Signs in Identifier Names
3261:
3262: In GNU C, you may use dollar signs in identifier names. This is because
3263: many traditional C implementations allow such identifiers.
3264:
1.1.1.9 root 3265: Dollar signs are allowed if you specify @samp{-traditional}; they are
3266: not allowed if you specify @samp{-ansi}. Whether they are allowed by
3267: default depends on the target machine; usually, they are not.
3268:
1.1 root 3269: @node Alignment, Inline, Dollar Signs, Extensions
3270: @section Inquiring about the Alignment of a Type or Variable
3271:
1.1.1.8 root 3272: The keyword @code{__alignof__} allows you to inquire about how an object
1.1 root 3273: is aligned, or the minimum alignment usually required by a type. Its
3274: syntax is just like @code{sizeof}.
3275:
3276: For example, if the target machine requires a @code{double} value to be
1.1.1.8 root 3277: aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
3278: This is true on many RISC machines. On more traditional machine
3279: designs, @code{__alignof__ (double)} is 4 or even 2.
1.1 root 3280:
3281: Some machines never actually require alignment; they allow reference to any
1.1.1.8 root 3282: data type even at an odd addresses. For these machines, @code{__alignof__}
1.1 root 3283: reports the @emph{recommended} alignment of a type.
3284:
1.1.1.8 root 3285: When the operand of @code{__alignof__} is an lvalue rather than a type, the
1.1 root 3286: value is the largest alignment that the lvalue is known to have. It may
3287: have this alignment as a result of its data type, or because it is part of
3288: a structure and inherits alignment from that structure. For example, after
3289: this declaration:
3290:
3291: @example
3292: struct foo @{ int x; char y; @} foo1;
3293: @end example
3294:
3295: @noindent
1.1.1.8 root 3296: the value of @code{__alignof__ (foo1.y)} is probably 2 or 4, the same as
3297: @code{__alignof__ (int)}, even though the data type of @code{foo1.y}
3298: does not itself demand any alignment.@refill
1.1 root 3299:
3300: @node Inline, Extended Asm, Alignment, Extensions
3301: @section An Inline Function is As Fast As a Macro
3302:
3303: By declaring a function @code{inline}, you can direct GNU CC to integrate
3304: that function's code into the code for its callers. This makes execution
3305: faster by eliminating the function-call overhead; in addition, if any of
3306: the actual argument values are constant, their known values may permit
3307: simplifications at compile time so that not all of the inline function's
3308: code needs to be included.
3309:
3310: To declare a function inline, use the @code{inline} keyword in its
3311: declaration, like this:
3312:
3313: @example
3314: inline int
3315: inc (int *a)
3316: @{
3317: (*a)++;
3318: @}
3319: @end example
3320:
1.1.1.7 root 3321: (If you are writing a header file to be included in ANSI C programs, write
1.1.1.8 root 3322: @code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.)
1.1.1.7 root 3323:
3324: You can also make all ``simple enough'' functions inline with the option
3325: @samp{-finline-functions}. Note that certain usages in a function
3326: definition can make it unsuitable for inline substitution.
1.1 root 3327:
3328: When a function is both inline and @code{static}, if all calls to the
1.1.1.8 root 3329: function are integrated into the caller, and the function's address is
3330: never used, then the function's own assembler code is never referenced.
3331: In this case, GNU CC does not actually output assembler code for the
3332: function, unless you specify the option @samp{-fkeep-inline-functions}.
3333: Some calls cannot be integrated for various reasons (in particular,
3334: calls that precede the function's definition cannot be integrated, and
3335: neither can recursive calls within the definition). If there is a
3336: nonintegrated call, then the function is compiled to assembler code as
3337: usual. The function must also be compiled as usual if the program
3338: refers to its address, because that can't be inlined.
1.1 root 3339:
3340: When an inline function is not @code{static}, then the compiler must assume
3341: that there may be calls from other source files; since a global symbol can
3342: be defined only once in any program, the function must not be defined in
3343: the other source files, so the calls therein cannot be integrated.
3344: Therefore, a non-@code{static} inline function is always compiled on its
3345: own in the usual fashion.
3346:
1.1.1.8 root 3347: If you specify both @code{inline} and @code{extern} in the function
3348: definition, then the definition is used only for inlining. In no case
3349: is the function compiled on its own, not even if you refer to its
3350: address explicitly. Such an address becomes an external reference, as
3351: if you had only declared the function, and had not defined it.
3352:
3353: This combination of @code{inline} and @code{extern} has almost the
3354: effect of a macro. The way to use it is to put a function definition in
3355: a header file with these keywords, and put another copy of the
3356: definition (lacking @code{inline} and @code{extern}) in a library file.
3357: The definition in the header file will cause most calls to the function
3358: to be inlined. If any uses of the function remain, they will refer to
3359: the single copy in the library.
3360:
1.1 root 3361: @node Extended Asm, Asm Labels, Inline, Extensions
3362: @section Assembler Instructions with C Expression Operands
3363:
3364: In an assembler instruction using @code{asm}, you can now specify the
3365: operands of the instruction using C expressions. This means no more
3366: guessing which registers or memory locations will contain the data you want
3367: to use.
3368:
3369: You must specify an assembler instruction template much like what appears
3370: in a machine description, plus an operand constraint string for each
3371: operand.
3372:
3373: For example, here is how to use the 68881's @code{fsinx} instruction:
3374:
3375: @example
3376: asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
3377: @end example
3378:
3379: @noindent
3380: Here @code{angle} is the C expression for the input operand while
3381: @code{result} is that of the output operand. Each has @samp{"f"} as its
3382: operand constraint, saying that a floating-point register is required. The
1.1.1.5 root 3383: @samp{=} in @samp{=f} indicates that the operand is an output; all output
1.1.1.4 root 3384: operands' constraints must use @samp{=}. The constraints use the same
3385: language used in the machine description (@pxref{Constraints}).
1.1 root 3386:
3387: Each operand is described by an operand-constraint string followed by the C
3388: expression in parentheses. A colon separates the assembler template from
3389: the first output operand, and another separates the last output operand
3390: from the first input, if any. Commas separate output operands and separate
1.1.1.4 root 3391: inputs. The total number of operands is limited to the maximum number of
1.1 root 3392: operands in any instruction pattern in the machine description.
3393:
1.1.1.4 root 3394: If there are no output operands, and there are input operands, then there
3395: must be two consecutive colons surrounding the place where the output
3396: operands would go.
3397:
1.1 root 3398: Output operand expressions must be lvalues; the compiler can check this.
3399: The input operands need not be lvalues. The compiler cannot check whether
3400: the operands have data types that are reasonable for the instruction being
3401: executed. It does not parse the assembler instruction template and does
3402: not know what it means, or whether it is valid assembler input. The
3403: extended @code{asm} feature is most often used for machine instructions
3404: that the compiler itself does not know exist.
3405:
3406: The output operands must be write-only; GNU CC will assume that the values
3407: in these operands before the instruction are dead and need not be
1.1.1.8 root 3408: generated. Extended asm does not support input-output or read-write
3409: operands. For this reason, the constraint character @samp{+}, which
3410: indicates such an operand, may not be used.
3411:
3412: When the assembler instruction has a read-write operand, or an operand
3413: in which only some of the bits are to be changed, you must logically
1.1 root 3414: split its function into two separate operands, one input operand and one
3415: write-only output operand. The connection between them is expressed by
3416: constraints which say they need to be in the same location when the
1.1.1.8 root 3417: instruction executes. You can use the same C expression for both
3418: operands, or different expressions. For example, here we write the
3419: (fictitious) @samp{combine} instruction with @code{bar} as its read-only
3420: source operand and @code{foo} as its read-write destination:
1.1 root 3421:
3422: @example
3423: asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
3424: @end example
3425:
3426: @noindent
3427: The constraint @samp{"0"} for operand 1 says that it must occupy the same
1.1.1.5 root 3428: location as operand 0. A digit in constraint is allowed only in an input
3429: operand, and it must refer to an output operand.
1.1 root 3430:
3431: Only a digit in the constraint can guarantee that one operand will be in
3432: the same place as another. The mere fact that @code{foo} is the value of
3433: both operands is not enough to guarantee that they will be in the same
3434: place in the generated assembler code. The following would not work:
3435:
3436: @example
3437: asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
3438: @end example
3439:
3440: Various optimizations or reloading could cause operands 0 and 1 to be in
3441: different registers; GNU CC knows no reason not to do so. For example, the
3442: compiler might find a copy of the value of @code{foo} in one register and
3443: use it for operand 1, but generate the output operand 0 in a different
3444: register (copying it afterward to @code{foo}'s own address). Of course,
3445: since the register for operand 1 is not even mentioned in the assembler
3446: code, the result will not work, but GNU CC can't tell that.
3447:
3448: Unless an output operand has the @samp{&} constraint modifier, GNU CC may
3449: allocate it in the same register as an unrelated input operand, on the
3450: assumption that the inputs are consumed before the outputs are produced.
3451: This assumption may be false if the assembler code actually consists of
3452: more than one instruction. In such a case, use @samp{&} for each output
3453: operand that may not overlap an input. @xref{Modifiers}.
3454:
1.1.1.4 root 3455: Some instructions clobber specific hard registers. To describe this, write
3456: a third colon after the input operands, followed by the names of the
3457: clobbered hard registers (given as strings). Here is a realistic example
3458: for the vax:
1.1 root 3459:
3460: @example
3461: asm volatile ("movc3 %0,%1,%2"
3462: : /* no outputs */
3463: : "g" (from), "g" (to), "g" (count)
3464: : "r0", "r1", "r2", "r3", "r4", "r5");
3465: @end example
3466:
1.1.1.4 root 3467: You can put multiple assembler instructions together in a single @code{asm}
1.1.1.7 root 3468: template, separated either with newlines (written as @samp{\n}) or with
3469: semicolons if the assembler allows such semicolons. The GNU assembler
3470: allows semicolons and all Unix assemblers seem to do so. The input
3471: operands are guaranteed not to use any of the clobbered registers, and
3472: neither will the output operands' addresses, so you can read and write the
3473: clobbered registers as many times as you like. Here is an example of
3474: multiple instructions in a template; it assumes that the subroutine
3475: @code{_foo} accepts arguments in registers 9 and 10:
1.1.1.4 root 3476:
3477: @example
3478: asm ("movl %0,r9;movl %1,r10;call _foo"
3479: : /* no outputs */
3480: : "g" (from), "g" (to)
3481: : "r9", "r10");
3482: @end example
3483:
1.1.1.7 root 3484: If you want to test the condition code produced by an assembler instruction,
3485: you must include a branch and a label in the @code{asm} construct, as follows:
3486:
3487: @example
3488: asm ("clr %0;frob %1;beq 0f;mov #1,%0;0:"
3489: : "g" (result)
3490: : "g" (input));
3491: @end example
3492:
3493: @noindent
3494: This assumes your assembler supports local labels, as the GNU assembler
3495: and most Unix assemblers do.
3496:
1.1 root 3497: Usually the most convenient way to use these @code{asm} instructions is to
3498: encapsulate them in macros that look like functions. For example,
3499:
3500: @example
3501: #define sin(x) \
3502: (@{ double __value, __arg = (x); \
3503: asm ("fsinx %1,%0": "=f" (__value): "f" (__arg)); \
3504: __value; @})
3505: @end example
3506:
3507: @noindent
3508: Here the variable @code{__arg} is used to make sure that the instruction
3509: operates on a proper @code{double} value, and to accept only those
3510: arguments @code{x} which can convert automatically to a @code{double}.
3511:
3512: Another way to make sure the instruction operates on the correct data type
3513: is to use a cast in the @code{asm}. This is different from using a
3514: variable @code{__arg} in that it converts more different types. For
3515: example, if the desired type were @code{int}, casting the argument to
3516: @code{int} would accept a pointer with no complaint, while assigning the
3517: argument to an @code{int} variable named @code{__arg} would warn about
3518: using a pointer unless the caller explicitly casts it.
3519:
1.1.1.4 root 3520: If an @code{asm} has output operands, GNU CC assumes for optimization
3521: purposes that the instruction has no side effects except to change the
3522: output operands. This does not mean that instructions with a side effect
3523: cannot be used, but you must be careful, because the compiler may eliminate
3524: them if the output operands aren't used, or move them out of loops, or
3525: replace two with one if they constitute a common subexpression. Also, if
3526: your instruction does have a side effect on a variable that otherwise
3527: appears not to change, the old value of the variable may be reused later if
3528: it happens to be found in a register.
1.1 root 3529:
3530: You can prevent an @code{asm} instruction from being deleted, moved or
3531: combined by writing the keyword @code{volatile} after the @code{asm}. For
3532: example:
3533:
3534: @example
3535: #define set_priority(x) \
3536: asm volatile ("set_priority %0": /* no outputs */ : "g" (x))
3537: @end example
3538:
1.1.1.7 root 3539: @noindent
3540: (However, an instruction without output operands will not be deleted
3541: or moved, regardless, unless it is unreachable.)
1.1.1.4 root 3542:
1.1 root 3543: It is a natural idea to look for a way to give access to the condition
3544: code left by the assembler instruction. However, when we attempted to
3545: implement this, we found no way to make it work reliably. The problem
3546: is that output operands might need reloading, which would result in
3547: additional following ``store'' instructions. On most machines, these
3548: instructions would alter the condition code before there was time to
3549: test it. This problem doesn't arise for ordinary ``test'' and
3550: ``compare'' instructions because they don't have any output operands.
3551:
1.1.1.7 root 3552: If you are writing a header file that should be includable in ANSI C
1.1.1.8 root 3553: programs, write @code{__asm__} instead of @code{asm}. @xref{Alternate
1.1.1.7 root 3554: Keywords}.
3555:
1.1.1.8 root 3556: @node Asm Labels, Explicit Reg Vars, Extended Asm, Extensions
1.1 root 3557: @section Controlling Names Used in Assembler Code
3558:
1.1.1.8 root 3559: You can specify the name to be used in the assembler code for a C
3560: function or variable by writing the @code{asm} (or @code{__asm__})
3561: keyword after the declarator as follows:
1.1 root 3562:
3563: @example
3564: int foo asm ("myfoo") = 2;
3565: @end example
3566:
3567: @noindent
3568: This specifies that the name to be used for the variable @code{foo} in
3569: the assembler code should be @samp{myfoo} rather than the usual
3570: @samp{_foo}.
3571:
3572: On systems where an underscore is normally prepended to the name of a C
3573: function or variable, this feature allows you to define names for the
3574: linker that do not start with an underscore.
3575:
3576: You cannot use @code{asm} in this way in a function @emph{definition}; but
3577: you can get the same effect by writing a declaration for the function
3578: before its definition and putting @code{asm} there, like this:
3579:
3580: @example
3581: extern func () asm ("FUNC");
3582:
3583: func (x, y)
3584: int x, y;
3585: @dots{}
3586: @end example
3587:
3588: It is up to you to make sure that the assembler names you choose do not
3589: conflict with any other assembler symbols. Also, you must not use a
3590: register name; that would produce completely invalid assembler code. GNU
3591: CC does not as yet have the ability to store static variables in registers.
3592: Perhaps that will be added.
3593:
1.1.1.8 root 3594: @node Explicit Reg Vars, Alternate Keywords, Asm Labels, Extensions
3595: @section Variables in Specified Registers
3596:
3597: GNU C allows you to put a few global variables into specified hardware
3598: registers. You can also specify the register in which an ordinary
3599: register variable should be allocated.
3600:
3601: @itemize @bullet
3602: @item
3603: Global register variables reserve registers throughout the program.
3604: This may be useful in programs such as programming language
3605: interpreters which have a couple of global variables that are accessed
3606: very often.
3607:
3608: @item
3609: Local register variables in specific registers do not reserve the
3610: registers. The compiler's data flow analysis is capable of
3611: determining where the specified registers contain live values, and
3612: where they are available for other uses. These local variables are
3613: sometimes convenient for use with the extended @code{asm} feature
3614: (@pxref{Extended Asm}).
3615: @end itemize
3616:
3617: @menu
3618: * Global Reg Vars::
3619: * Local Reg Vars::
3620: @end menu
1.1.1.5 root 3621:
1.1.1.8 root 3622: @node Global Reg Vars, Local Reg Vars, Explicit Reg Vars, Explicit Reg Vars
3623: @subsection Defining Global Register Variables
1.1.1.5 root 3624:
3625: You can define a global register variable in GNU C like this:
3626:
3627: @example
3628: register int *foo asm ("a5");
3629: @end example
3630:
3631: @noindent
3632: Here @code{a5} is the name of the register which should be used. Choose a
3633: register which is normally saved and restored by function calls on your
3634: machine, so that library routines will not clobber it.
3635:
3636: Naturally the register name is cpu-dependent, so you would need to
3637: conditionalize your program according to cpu type. The register
3638: @code{a5} would be a good choice on a 68000 for a variable of pointer
3639: type. On machines with register windows, be sure to choose a ``global''
1.1.1.8 root 3640: register that is not affected magically by the function call mechanism.
1.1.1.5 root 3641:
3642: In addition, operating systems on one type of cpu may differ in how they
3643: name the registers; then you would need additional conditionals. For
3644: example, some 68000 operating systems call this register @code{%a5}.
3645:
3646: Eventually there may be a way of asking the compiler to choose a register
3647: automatically, but first we need to figure out how it should choose and
1.1.1.6 root 3648: how to enable you to guide the choice. No solution is evident.
1.1.1.5 root 3649:
3650: Defining a global register variable in a certain register reserves that
3651: register entirely for this use, at least within the current compilation.
3652: The register will not be allocated for any other purpose in the functions
3653: in the current compilation. The register will not be saved and restored by
3654: these functions. Stores into this register are never deleted even if they
3655: would appear to be dead, but references may be deleted or moved or
3656: simplified.
3657:
3658: It is not safe to access the global register variables from signal
3659: handlers, or from more than one thread of control, because the system
3660: library routines may temporarily use the register for other things (unless
3661: you recompile them specially for the task at hand).
3662:
3663: It is not safe for one function that uses a global register variable to
3664: call another such function @code{foo} by way of a third function
3665: @code{lose} that was compiled without knowledge of this variable (i.e. in a
3666: different source file in which the variable wasn't declared). This is
3667: because @code{lose} might save the register and put some other value there.
3668: For example, you can't expect a global register variable to be available in
3669: the comparison-function that you pass to @code{qsort}, since @code{qsort}
3670: might have put something else in that register. (If you are prepared to
3671: recompile @code{qsort} with the same global register variable, you can
3672: solve this problem.)
3673:
3674: If you want to recompile @code{qsort} or other source files which do not
3675: actually use your global register variable, so that they will not use that
3676: register for any other purpose, then it suffices to specify the compiler
3677: option @samp{-ffixed-@var{reg}}. You need not actually add a global
3678: register declaration to their source code.
3679:
3680: A function which can alter the value of a global register variable cannot
3681: safely be called from a function compiled without this variable, because it
3682: could clobber the value the caller expects to find there on return.
3683: Therefore, the function which is the entry point into the part of the
3684: program that uses the global register variable must explicitly save and
3685: restore the value which belongs to its caller.
3686:
3687: On most machines, @code{longjmp} will restore to each global register
3688: variable the value it had at the time of the @code{setjmp}. On some
3689: machines, however, @code{longjmp} will not change the value of global
3690: register variables. To be portable, the function that called @code{setjmp}
3691: should make other arrangements to save the values of the global register
1.1.1.10 root 3692: variables, and to restore them in a @code{longjmp}. This way, the same
1.1.1.5 root 3693: thing will happen regardless of what @code{longjmp} does.
3694:
3695: All global register variable declarations must precede all function
3696: definitions. If such a declaration could appear after function
3697: definitions, the declaration would be too late to prevent the register from
3698: being used for other purposes in the preceding functions.
3699:
1.1.1.6 root 3700: Global register variables may not have initial values, because an
3701: executable file has no means to supply initial contents for a register.
3702:
1.1.1.9 root 3703: @node Local Reg Vars,, Global Reg Vars, Explicit Reg Vars
1.1.1.8 root 3704: @subsection Specifying Registers for Local Variables
3705:
3706: You can define a local register variable with a specified register
3707: like this:
3708:
3709: @example
3710: register int *foo asm ("a5");
3711: @end example
3712:
3713: @noindent
3714: Here @code{a5} is the name of the register which should be used. Note
3715: that this is the same syntax used for defining global register
3716: variables, but for a local variable it would appear within a function.
3717:
3718: Naturally the register name is cpu-dependent, but this is not a
3719: problem, since specific registers are most often useful with explicit
3720: assembler instructions (@pxref{Extended Asm}). Both of these things
3721: generally require that you conditionalize your program according to
3722: cpu type.
3723:
3724: In addition, operating systems on one type of cpu may differ in how they
3725: name the registers; then you would need additional conditionals. For
3726: example, some 68000 operating systems call this register @code{%a5}.
3727:
3728: Eventually there may be a way of asking the compiler to choose a register
3729: automatically, but first we need to figure out how it should choose and
3730: how to enable you to guide the choice. No solution is evident.
3731:
3732: Defining such a register variable does not reserve the register; it
1.1.1.10 root 3733: remains available for other uses in places where flow control determines
3734: the variable's value is not live. However, these registers are made
3735: unavailable for use in the reload pass. I would not be surprised if
3736: excessive use of this feature leaves the compiler too few available
1.1.1.8 root 3737: registers to compile certain functions.
3738:
3739: @node Alternate Keywords,, Explicit Reg Vars, Extensions
1.1.1.7 root 3740: @section Alternate Keywords
3741:
3742: The option @samp{-traditional} disables certain keywords; @samp{-ansi}
3743: disables certain others. This causes trouble when you want to use GNU C
3744: extensions, or ANSI C features, in a general-purpose header file that
3745: should be usable by all programs, including ANSI C programs and traditional
3746: ones. The keywords @code{asm}, @code{typeof} and @code{inline} cannot be
3747: used since they won't work in a program compiled with @samp{-ansi}, while
3748: the keywords @code{const}, @code{volatile}, @code{signed}, @code{typeof}
3749: and @code{inline} won't work in a program compiled with
3750: @samp{-traditional}.@refill
3751:
1.1.1.8 root 3752: The way to solve these problems is to put @samp{__} at the beginning and
3753: end of each problematical keyword. For example, use @code{__asm__}
3754: instead of @code{asm}, @code{__const__} instead of @code{const}, and
3755: @code{__inline__} instead of @code{inline}.
1.1.1.7 root 3756:
3757: Other C compilers won't accept these alternative keywords; if you want to
3758: compile with another compiler, you can define the alternate keywords as
3759: macros to replace them with the customary keywords. It looks like this:
3760:
3761: @example
3762: #ifndef __GNUC__
1.1.1.8 root 3763: #define __asm__ asm
1.1.1.7 root 3764: #endif
3765: @end example
3766:
1.1 root 3767: @node Bugs, Portability, Extensions, Top
3768: @chapter Reporting Bugs
3769:
3770: Your bug reports play an essential role in making GNU CC reliable.
3771:
1.1.1.11 root 3772: When you encounter a problem, the first thing to do is to see if it is
3773: already known. @xref{Trouble}. Also look in @ref{Incompatibilities}.
3774: If it isn't known, then you should report the problem.
3775:
3776: Reporting a bug may help you by bringing a solution to your problem, or
3777: it may not. (If it does not, look in the service directory; see
3778: @ref{Service}.) In any case, the principal function of a bug report
3779: is to help the entire community by making the next version of GNU CC
3780: work better. Bug reports are your contribution to the maintenance of
3781: GNU CC.
1.1 root 3782:
3783: In order for a bug report to serve its purpose, you must include the
3784: information that makes for fixing the bug.
3785:
3786: @menu
3787: * Criteria: Bug Criteria. Have you really found a bug?
3788: * Reporting: Bug Reporting. How to report a bug effectively.
3789: @end menu
3790:
3791: @node Bug Criteria, Bug Reporting, Bugs, Bugs
3792: @section Have You Found a Bug?
3793:
3794: If you are not sure whether you have found a bug, here are some guidelines:
3795:
3796: @itemize @bullet
3797: @item
3798: If the compiler gets a fatal signal, for any input whatever, that is a
3799: compiler bug. Reliable compilers never crash.
3800:
3801: @item
3802: If the compiler produces invalid assembly code, for any input whatever
3803: (except an @code{asm} statement), that is a compiler bug, unless the
3804: compiler reports errors (not just warnings) which would ordinarily
3805: prevent the assembler from being run.
3806:
3807: @item
3808: If the compiler produces valid assembly code that does not correctly
3809: execute the input source code, that is a compiler bug.
3810:
3811: However, you must double-check to make sure, because you may have run
3812: into an incompatibility between GNU C and traditional C
3813: (@pxref{Incompatibilities}). These incompatibilities might be considered
3814: bugs, but they are inescapable consequences of valuable features.
3815:
3816: Or you may have a program whose behavior is undefined, which happened
3817: by chance to give the desired results with another C compiler.
3818:
3819: For example, in many nonoptimizing compilers, you can write @samp{x;}
3820: at the end of a function instead of @samp{return x;}, with the same
1.1.1.8 root 3821: results. But the value of the function is undefined if @code{return}
1.1 root 3822: is omitted; it is not a bug when GNU CC produces different results.
3823:
3824: Problems often result from expressions with two increment operators,
1.1.1.8 root 3825: as in @code{f (*p++, *p++)}. Your previous compiler might have
1.1 root 3826: interpreted that expression the way you intended; GNU CC might
1.1.1.8 root 3827: interpret it another way. Neither compiler is wrong. The bug is
3828: in your code.
1.1 root 3829:
3830: After you have localized the error to a single source line, it should
3831: be easy to check for these things. If your program is correct and
3832: well defined, you have found a compiler bug.
3833:
3834: @item
3835: If the compiler produces an error message for valid input, that is a
3836: compiler bug.
3837:
3838: Note that the following is not valid input, and the error message for
3839: it is not a bug:
3840:
3841: @example
3842: int foo (char);
3843:
3844: int
3845: foo (x)
3846: char x;
3847: @{ @dots{} @}
3848: @end example
3849:
3850: @noindent
3851: The prototype says to pass a @code{char}, while the definition says to
3852: pass an @code{int} and treat the value as a @code{char}. This is what
3853: the ANSI standard says, and it makes sense.
3854:
3855: @item
3856: If the compiler does not produce an error message for invalid input,
3857: that is a compiler bug. However, you should note that your idea of
3858: ``invalid input'' might be my idea of ``an extension'' or ``support
3859: for traditional practice''.
3860:
3861: @item
3862: If you are an experienced user of C compilers, your suggestions
3863: for improvement of GNU CC are welcome in any case.
3864: @end itemize
3865:
3866: @node Bug Reporting,, Bug Criteria, Bugs
3867: @section How to Report Bugs
3868:
3869: Send bug reports for GNU C to one of these addresses:
3870:
3871: @example
3872: bug-gcc@@prep.ai.mit.edu
3873: @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gcc
3874: @end example
3875:
1.1.1.12 root 3876: @strong{Do not send bug reports to @samp{help-gcc}, or to the newsgroup
3877: @samp{gnu.gcc.help}.} Most users of GNU CC do not want to receive bug
1.1.1.8 root 3878: reports. Those that do, have asked to be on @samp{bug-gcc}.
3879:
3880: The mailing list @samp{bug-gcc} has a newsgroup which serves as a
3881: repeater. The mailing list and the newsgroup carry exactly the same
3882: messages. Often people think of posting bug reports to the newsgroup
3883: instead of mailing them. This appears to work, but it has one problem
3884: which can be crucial: a newsgroup posting does not contain a mail path
3885: back to the sender. Thus, if I need to ask for more information, I
3886: may be unable to reach you. For this reason, it is better to send bug
3887: reports to the mailing list.
3888:
3889: As a last resort, send bug reports on paper to:
1.1 root 3890:
3891: @example
3892: GNU Compiler Bugs
1.1.1.12 root 3893: Free Software Foundation
3894: 675 Mass Ave
1.1 root 3895: Cambridge, MA 02139
3896: @end example
3897:
3898: The fundamental principle of reporting bugs usefully is this:
1.1.1.8 root 3899: @strong{report all the facts}. If you are not sure whether to state a
3900: fact or leave it out, state it!
1.1 root 3901:
3902: Often people omit facts because they think they know what causes the
3903: problem and they conclude that some details don't matter. Thus, you might
3904: assume that the name of the variable you use in an example does not matter.
3905: Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a
3906: stray memory reference which happens to fetch from the location where that
3907: name is stored in memory; perhaps, if the name were different, the contents
3908: of that location would fool the compiler into doing the right thing despite
1.1.1.8 root 3909: the bug. Play it safe and give a specific, complete example. That is the
3910: easiest thing for you to do, and the most helpful.
1.1 root 3911:
1.1.1.8 root 3912: Keep in mind that the purpose of a bug report is to enable me to fix
3913: the bug if it is not known. It isn't very important what happens if
3914: the bug is already known. Therefore, always write your bug reports on
3915: the assumption that the bug is not known.
3916:
3917: Sometimes people give a few sketchy facts and ask, ``Does this ring a
3918: bell?'' Those bug reports are useless, and I urge everyone to
3919: @emph{refuse to respond to them} except to chide the sender to report
3920: bugs properly.
3921:
3922: To enable me to fix the bug, you should include all these things:
1.1 root 3923:
3924: @itemize @bullet
3925: @item
3926: The version of GNU CC. You can get this by running it with the
3927: @samp{-v} option.
3928:
3929: Without this, I won't know whether there is any point in looking for
3930: the bug in the current version of GNU CC.
3931:
3932: @item
3933: A complete input file that will reproduce the bug. If the bug is in
3934: the C preprocessor, send me a source file and any header files that it
3935: requires. If the bug is in the compiler proper (@file{cc1}), run your
3936: source file through the C preprocessor by doing @samp{gcc -E
3937: @var{sourcefile} > @var{outfile}}, then include the contents of
3938: @var{outfile} in the bug report. (Any @samp{-I}, @samp{-D} or
3939: @samp{-U} options that you used in actual compilation should also be
3940: used when doing this.)
3941:
3942: A single statement is not enough of an example. In order to compile
3943: it, it must be embedded in a function definition; and the bug might
3944: depend on the details of how this is done.
3945:
3946: Without a real example I can compile, all I can do about your bug
3947: report is wish you luck. It would be futile to try to guess how to
3948: provoke the bug. For example, bugs in register allocation and
3949: reloading frequently depend on every little detail of the function
3950: they happen in.
3951:
3952: @item
3953: The command arguments you gave GNU CC to compile that example and
3954: observe the bug. For example, did you use @samp{-O}? To guarantee
3955: you won't omit something important, list them all.
3956:
3957: If I were to try to guess the arguments, I would probably guess wrong
3958: and then I would not encounter the bug.
3959:
3960: @item
3961: The names of the files that you used for @file{tm.h} and @file{md}
3962: when you installed the compiler.
3963:
3964: @item
3965: The type of machine you are using, and the operating system name and
3966: version number.
3967:
3968: @item
3969: A description of what behavior you observe that you believe is
3970: incorrect. For example, ``It gets a fatal signal,'' or, ``There is an
3971: incorrect assembler instruction in the output.''
3972:
3973: Of course, if the bug is that the compiler gets a fatal signal, then I
3974: will certainly notice it. But if the bug is incorrect output, I might
3975: not notice unless it is glaringly wrong. I won't study all the
3976: assembler code from a 50-line C program just on the off chance that it
3977: might be wrong.
3978:
3979: Even if the problem you experience is a fatal signal, you should still
3980: say so explicitly. Suppose something strange is going on, such as,
3981: your copy of the compiler is out of synch, or you have encountered a
3982: bug in the C library on your system. (This has happened!) Your copy
3983: might crash and mine would not. If you @i{told} me to expect a crash,
3984: then when mine fails to crash, I would know that the bug was not
3985: happening for me. If you had not told me to expect a crash, then I
3986: would not be able to draw any conclusion from my observations.
3987:
1.1.1.8 root 3988: Often the observed symptom is incorrect output when your program is run.
3989: Sad to say, this is not enough information for me unless the program is
3990: short and simple. If you send me a large program, I don't have time to
3991: figure out how it would work if compiled correctly, much less which line
3992: of it was compiled wrong. So you will have to do that. Tell me which
3993: source line it is, and what incorrect result happens when that line is
3994: executed. A person who understands the test program can find this as
3995: easily as a bug in the program itself.
1.1 root 3996:
3997: @item
3998: If you send me examples of output from GNU CC, please use @samp{-g}
3999: when you make them. The debugging information includes source line
4000: numbers which are essential for correlating the output with the input.
4001:
4002: @item
4003: If you wish to suggest changes to the GNU CC source, send me context
4004: diffs. If you even discuss something in the GNU CC source, refer to
4005: it by context, not by line number.
4006:
4007: The line numbers in my development sources don't match those in your
4008: sources. Your line numbers would convey no useful information to me.
4009:
4010: @item
4011: Additional information from a debugger might enable me to find
4012: a problem on a machine which I do not have available myself.
4013: However, you need to think when you collect this information if
4014: you want it to have any chance of being useful.
4015:
4016: For example, many people send just a backtrace, but that is never
4017: useful by itself. A simple backtrace with arguments conveys little
4018: about GNU CC because the compiler is largely data-driven; the same
4019: functions are called over and over for different RTL insns, doing
4020: different things depending on the details of the insn.
4021:
4022: Most of the arguments listed in the backtrace are useless because they
4023: are pointers to RTL list structure. The numeric values of the
4024: pointers, which the debugger prints in the backtrace, have no
4025: significance whatever; all that matters is the contents of the objects
4026: they point to (and most of the contents are other such pointers).
4027:
4028: In addition, most compiler passes consist of one or more loops that
4029: scan the RTL insn sequence. The most vital piece of information about
1.1.1.8 root 4030: such a loop---which insn it has reached---is usually in a local variable,
1.1 root 4031: not in an argument.
4032:
4033: What you need to provide in addition to a backtrace are the values of
4034: the local variables for several stack frames up. When a local
4035: variable or an argument is an RTX, first print its value and then use
4036: the GDB command @code{pr} to print the RTL expression that it points
4037: to. (If GDB doesn't run on your machine, use your debugger to call
4038: the function @code{debug_rtx} with the RTX as an argument.) In
4039: general, whenever a variable is a pointer, its value is no use
4040: without the data it points to.
4041:
4042: In addition, include a debugging dump from just before the pass
4043: in which the crash happens. Most bugs involve a series of insns,
4044: not just one.
4045: @end itemize
4046:
4047: Here are some things that are not necessary:
4048:
4049: @itemize @bullet
4050: @item
4051: A description of the envelope of the bug.
4052:
4053: Often people who encounter a bug spend a lot of time investigating
4054: which changes to the input file will make the bug go away and which
4055: changes will not affect it.
4056:
4057: This is often time consuming and not very useful, because the way I
4058: will find the bug is by running a single example under the debugger
4059: with breakpoints, not by pure deduction from a series of examples.
1.1.1.8 root 4060: I recommend that you save your time for something else.
1.1 root 4061:
4062: Of course, if you can find a simpler example to report @emph{instead}
4063: of the original one, that is a convenience for me. Errors in the
4064: output will be easier to spot, running under the debugger will take
4065: less time, etc. Most GNU CC bugs involve just one function, so the
4066: most straightforward way to simplify an example is to delete all the
4067: function definitions except the one where the bug occurs. Those
4068: earlier in the file may be replaced by external declarations if the
1.1.1.8 root 4069: crucial function depends on them. (Exception: inline functions may
4070: affect compilation of functions defined later in the file.)
1.1 root 4071:
4072: However, simplification is not vital; if you don't want to do this,
1.1.1.8 root 4073: report the bug anyway and send me the entire test case you used.
1.1 root 4074:
4075: @item
4076: A patch for the bug.
4077:
4078: A patch for the bug does help me if it is a good one. But don't omit
1.1.1.8 root 4079: the necessary information, such as the test case, on the assumption that
4080: a patch is all I need. I might see problems with your patch and decide
4081: to fix the problem another way, or I might not understand it at all.
1.1 root 4082:
4083: Sometimes with a program as complicated as GNU CC it is very hard to
4084: construct an example that will make the program follow a certain path
4085: through the code. If you don't send me the example, I won't be able
4086: to construct one, so I won't be able to verify that the bug is fixed.
4087:
1.1.1.8 root 4088: And if I can't understand what bug you are trying to fix, or why your
4089: patch should be an improvement, I won't install it. A test case will
4090: help me to understand.
4091:
1.1 root 4092: @item
4093: A guess about what the bug is or what it depends on.
4094:
4095: Such guesses are usually wrong. Even I can't guess right about such
1.1.1.8 root 4096: things without first using the debugger to find the facts.
1.1 root 4097: @end itemize
4098:
4099: @node Portability, Interface, Bugs, Top
4100: @chapter GNU CC and Portability
4101:
4102: The main goal of GNU CC was to make a good, fast compiler for machines in
4103: the class that the GNU system aims to run on: 32-bit machines that address
4104: 8-bit bytes and have several general registers. Elegance, theoretical
4105: power and simplicity are only secondary.
4106:
4107: GNU CC gets most of the information about the target machine from a machine
4108: description which gives an algebraic formula for each of the machine's
4109: instructions. This is a very clean way to describe the target. But when
4110: the compiler needs information that is difficult to express in this
4111: fashion, I have not hesitated to define an ad-hoc parameter to the machine
4112: description. The purpose of portability is to reduce the total work needed
4113: on the compiler; it was not of interest for its own sake.
4114:
4115: GNU CC does not contain machine dependent code, but it does contain code
4116: that depends on machine parameters such as endianness (whether the most
4117: significant byte has the highest or lowest address of the bytes in a word)
4118: and the availability of autoincrement addressing. In the RTL-generation
4119: pass, it is often necessary to have multiple strategies for generating code
4120: for a particular kind of syntax tree, strategies that are usable for different
4121: combinations of parameters. Often I have not tried to address all possible
4122: cases, but only the common ones or only the ones that I have encountered.
4123: As a result, a new target may require additional strategies. You will know
4124: if this happens because the compiler will call @code{abort}. Fortunately,
4125: the new strategies can be added in a machine-independent fashion, and will
4126: affect only the target machines that need them.
4127:
4128: @node Interface, Passes, Portability, Top
4129: @chapter Interfacing to GNU CC Output
4130:
4131: GNU CC is normally configured to use the same function calling convention
4132: normally in use on the target system. This is done with the
4133: machine-description macros described (@pxref{Machine Macros}).
4134:
4135: However, returning of structure and union values is done differently on
4136: some target machines. As a result, functions compiled with PCC
4137: returning such types cannot be called from code compiled with GNU CC,
4138: and vice versa. This does not cause trouble often because few Unix
4139: library routines return structures or unions.
4140:
4141: GNU CC code returns structures and unions that are 1, 2, 4 or 8 bytes
4142: long in the same registers used for @code{int} or @code{double} return
4143: values. (GNU CC typically allocates variables of such types in
4144: registers also.) Structures and unions of other sizes are returned by
4145: storing them into an address passed by the caller (usually in a
4146: register). The machine-description macros @code{STRUCT_VALUE} and
4147: @code{STRUCT_INCOMING_VALUE} tell GNU CC where to pass this address.
4148:
4149: By contrast, PCC on most target machines returns structures and unions
4150: of any size by copying the data into an area of static storage, and then
4151: returning the address of that storage as if it were a pointer value.
4152: The caller must copy the data from that memory area to the place where
4153: the value is wanted. This is slower than the method used by GNU CC, and
4154: fails to be reentrant.
4155:
4156: On some target machines, such as RISC machines and the 80386, the
4157: standard system convention is to pass to the subroutine the address of
4158: where to return the value. On these machines, GNU CC has been
4159: configured to be compatible with the standard compiler, when this method
4160: is used. It may not be compatible for structures of 1, 2, 4 or 8 bytes.
4161:
4162: GNU CC uses the system's standard convention for passing arguments. On
4163: some machines, the first few arguments are passed in registers; in
4164: others, all are passed on the stack. It would be possible to use
4165: registers for argument passing on any machine, and this would probably
4166: result in a significant speedup. But the result would be complete
4167: incompatibility with code that follows the standard convention. So this
4168: change is practical only if you are switching to GNU CC as the sole C
4169: compiler for the system. We may implement register argument passing on
4170: certain machines once we have a complete GNU system so that we can
4171: compile the libraries with GNU CC.
4172:
4173: If you use @code{longjmp}, beware of automatic variables. ANSI C says that
4174: automatic variables that are not declared @code{volatile} have undefined
4175: values after a @code{longjmp}. And this is all GNU CC promises to do,
4176: because it is very difficult to restore register variables correctly, and
4177: one of GNU CC's features is that it can put variables in registers without
4178: your asking it to.
4179:
4180: If you want a variable to be unaltered by @code{longjmp}, and you don't
4181: want to write @code{volatile} because old C compilers don't accept it,
4182: just take the address of the variable. If a variable's address is ever
4183: taken, even if just to compute it and ignore it, then the variable cannot
4184: go in a register:
4185:
4186: @example
4187: @{
4188: int careful;
4189: &careful;
4190: @dots{}
4191: @}
4192: @end example
4193:
4194: Code compiled with GNU CC may call certain library routines. Most of
4195: them handle arithmetic for which there are no instructions. This
4196: includes multiply and divide on some machines, and floating point
4197: operations on any machine for which floating point support is disabled
4198: with @samp{-msoft-float}. Some standard parts of the C library, such as
4199: @code{bcopy} or @code{memcpy}, are also called automatically. The usual
4200: function call interface is used for calling the library routines.
4201:
4202: These library routines should be defined in the library @file{gnulib},
4203: which GNU CC automatically searches whenever it links a program. On
4204: machines that have multiply and divide instructions, if hardware
4205: floating point is in use, normally @file{gnulib} is not needed, but it
4206: is searched just in case.
4207:
4208: Each arithmetic function is defined in @file{gnulib.c} to use the
4209: corresponding C arithmetic operator. As long as the file is compiled
4210: with another C compiler, which supports all the C arithmetic operators,
4211: this file will work portably. However, @file{gnulib.c} does not work if
4212: compiled with GNU CC, because each arithmetic function would compile
4213: into a call to itself!
4214:
4215: @node Passes, RTL, Interface, Top
4216: @chapter Passes and Files of the Compiler
4217:
4218: The overall control structure of the compiler is in @file{toplev.c}. This
4219: file is responsible for initialization, decoding arguments, opening and
4220: closing files, and sequencing the passes.
4221:
4222: The parsing pass is invoked only once, to parse the entire input. The RTL
4223: intermediate code for a function is generated as the function is parsed, a
4224: statement at a time. Each statement is read in as a syntax tree and then
4225: converted to RTL; then the storage for the tree for the statement is
4226: reclaimed. Storage for types (and the expressions for their sizes),
4227: declarations, and a representation of the binding contours and how they nest,
4228: remains until the function is finished being compiled; these are all needed
4229: to output the debugging information.
4230:
4231: Each time the parsing pass reads a complete function definition or
4232: top-level declaration, it calls the function
4233: @code{rest_of_compilation} or @code{rest_of_decl_compilation} in
4234: @file{toplev.c}, which are responsible for all further processing
4235: necessary, ending with output of the assembler language. All other
4236: compiler passes run, in sequence, within @code{rest_of_compilation}.
4237: When that function returns from compiling a function definition, the
4238: storage used for that function definition's compilation is entirely
4239: freed, unless it is an inline function (@pxref{Inline}).
4240:
4241: Here is a list of all the passes of the compiler and their source files.
4242: Also included is a description of where debugging dumps can be requested
4243: with @samp{-d} options.
4244:
4245: @itemize @bullet
4246: @item
4247: Parsing. This pass reads the entire text of a function definition,
4248: constructing partial syntax trees. This and RTL generation are no longer
4249: truly separate passes (formerly they were), but it is easier to think
4250: of them as separate.
4251:
4252: The tree representation does not entirely follow C syntax, because it is
4253: intended to support other languages as well.
4254:
4255: C data type analysis is also done in this pass, and every tree node
4256: that represents an expression has a data type attached. Variables are
4257: represented as declaration nodes.
4258:
4259: Constant folding and associative-law simplifications are also done
4260: during this pass.
4261:
4262: The source files for parsing are @file{c-parse.y}, @file{c-decl.c},
4263: @file{c-typeck.c}, @file{c-convert.c}, @file{stor-layout.c},
4264: @file{fold-const.c}, and @file{tree.c}. The last three files are
4265: intended to be language-independent. There are also header files
4266: @file{c-parse.h}, @file{c-tree.h}, @file{tree.h} and @file{tree.def}.
4267: The last two define the format of the tree representation.@refill
4268:
4269: @item
4270: RTL generation. This is the conversion of syntax tree into RTL code.
4271: It is actually done statement-by-statement during parsing, but for
4272: most purposes it can be thought of as a separate pass.
4273:
4274: This is where the bulk of target-parameter-dependent code is found,
4275: since often it is necessary for strategies to apply only when certain
4276: standard kinds of instructions are available. The purpose of named
4277: instruction patterns is to provide this information to the RTL
4278: generation pass.
4279:
4280: Optimization is done in this pass for @code{if}-conditions that are
4281: comparisons, boolean operations or conditional expressions. Tail
4282: recursion is detected at this time also. Decisions are made about how
4283: best to arrange loops and how to output @code{switch} statements.
4284:
4285: The source files for RTL generation are @file{stmt.c}, @file{expr.c},
4286: @file{explow.c}, @file{expmed.c}, @file{optabs.c} and @file{emit-rtl.c}.
4287: Also, the file @file{insn-emit.c}, generated from the machine description
4288: by the program @code{genemit}, is used in this pass. The header files
4289: @file{expr.h} is used for communication within this pass.@refill
4290:
4291: The header files @file{insn-flags.h} and @file{insn-codes.h},
4292: generated from the machine description by the programs @code{genflags}
4293: and @code{gencodes}, tell this pass which standard names are available
4294: for use and which patterns correspond to them.@refill
4295:
4296: Aside from debugging information output, none of the following passes
4297: refers to the tree structure representation of the function (only
4298: part of which is saved).
4299:
4300: The decision of whether the function can and should be expanded inline
4301: in its subsequent callers is made at the end of rtl generation. The
4302: function must meet certain criteria, currently related to the size of
4303: the function and the types and number of parameters it has. Note that
4304: this function may contain loops, recursive calls to itself
4305: (tail-recursive functions can be inlined!), gotos, in short, all
4306: constructs supported by GNU CC.
4307:
4308: The option @samp{-dr} causes a debugging dump of the RTL code after
4309: this pass. This dump file's name is made by appending @samp{.rtl} to
4310: the input file name.
4311:
4312: @item
4313: Jump optimization. This pass simplifies jumps to the following
4314: instruction, jumps across jumps, and jumps to jumps. It deletes
4315: unreferenced labels and unreachable code, except that unreachable code
4316: that contains a loop is not recognized as unreachable in this pass.
4317: (Such loops are deleted later in the basic block analysis.)
4318:
4319: Jump optimization is performed two or three times. The first time is
4320: immediately following RTL generation. The second time is after CSE,
4321: but only if CSE says repeated jump optimization is needed. The
4322: last time is right before the final pass. That time, cross-jumping
4323: and deletion of no-op move instructions are done together with the
4324: optimizations described above.
4325:
4326: The source file of this pass is @file{jump.c}.
4327:
4328: The option @samp{-dj} causes a debugging dump of the RTL code after
4329: this pass is run for the first time. This dump file's name is made by
4330: appending @samp{.jump} to the input file name.
4331:
4332: @item
4333: Register scan. This pass finds the first and last use of each
4334: register, as a guide for common subexpression elimination. Its source
4335: is in @file{regclass.c}.
4336:
4337: @item
4338: Common subexpression elimination. This pass also does constant
4339: propagation. Its source file is @file{cse.c}. If constant
4340: propagation causes conditional jumps to become unconditional or to
4341: become no-ops, jump optimization is run again when CSE is finished.
4342:
4343: The option @samp{-ds} causes a debugging dump of the RTL code after
4344: this pass. This dump file's name is made by appending @samp{.cse} to
4345: the input file name.
4346:
4347: @item
1.1.1.8 root 4348: Loop optimization. This pass moves constant expressions out of loops,
4349: and optionally does strength-reduction as well. Its source file is
4350: @file{loop.c}.
1.1 root 4351:
4352: The option @samp{-dL} causes a debugging dump of the RTL code after
4353: this pass. This dump file's name is made by appending @samp{.loop} to
4354: the input file name.
4355:
4356: @item
4357: Stupid register allocation is performed at this point in a
4358: nonoptimizing compilation. It does a little data flow analysis as
4359: well. When stupid register allocation is in use, the next pass
4360: executed is the reloading pass; the others in between are skipped.
4361: The source file is @file{stupid.c}.
4362:
4363: @item
4364: Data flow analysis (@file{flow.c}). This pass divides the program
4365: into basic blocks (and in the process deletes unreachable loops); then
4366: it computes which pseudo-registers are live at each point in the
4367: program, and makes the first instruction that uses a value point at
4368: the instruction that computed the value.
4369:
4370: This pass also deletes computations whose results are never used, and
4371: combines memory references with add or subtract instructions to make
4372: autoincrement or autodecrement addressing.
4373:
4374: The option @samp{-df} causes a debugging dump of the RTL code after
4375: this pass. This dump file's name is made by appending @samp{.flow} to
4376: the input file name. If stupid register allocation is in use, this
4377: dump file reflects the full results of such allocation.
4378:
4379: @item
4380: Instruction combination (@file{combine.c}). This pass attempts to
4381: combine groups of two or three instructions that are related by data
4382: flow into single instructions. It combines the RTL expressions for
4383: the instructions by substitution, simplifies the result using algebra,
4384: and then attempts to match the result against the machine description.
4385:
4386: The option @samp{-dc} causes a debugging dump of the RTL code after
4387: this pass. This dump file's name is made by appending @samp{.combine}
4388: to the input file name.
4389:
4390: @item
4391: Register class preferencing. The RTL code is scanned to find out
4392: which register class is best for each pseudo register. The source
4393: file is @file{regclass.c}.
4394:
4395: @item
4396: Local register allocation (@file{local-alloc.c}). This pass allocates
4397: hard registers to pseudo registers that are used only within one basic
4398: block. Because the basic block is linear, it can use fast and
4399: powerful techniques to do a very good job.
4400:
4401: The option @samp{-dl} causes a debugging dump of the RTL code after
4402: this pass. This dump file's name is made by appending @samp{.lreg} to
4403: the input file name.
4404:
4405: @item
4406: Global register allocation (@file{global-alloc.c}). This pass
4407: allocates hard registers for the remaining pseudo registers (those
4408: whose life spans are not contained in one basic block).
4409:
4410: @item
4411: Reloading. This pass renumbers pseudo registers with the hardware
4412: registers numbers they were allocated. Pseudo registers that did not
4413: get hard registers are replaced with stack slots. Then it finds
4414: instructions that are invalid because a value has failed to end up in
4415: a register, or has ended up in a register of the wrong kind. It fixes
4416: up these instructions by reloading the problematical values
4417: temporarily into registers. Additional instructions are generated to
4418: do the copying.
4419:
4420: Source files are @file{reload.c} and @file{reload1.c}, plus the header
4421: @file{reload.h} used for communication between them.
4422:
4423: The option @samp{-dg} causes a debugging dump of the RTL code after
4424: this pass. This dump file's name is made by appending @samp{.greg} to
4425: the input file name.
4426:
4427: @item
4428: Jump optimization is repeated, this time including cross-jumping
1.1.1.5 root 4429: and deletion of no-op move instructions.
1.1 root 4430:
4431: The option @samp{-dJ} causes a debugging dump of the RTL code after
4432: this pass. This dump file's name is made by appending @samp{.jump2}
4433: to the input file name.
4434:
4435: @item
1.1.1.8 root 4436: Delayed branch scheduling may be done at this point. The source file
4437: name is @file{dbranch.c}.
4438:
4439: The option @samp{-dd} causes a debugging dump of the RTL code after
4440: this pass. This dump file's name is made by appending @samp{.dbr}
4441: to the input file name.
4442:
4443: @item
1.1 root 4444: Final. This pass outputs the assembler code for the function. It is
4445: also responsible for identifying spurious test and compare
1.1.1.5 root 4446: instructions. Machine-specific peephole optimizations are performed
4447: at the same time. The function entry and exit sequences are generated
1.1 root 4448: directly as assembler code in this pass; they never exist as RTL.
4449:
4450: The source files are @file{final.c} plus @file{insn-output.c}; the
4451: latter is generated automatically from the machine description by the
4452: tool @file{genoutput}. The header file @file{conditions.h} is used
4453: for communication between these files.
4454:
4455: @item
4456: Debugging information output. This is run after final because it must
4457: output the stack slot offsets for pseudo registers that did not get
4458: hard registers. Source files are @file{dbxout.c} for DBX symbol table
4459: format and @file{symout.c} for GDB's own symbol table format.
4460: @end itemize
4461:
4462: Some additional files are used by all or many passes:
4463:
4464: @itemize @bullet
4465: @item
4466: Every pass uses @file{machmode.def}, which defines the machine modes.
4467:
4468: @item
4469: All the passes that work with RTL use the header files @file{rtl.h}
4470: and @file{rtl.def}, and subroutines in file @file{rtl.c}. The tools
4471: @code{gen*} also use these files to read and work with the machine
4472: description RTL.
4473:
4474: @item
4475: Several passes refer to the header file @file{insn-config.h} which
4476: contains a few parameters (C macro definitions) generated
4477: automatically from the machine description RTL by the tool
4478: @code{genconfig}.
4479:
4480: @item
4481: Several passes use the instruction recognizer, which consists of
4482: @file{recog.c} and @file{recog.h}, plus the files @file{insn-recog.c}
4483: and @file{insn-extract.c} that are generated automatically from the
4484: machine description by the tools @file{genrecog} and
4485: @file{genextract}.@refill
4486:
4487: @item
4488: Several passes use the header files @file{regs.h} which defines the
4489: information recorded about pseudo register usage, and @file{basic-block.h}
4490: which defines the information recorded about basic blocks.
4491:
4492: @item
4493: @file{hard-reg-set.h} defines the type @code{HARD_REG_SET}, a bit-vector
4494: with a bit for each hard register, and some macros to manipulate it.
4495: This type is just @code{int} if the machine has few enough hard registers;
4496: otherwise it is an array of @code{int} and some of the macros expand
4497: into loops.
4498: @end itemize
4499:
4500: @node RTL, Machine Desc, Passes, Top
4501: @chapter RTL Representation
4502:
4503: Most of the work of the compiler is done on an intermediate representation
4504: called register transfer language. In this language, the instructions to be
4505: output are described, pretty much one by one, in an algebraic form that
4506: describes what the instruction does.
4507:
4508: RTL is inspired by Lisp lists. It has both an internal form, made up of
4509: structures that point at other structures, and a textual form that is used
4510: in the machine description and in printed debugging dumps. The textual
4511: form uses nested parentheses to indicate the pointers in the internal form.
4512:
4513: @menu
4514: * RTL Objects:: Expressions vs vectors vs strings vs integers.
4515: * Accessors:: Macros to access expression operands or vector elts.
4516: * Flags:: Other flags in an RTL expression.
4517: * Machine Modes:: Describing the size and format of a datum.
4518: * Constants:: Expressions with constant values.
4519: * Regs and Memory:: Expressions representing register contents or memory.
4520: * Arithmetic:: Expressions representing arithmetic on other expressions.
4521: * Comparisons:: Expressions representing comparison of expressions.
4522: * Bit Fields:: Expressions representing bit-fields in memory or reg.
4523: * Conversions:: Extending, truncating, floating or fixing.
4524: * RTL Declarations:: Declaring volatility, constancy, etc.
4525: * Side Effects:: Expressions for storing in registers, etc.
4526: * Incdec:: Embedded side-effects for autoincrement addressing.
1.1.1.9 root 4527: * Assembler:: Representing @code{asm} with operands.
1.1 root 4528: * Insns:: Expression types for entire insns.
1.1.1.9 root 4529: * Calls:: RTL representation of function call insns.
1.1 root 4530: * Sharing:: Some expressions are unique; others *must* be copied.
4531: @end menu
4532:
4533: @node RTL Objects, Accessors, RTL, RTL
4534: @section RTL Object Types
4535:
4536: RTL uses four kinds of objects: expressions, integers, strings and vectors.
4537: Expressions are the most important ones. An RTL expression (``RTX'', for
4538: short) is a C structure, but it is usually referred to with a pointer; a
4539: type that is given the typedef name @code{rtx}.
4540:
4541: An integer is simply an @code{int}, and a string is a @code{char *}.
1.1.1.8 root 4542: Within RTL code, strings appear only inside @code{symbol_ref} expressions,
1.1 root 4543: but they appear in other contexts in the RTL expressions that make up
4544: machine descriptions. Their written form uses decimal digits.
4545:
4546: A string is a sequence of characters. In core it is represented as a
4547: @code{char *} in usual C fashion, and it is written in C syntax as well.
4548: However, strings in RTL may never be null. If you write an empty string in
4549: a machine description, it is represented in core as a null pointer rather
4550: than as a pointer to a null character. In certain contexts, these null
4551: pointers instead of strings are valid.
4552:
4553: A vector contains an arbitrary, specified number of pointers to
4554: expressions. The number of elements in the vector is explicitly present in
4555: the vector. The written form of a vector consists of square brackets
4556: (@samp{[@dots{}]}) surrounding the elements, in sequence and with
4557: whitespace separating them. Vectors of length zero are not created; null
4558: pointers are used instead.
4559:
4560: Expressions are classified by @dfn{expression codes} (also called RTX
4561: codes). The expression code is a name defined in @file{rtl.def}, which is
4562: also (in upper case) a C enumeration constant. The possible expression
4563: codes and their meanings are machine-independent. The code of an RTX can
4564: be extracted with the macro @code{GET_CODE (@var{x})} and altered with
4565: @code{PUT_CODE (@var{x}, @var{newcode})}.
4566:
4567: The expression code determines how many operands the expression contains,
4568: and what kinds of objects they are. In RTL, unlike Lisp, you cannot tell
4569: by looking at an operand what kind of object it is. Instead, you must know
4570: from its context---from the expression code of the containing expression.
1.1.1.8 root 4571: For example, in an expression of code @code{subreg}, the first operand is
1.1 root 4572: to be regarded as an expression and the second operand as an integer. In
1.1.1.8 root 4573: an expression of code @code{plus}, there are two operands, both of which
4574: are to be regarded as expressions. In a @code{symbol_ref} expression,
1.1 root 4575: there is one operand, which is to be regarded as a string.
4576:
4577: Expressions are written as parentheses containing the name of the
4578: expression type, its flags and machine mode if any, and then the operands
4579: of the expression (separated by spaces).
4580:
4581: Expression code names in the @samp{md} file are written in lower case,
4582: but when they appear in C code they are written in upper case. In this
1.1.1.8 root 4583: manual, they are shown as follows: @code{const_int}.
1.1 root 4584:
4585: In a few contexts a null pointer is valid where an expression is normally
1.1.1.4 root 4586: wanted. The written form of this is @code{(nil)}.
1.1 root 4587:
4588: @node Accessors, Flags, RTL Objects, RTL
4589: @section Access to Operands
4590:
4591: For each expression type @file{rtl.def} specifies the number of contained
4592: objects and their kinds, with four possibilities: @samp{e} for expression
4593: (actually a pointer to an expression), @samp{i} for integer, @samp{s} for
4594: string, and @samp{E} for vector of expressions. The sequence of letters
4595: for an expression code is called its @dfn{format}. Thus, the format of
1.1.1.8 root 4596: @code{subreg} is @samp{ei}.@refill
1.1 root 4597:
4598: Two other format characters are used occasionally: @samp{u} and @samp{0}.
4599: @samp{u} is equivalent to @samp{e} except that it is printed differently in
4600: debugging dumps, and @samp{0} means a slot whose contents do not fit any
4601: normal category. @samp{0} slots are not printed at all in dumps, and are
4602: often used in special ways by small parts of the compiler.@refill
4603:
4604: There are macros to get the number of operands and the format of an
4605: expression code:
4606:
4607: @table @code
4608: @item GET_RTX_LENGTH (@var{code})
4609: Number of operands of an RTX of code @var{code}.
4610:
4611: @item GET_RTX_FORMAT (@var{code})
4612: The format of an RTX of code @var{code}, as a C string.
4613: @end table
4614:
4615: Operands of expressions are accessed using the macros @code{XEXP},
4616: @code{XINT} and @code{XSTR}. Each of these macros takes two arguments: an
4617: expression-pointer (RTX) and an operand number (counting from zero).
4618: Thus,@refill
4619:
4620: @example
4621: XEXP (@var{x}, 2)
4622: @end example
4623:
4624: @noindent
4625: accesses operand 2 of expression @var{x}, as an expression.
4626:
4627: @example
4628: XINT (@var{x}, 2)
4629: @end example
4630:
4631: @noindent
4632: accesses the same operand as an integer. @code{XSTR}, used in the same
4633: fashion, would access it as a string.
4634:
4635: Any operand can be accessed as an integer, as an expression or as a string.
4636: You must choose the correct method of access for the kind of value actually
4637: stored in the operand. You would do this based on the expression code of
4638: the containing expression. That is also how you would know how many
4639: operands there are.
4640:
1.1.1.8 root 4641: For example, if @var{x} is a @code{subreg} expression, you know that it has
1.1 root 4642: two operands which can be correctly accessed as @code{XEXP (@var{x}, 0)}
4643: and @code{XINT (@var{x}, 1)}. If you did @code{XINT (@var{x}, 0)}, you
4644: would get the address of the expression operand but cast as an integer;
4645: that might occasionally be useful, but it would be cleaner to write
4646: @code{(int) XEXP (@var{x}, 0)}. @code{XEXP (@var{x}, 1)} would also
4647: compile without error, and would return the second, integer operand cast as
4648: an expression pointer, which would probably result in a crash when
4649: accessed. Nothing stops you from writing @code{XEXP (@var{x}, 28)} either,
4650: but this will access memory past the end of the expression with
4651: unpredictable results.@refill
4652:
4653: Access to operands which are vectors is more complicated. You can use the
4654: macro @code{XVEC} to get the vector-pointer itself, or the macros
4655: @code{XVECEXP} and @code{XVECLEN} to access the elements and length of a
4656: vector.
4657:
4658: @table @code
4659: @item XVEC (@var{exp}, @var{idx})
4660: Access the vector-pointer which is operand number @var{idx} in @var{exp}.
4661:
4662: @item XVECLEN (@var{exp}, @var{idx})
4663: Access the length (number of elements) in the vector which is
4664: in operand number @var{idx} in @var{exp}. This value is an @code{int}.
4665:
4666: @item XVECEXP (@var{exp}, @var{idx}, @var{eltnum})
4667: Access element number @var{eltnum} in the vector which is
4668: in operand number @var{idx} in @var{exp}. This value is an RTX.
4669:
4670: It is up to you to make sure that @var{eltnum} is not negative
4671: and is less than @code{XVECLEN (@var{exp}, @var{idx})}.
4672: @end table
4673:
4674: All the macros defined in this section expand into lvalues and therefore
4675: can be used to assign the operands, lengths and vector elements as well as
4676: to access them.
4677:
4678: @node Flags, Machine Modes, Accessors, RTL
4679: @section Flags in an RTL Expression
4680:
4681: RTL expressions contain several flags (one-bit bit-fields) that are used
4682: in certain types of expression. Most often they are accessed with the
4683: following macros:
4684:
4685: @table @code
1.1.1.10 root 4686: @item EXTERNAL_SYMBOL_P (@var{x})
4687: In a @code{symbol_ref} expression, nonzero if it corresponds to a variable
4688: declared extern in the users code. Zero for all other variables. Stored in
4689: the @code{volatil} field and printed as @samp{/v}.
4690:
1.1 root 4691: @item MEM_VOLATILE_P (@var{x})
1.1.1.8 root 4692: In @code{mem} expressions, nonzero for volatile memory references.
1.1 root 4693: Stored in the @code{volatil} field and printed as @samp{/v}.
4694:
4695: @item MEM_IN_STRUCT_P (@var{x})
1.1.1.8 root 4696: In @code{mem} expressions, nonzero for reference to an entire
1.1 root 4697: structure, union or array, or to a component of one. Zero for
4698: references to a scalar variable or through a pointer to a scalar.
4699: Stored in the @code{in_struct} field and printed as @samp{/s}.
4700:
4701: @item REG_USER_VAR_P (@var{x})
1.1.1.8 root 4702: In a @code{reg}, nonzero if it corresponds to a variable present in
1.1 root 4703: the user's source code. Zero for temporaries generated internally by
4704: the compiler. Stored in the @code{volatil} field and printed as
4705: @samp{/v}.
4706:
4707: @item REG_FUNCTION_VALUE_P (@var{x})
1.1.1.8 root 4708: Nonzero in a @code{reg} if it is the place in which this function's
1.1 root 4709: value is going to be returned. (This happens only in a hard
4710: register.) Stored in the @code{integrated} field and printed as
4711: @samp{/i}.
4712:
4713: The same hard register may be used also for collecting the values of
4714: functions called by this one, but @code{REG_FUNCTION_VALUE_P} is zero
4715: in this kind of use.
4716:
4717: @item RTX_UNCHANGING_P (@var{x})
1.1.1.8 root 4718: Nonzero in a @code{reg} or @code{mem} if the value is not changed
1.1 root 4719: explicitly by the current function. (If it is a memory reference then
4720: it may be changed by other functions or by aliasing.) Stored in the
4721: @code{unchanging} field and printed as @samp{/u}.
4722:
4723: @item RTX_INTEGRATED_P (@var{insn})
4724: Nonzero in an insn if it resulted from an in-line function call.
4725: Stored in the @code{integrated} field and printed as @samp{/i}. This
4726: may be deleted; nothing currently depends on it.
4727:
4728: @item INSN_DELETED_P (@var{insn})
4729: In an insn, nonzero if the insn has been deleted. Stored in the
4730: @code{volatil} field and printed as @samp{/v}.
4731:
4732: @item CONSTANT_POOL_ADDRESS_P (@var{x})
1.1.1.8 root 4733: Nonzero in a @code{symbol_ref} if it refers to part of the current
1.1 root 4734: function's ``constants pool''. These are addresses close to the
4735: beginning of the function, and GNU CC assumes they can be addressed
4736: directly (perhaps with the help of base registers). Stored in the
4737: @code{unchanging} field and printed as @samp{/u}.
4738: @end table
4739:
4740: These are the fields which the above macros refer to:
4741:
4742: @table @code
4743: @item used
4744: This flag is used only momentarily, at the end of RTL generation for a
4745: function, to count the number of times an expression appears in insns.
4746: Expressions that appear more than once are copied, according to the
4747: rules for shared structure (@pxref{Sharing}).
4748:
4749: @item volatil
1.1.1.10 root 4750: This flag is used in @code{mem},@code{symbol_ref} and @code{reg} expressions
4751: and in insns. In RTL dump files, it is printed as @samp{/v}.
1.1 root 4752:
1.1.1.8 root 4753: In a @code{mem} expression, it is 1 if the memory reference is volatile.
1.1 root 4754: Volatile memory references may not be deleted, reordered or combined.
4755:
1.1.1.8 root 4756: In a @code{reg} expression, it is 1 if the value is a user-level variable.
1.1 root 4757: 0 indicates an internal compiler temporary.
4758:
1.1.1.10 root 4759: In a @code{symbol_ref} expression, it is 1 if the symbol is declared
4760: @code{extern}.
4761:
1.1 root 4762: In an insn, 1 means the insn has been deleted.
4763:
4764: @item in_struct
1.1.1.8 root 4765: This flag is used in @code{mem} expressions. It is 1 if the memory
1.1 root 4766: datum referred to is all or part of a structure or array; 0 if it is (or
4767: might be) a scalar variable. A reference through a C pointer has 0
4768: because the pointer might point to a scalar variable.
4769:
4770: This information allows the compiler to determine something about possible
4771: cases of aliasing.
4772:
4773: In an RTL dump, this flag is represented as @samp{/s}.
4774:
4775: @item unchanging
1.1.1.8 root 4776: This flag is used in @code{reg} and @code{mem} expressions. 1 means
1.1 root 4777: that the value of the expression never changes (at least within the
4778: current function).
4779:
4780: In an RTL dump, this flag is represented as @samp{/u}.
4781:
4782: @item integrated
4783: In some kinds of expressions, including insns, this flag means the
4784: rtl was produced by procedure integration.
4785:
1.1.1.8 root 4786: In a @code{reg} expression, this flag indicates the register
1.1 root 4787: containing the value to be returned by the current function. On
4788: machines that pass parameters in registers, the same register number
4789: may be used for parameters as well, but this flag is not set on such
4790: uses.
4791: @end table
4792:
4793: @node Machine Modes, Constants, Flags, RTL
4794: @section Machine Modes
4795:
4796: A machine mode describes a size of data object and the representation used
4797: for it. In the C code, machine modes are represented by an enumeration
4798: type, @code{enum machine_mode}, defined in @file{machmode.def}. Each RTL
4799: expression has room for a machine mode and so do certain kinds of tree
4800: expressions (declarations and types, to be precise).
4801:
4802: In debugging dumps and machine descriptions, the machine mode of an RTL
4803: expression is written after the expression code with a colon to separate
4804: them. The letters @samp{mode} which appear at the end of each machine mode
1.1.1.8 root 4805: name are omitted. For example, @code{(reg:SI 38)} is a @code{reg}
1.1 root 4806: expression with machine mode @code{SImode}. If the mode is
4807: @code{VOIDmode}, it is not written at all.
4808:
4809: Here is a table of machine modes.
4810:
4811: @table @code
4812: @item QImode
4813: ``Quarter-Integer'' mode represents a single byte treated as an integer.
4814:
4815: @item HImode
4816: ``Half-Integer'' mode represents a two-byte integer.
4817:
1.1.1.7 root 4818: @item PSImode
4819: ``Partial Single Integer'' mode represents an integer which occupies
4820: four bytes but which doesn't really use all four. On some machines,
4821: this is the right mode to use for pointers.
4822:
1.1 root 4823: @item SImode
4824: ``Single Integer'' mode represents a four-byte integer.
4825:
1.1.1.7 root 4826: @item PDImode
4827: ``Partial Double Integer'' mode represents an integer which occupies
4828: eight bytes but which doesn't really use all eight. On some machines,
4829: this is the right mode to use for certain pointers.
4830:
1.1 root 4831: @item DImode
4832: ``Double Integer'' mode represents an eight-byte integer.
4833:
4834: @item TImode
4835: ``Tetra Integer'' (?) mode represents a sixteen-byte integer.
4836:
4837: @item SFmode
4838: ``Single Floating'' mode represents a single-precision (four byte) floating
4839: point number.
4840:
4841: @item DFmode
4842: ``Double Floating'' mode represents a double-precision (eight byte) floating
4843: point number.
4844:
1.1.1.7 root 4845: @item XFmode
4846: ``Extended Floating'' mode represents a triple-precision (twelve byte)
4847: floating point number. This mode is used for IEEE extended floating
4848: point.
4849:
1.1 root 4850: @item TFmode
4851: ``Tetra Floating'' mode represents a quadruple-precision (sixteen byte)
4852: floating point number.
4853:
4854: @item BLKmode
4855: ``Block'' mode represents values that are aggregates to which none of
4856: the other modes apply. In RTL, only memory references can have this mode,
4857: and only if they appear in string-move or vector instructions. On machines
4858: which have no such instructions, @code{BLKmode} will not appear in RTL.
4859:
4860: @item VOIDmode
4861: Void mode means the absence of a mode or an unspecified mode.
1.1.1.8 root 4862: For example, RTL expressions of code @code{const_int} have mode
1.1 root 4863: @code{VOIDmode} because they can be taken to have whatever mode the context
4864: requires. In debugging dumps of RTL, @code{VOIDmode} is expressed by
4865: the absence of any mode.
4866:
4867: @item EPmode
4868: ``Entry Pointer'' mode is intended to be used for function variables in
4869: Pascal and other block structured languages. Such values contain
4870: both a function address and a static chain pointer for access to
4871: automatic variables of outer levels. This mode is only partially
4872: implemented since C does not use it.
4873:
4874: @item CSImode@r{, @dots{}}
4875: ``Complex Single Integer'' mode stands for a complex number represented
4876: as a pair of @code{SImode} integers. Any of the integer and floating modes
4877: may have @samp{C} prefixed to its name to obtain a complex number mode.
4878: For example, there are @code{CQImode}, @code{CSFmode}, and @code{CDFmode}.
4879: Since C does not support complex numbers, these machine modes are only
4880: partially implemented.
4881:
4882: @item BImode
4883: This is the machine mode of a bit-field in a structure. It is used
4884: only in the syntax tree, never in RTL, and in the syntax tree it appears
4885: only in declaration nodes. In C, it appears only in @code{FIELD_DECL}
4886: nodes for structure fields defined with a bit size.
4887: @end table
4888:
4889: The machine description defines @code{Pmode} as a C macro which expands
4890: into the machine mode used for addresses. Normally this is @code{SImode}.
4891:
4892: The only modes which a machine description @i{must} support are
4893: @code{QImode}, @code{SImode}, @code{SFmode} and @code{DFmode}. The
4894: compiler will attempt to use @code{DImode} for two-word structures and
1.1.1.7 root 4895: unions, but this can be prevented by overriding the definition of
4896: @code{MAX_FIXED_MODE_SIZE}. Likewise, you can arrange for the C type
4897: @code{short int} to avoid using @code{HImode}. In the long term it
4898: might be desirable to make the set of available machine modes
4899: machine-dependent and eliminate all assumptions about specific machine
4900: modes or their uses from the machine-independent code of the compiler.
1.1 root 4901:
1.1.1.4 root 4902: To help begin this process, the machine modes are divided into mode
4903: classes. These are represented by the enumeration type @code{enum
4904: mode_class} defined in @file{rtl.h}. The possible mode classes are:
4905:
4906: @table @code
4907: @item MODE_INT
4908: Integer modes. By default these are @code{QImode}, @code{HImode},
4909: @code{SImode}, @code{DImode}, @code{TImode}, and also @code{BImode}.
4910:
4911: @item MODE_FLOAT
4912: Floating-point modes. By default these are @code{QFmode},
4913: @code{HFmode}, @code{SFmode}, @code{DFmode} and @code{TFmode}, but the
4914: MC68881 also defines @code{XFmode} to be an 80-bit extended-precision
4915: floating-point mode.
4916:
4917: @item MODE_COMPLEX_INT
4918: Complex integer modes. By default these are @code{CQImode},
4919: @code{CHImode}, @code{CSImode}, @code{CDImode} and @code{CTImode}.
4920:
4921: @item MODE_COMPLEX_FLOAT
4922: Complex floating-point modes. By default these are @code{CQFmode},
4923: @code{CHFmode}, @code{CSFmode}, @code{CDFmode} and @code{CTFmode},
4924:
4925: @item MODE_FUNCTION
4926: Algol or Pascal function variables including a static chain.
4927: (These are not currently implemented).
4928:
4929: @item MODE_RANDOM
4930: This is a catchall mode class for modes which don't fit into the above
4931: classes. Currently @code{VOIDmode}, @code{BLKmode} and @code{EPmode}
4932: are in @code{MODE_RANDOM}.
4933: @end table
4934:
1.1 root 4935: Here are some C macros that relate to machine modes:
4936:
4937: @table @code
4938: @item GET_MODE (@var{x})
4939: Returns the machine mode of the RTX @var{x}.
4940:
4941: @item PUT_MODE (@var{x}, @var{newmode})
4942: Alters the machine mode of the RTX @var{x} to be @var{newmode}.
4943:
1.1.1.4 root 4944: @item NUM_MACHINE_MODES
4945: Stands for the number of machine modes available on the target
4946: machine. This is one greater than the largest numeric value of any
4947: machine mode.
4948:
4949: @item GET_MODE_NAME (@var{m})
4950: Returns the name of mode @var{m} as a string.
4951:
4952: @item GET_MODE_CLASS (@var{m})
4953: Returns the mode class of mode @var{m}.
4954:
1.1 root 4955: @item GET_MODE_SIZE (@var{m})
4956: Returns the size in bytes of a datum of mode @var{m}.
4957:
4958: @item GET_MODE_BITSIZE (@var{m})
4959: Returns the size in bits of a datum of mode @var{m}.
4960:
4961: @item GET_MODE_UNIT_SIZE (@var{m})
4962: Returns the size in bits of the subunits of a datum of mode @var{m}.
4963: This is the same as @code{GET_MODE_SIZE} except in the case of
4964: complex modes and @code{EPmode}. For them, the unit size is the
4965: size of the real or imaginary part, or the size of the function
4966: pointer or the context pointer.
4967: @end table
4968:
4969: @node Constants, Regs and Memory, Machine Modes, RTL
4970: @section Constant Expression Types
4971:
4972: The simplest RTL expressions are those that represent constant values.
4973:
4974: @table @code
4975: @item (const_int @var{i})
4976: This type of expression represents the integer value @var{i}. @var{i}
4977: is customarily accessed with the macro @code{INTVAL} as in
4978: @code{INTVAL (@var{exp})}, which is equivalent to @code{XINT (@var{exp}, 0)}.
4979:
4980: There is only one expression object for the integer value zero;
4981: it is the value of the variable @code{const0_rtx}. Likewise, the
4982: only expression for integer value one is found in @code{const1_rtx}.
1.1.1.8 root 4983: Any attempt to create an expression of code @code{const_int} and
1.1 root 4984: value zero or one will return @code{const0_rtx} or @code{const1_rtx}
4985: as appropriate.
4986:
4987: @item (const_double:@var{m} @var{i0} @var{i1})
1.1.1.6 root 4988: Represents a 64-bit constant of mode @var{m}. All floating point
1.1 root 4989: constants are represented in this way, and so are 64-bit @code{DImode}
4990: integer constants.
4991:
4992: The two integers @var{i0} and @var{i1} together contain the bits of
4993: the value. If the constant is floating point (either single or double
4994: precision), then they represent a @code{double}. To convert them to a
4995: @code{double}, do
4996:
4997: @example
4998: union @{ double d; int i[2];@} u;
1.1.1.8 root 4999: u.i[0] = CONST_DOUBLE_LOW(x);
5000: u.i[1] = CONST_DOUBLE_HIGH(x);
1.1 root 5001: @end example
5002:
5003: @noindent
5004: and then refer to @code{u.d}.
5005:
5006: The global variables @code{dconst0_rtx} and @code{fconst0_rtx} hold
1.1.1.8 root 5007: @code{const_double} expressions with value 0, in modes @code{DFmode}
1.1.1.7 root 5008: and @code{SFmode}, respectively. The macro @code{CONST0_RTX
1.1.1.8 root 5009: (@var{mode})} refers to a @code{const_double} expression with value 0
1.1.1.7 root 5010: in mode @var{mode}. The mode @var{mode} must be of mode class
5011: @code{MODE_FLOAT}.
1.1 root 5012:
5013: @item (symbol_ref @var{symbol})
5014: Represents the value of an assembler label for data. @var{symbol} is
5015: a string that describes the name of the assembler label. If it starts
5016: with a @samp{*}, the label is the rest of @var{symbol} not including
5017: the @samp{*}. Otherwise, the label is @var{symbol}, prefixed with
5018: @samp{_}.
5019:
5020: @item (label_ref @var{label})
5021: Represents the value of an assembler label for code. It contains one
1.1.1.8 root 5022: operand, an expression, which must be a @code{code_label} that appears
1.1 root 5023: in the instruction sequence to identify the place where the label
5024: should go.
5025:
5026: The reason for using a distinct expression type for code label
5027: references is so that jump optimization can distinguish them.
5028:
5029: @item (const @var{exp})
5030: Represents a constant that is the result of an assembly-time
5031: arithmetic computation. The operand, @var{exp}, is an expression that
1.1.1.8 root 5032: contains only constants (@code{const_int}, @code{symbol_ref} and
5033: @code{label_ref} expressions) combined with @code{plus} and
5034: @code{minus}. However, not all combinations are valid, since the
1.1 root 5035: assembler cannot do arbitrary arithmetic on relocatable symbols.
5036: @end table
5037:
5038: @node Regs and Memory, Arithmetic, Constants, RTL
5039: @section Registers and Memory
5040:
5041: Here are the RTL expression types for describing access to machine
5042: registers and to main memory.
5043:
5044: @table @code
5045: @item (reg:@var{m} @var{n})
5046: For small values of the integer @var{n} (less than
5047: @code{FIRST_PSEUDO_REGISTER}), this stands for a reference to machine
5048: register number @var{n}: a @dfn{hard register}. For larger values of
5049: @var{n}, it stands for a temporary value or @dfn{pseudo register}.
5050: The compiler's strategy is to generate code assuming an unlimited
5051: number of such pseudo registers, and later convert them into hard
5052: registers or into memory references.
5053:
5054: The symbol @code{FIRST_PSEUDO_REGISTER} is defined by the machine
5055: description, since the number of hard registers on the machine is an
5056: invariant characteristic of the machine. Note, however, that not
5057: all of the machine registers must be general registers. All the
5058: machine registers that can be used for storage of data are given
5059: hard register numbers, even those that can be used only in certain
5060: instructions or can hold only certain types of data.
5061:
5062: Each pseudo register number used in a function's RTL code is
1.1.1.8 root 5063: represented by a unique @code{reg} expression.
1.1 root 5064:
5065: @var{m} is the machine mode of the reference. It is necessary because
5066: machines can generally refer to each register in more than one mode.
5067: For example, a register may contain a full word but there may be
5068: instructions to refer to it as a half word or as a single byte, as
5069: well as instructions to refer to it as a floating point number of
5070: various precisions.
5071:
5072: Even for a register that the machine can access in only one mode,
5073: the mode must always be specified.
5074:
5075: A hard register may be accessed in various modes throughout one
5076: function, but each pseudo register is given a natural mode
5077: and is accessed only in that mode. When it is necessary to describe
1.1.1.8 root 5078: an access to a pseudo register using a nonnatural mode, a @code{subreg}
1.1 root 5079: expression is used.
5080:
1.1.1.8 root 5081: A @code{reg} expression with a machine mode that specifies more than
1.1 root 5082: one word of data may actually stand for several consecutive registers.
5083: If in addition the register number specifies a hardware register, then
5084: it actually represents several consecutive hardware registers starting
5085: with the specified one.
5086:
1.1.1.8 root 5087: Such multi-word hardware register @code{reg} expressions must not be live
1.1 root 5088: across the boundary of a basic block. The lifetime analysis pass does not
5089: know how to record properly that several consecutive registers are
5090: actually live there, and therefore register allocation would be confused.
5091: The CSE pass must go out of its way to make sure the situation does
5092: not arise.
5093:
5094: @item (subreg:@var{m} @var{reg} @var{wordnum})
1.1.1.8 root 5095: @code{subreg} expressions are used to refer to a register in a machine
1.1 root 5096: mode other than its natural one, or to refer to one register of
1.1.1.8 root 5097: a multi-word @code{reg} that actually refers to several registers.
1.1 root 5098:
5099: Each pseudo-register has a natural mode. If it is necessary to
5100: operate on it in a different mode---for example, to perform a fullword
1.1.1.8 root 5101: move instruction on a pseudo-register that contains a single
5102: byte---the pseudo-register must be enclosed in a @code{subreg}. In
5103: such a case, @var{wordnum} is zero.
1.1 root 5104:
1.1.1.8 root 5105: The other use of @code{subreg} is to extract the individual registers
1.1 root 5106: of a multi-register value. Machine modes such as @code{DImode} and
5107: @code{EPmode} indicate values longer than a word, values which usually
5108: require two consecutive registers. To access one of the registers,
1.1.1.8 root 5109: use a @code{subreg} with mode @code{SImode} and a @var{wordnum} that
1.1 root 5110: says which register.
5111:
5112: The compilation parameter @code{WORDS_BIG_ENDIAN}, if defined, says
5113: that word number zero is the most significant part; otherwise, it is
5114: the least significant part.
5115:
5116: Between the combiner pass and the reload pass, it is possible to have
1.1.1.8 root 5117: a @code{subreg} which contains a @code{mem} instead of a @code{reg} as
1.1 root 5118: its first operand. The reload pass eliminates these cases by
1.1.1.8 root 5119: reloading the @code{mem} into a suitable register.
1.1 root 5120:
5121: Note that it is not valid to access a @code{DFmode} value in @code{SFmode}
1.1.1.8 root 5122: using a @code{subreg}. On some machines the most significant part of a
1.1 root 5123: @code{DFmode} value does not have the same format as a single-precision
5124: floating value.
5125:
5126: @item (cc0)
5127: This refers to the machine's condition code register. It has no
1.1.1.10 root 5128: operands and may not have a machine mode. There are two ways to use it:
5129:
5130: @itemize @bullet
5131: @item
5132: To stand for a complete set of condition code flags. This is best on
5133: most machines, where each comparison sets the entire series of flags.
5134:
5135: With this technique, @code{(cc0)} may be validly used in only two
5136: contexts: as the destination of an assignment (in test and compare
5137: instructions) and in comparison operators comparing against zero
5138: (@code{const_int} with value zero; that is to say, @code{const0_rtx}).
5139:
5140: @item
5141: To stand for a single flag that is the result of a single condition.
5142: This is useful on machines that have only a single flag bit, and in
5143: which comparison instructions must specify the condition to test.
5144:
5145: With this technique, @code{(cc0)} may be validly used in only two
5146: contexts: as the destination of an assignment (in test and compare
5147: instructions) where the source is a comparison operator, and as the
5148: first operand of @code{if_then_else} (in a conditional branch).
5149: @end itemize
1.1 root 5150:
1.1.1.8 root 5151: There is only one expression object of code @code{cc0}; it is the
1.1 root 5152: value of the variable @code{cc0_rtx}. Any attempt to create an
1.1.1.8 root 5153: expression of code @code{cc0} will return @code{cc0_rtx}.
1.1 root 5154:
5155: One special thing about the condition code register is that
5156: instructions can set it implicitly. On many machines, nearly all
5157: instructions set the condition code based on the value that they
5158: compute or store. It is not necessary to record these actions
5159: explicitly in the RTL because the machine description includes a
5160: prescription for recognizing the instructions that do so (by means of
5161: the macro @code{NOTICE_UPDATE_CC}). Only instructions whose sole
5162: purpose is to set the condition code, and instructions that use the
5163: condition code, need mention @code{(cc0)}.
5164:
1.1.1.10 root 5165: In some cases, better code may result from recognizing combinations or
5166: peepholes that include instructions that set the condition codes, even
5167: in cases where some reloading is inevitable. For examples, search for
5168: @samp{addcc} and @samp{andcc} in @file{sparc.md}.
5169:
1.1 root 5170: @item (pc)
5171: This represents the machine's program counter. It has no operands and
5172: may not have a machine mode. @code{(pc)} may be validly used only in
5173: certain specific contexts in jump instructions.
5174:
1.1.1.8 root 5175: There is only one expression object of code @code{pc}; it is the value
1.1 root 5176: of the variable @code{pc_rtx}. Any attempt to create an expression of
1.1.1.8 root 5177: code @code{pc} will return @code{pc_rtx}.
1.1 root 5178:
5179: All instructions that do not jump alter the program counter implicitly
5180: by incrementing it, but there is no need to mention this in the RTL.
5181:
5182: @item (mem:@var{m} @var{addr})
5183: This RTX represents a reference to main memory at an address
5184: represented by the expression @var{addr}. @var{m} specifies how large
5185: a unit of memory is accessed.
5186: @end table
5187:
5188: @node Arithmetic, Comparisons, Regs and Memory, RTL
5189: @section RTL Expressions for Arithmetic
5190:
5191: @table @code
5192: @item (plus:@var{m} @var{x} @var{y})
5193: Represents the sum of the values represented by @var{x} and @var{y}
5194: carried out in machine mode @var{m}. This is valid only if
5195: @var{x} and @var{y} both are valid for mode @var{m}.
5196:
5197: @item (minus:@var{m} @var{x} @var{y})
1.1.1.8 root 5198: Like @code{plus} but represents subtraction.
1.1 root 5199:
1.1.1.6 root 5200: @item (compare @var{x} @var{y})
1.1 root 5201: Represents the result of subtracting @var{y} from @var{x}
5202: for purposes of comparison. The absence of a machine mode
1.1.1.8 root 5203: in the @code{compare} expression indicates that the result is
1.1 root 5204: computed without overflow, as if with infinite precision.
5205:
5206: Of course, machines can't really subtract with infinite precision.
5207: However, they can pretend to do so when only the sign of the
5208: result will be used, which is the case when the result is stored
5209: in @code{(cc0)}. And that is the only way this kind of expression
5210: may validly be used: as a value to be stored in the condition codes.
5211:
5212: @item (neg:@var{m} @var{x})
5213: Represents the negation (subtraction from zero) of the value
5214: represented by @var{x}, carried out in mode @var{m}. @var{x} must be
5215: valid for mode @var{m}.
5216:
5217: @item (mult:@var{m} @var{x} @var{y})
5218: Represents the signed product of the values represented by @var{x} and
5219: @var{y} carried out in machine mode @var{m}. If
5220: @var{x} and @var{y} are both valid for mode @var{m}, this is ordinary
5221: size-preserving multiplication. Alternatively, both @var{x} and @var{y}
5222: may be valid for a different, narrower mode. This represents the
5223: kind of multiplication that generates a product wider than the operands.
5224: Widening multiplication and same-size multiplication are completely
5225: distinct and supported by different machine instructions; machines may
5226: support one but not the other.@refill
5227:
1.1.1.8 root 5228: @code{mult} may be used for floating point multiplication as well.
1.1 root 5229: Then @var{m} is a floating point machine mode.
5230:
5231: @item (umult:@var{m} @var{x} @var{y})
1.1.1.8 root 5232: Like @code{mult} but represents unsigned multiplication. It may be
5233: used in both same-size and widening forms, like @code{mult}.
5234: @code{umult} is used only for fixed-point multiplication.
1.1 root 5235:
5236: @item (div:@var{m} @var{x} @var{y})
5237: Represents the quotient in signed division of @var{x} by @var{y},
5238: carried out in machine mode @var{m}. If @var{m} is a floating-point
5239: mode, it represents the exact quotient; otherwise, the integerized
5240: quotient. If @var{x} and @var{y} are both valid for mode @var{m},
5241: this is ordinary size-preserving division. Some machines have
5242: division instructions in which the operands and quotient widths are
1.1.1.8 root 5243: not all the same; such instructions are represented by @code{div}
1.1 root 5244: expressions in which the machine modes are not all the same.
5245:
5246: @item (udiv:@var{m} @var{x} @var{y})
1.1.1.8 root 5247: Like @code{div} but represents unsigned division.
1.1 root 5248:
5249: @item (mod:@var{m} @var{x} @var{y})
5250: @itemx (umod:@var{m} @var{x} @var{y})
1.1.1.8 root 5251: Like @code{div} and @code{udiv} but represent the remainder instead of
1.1 root 5252: the quotient.
5253:
5254: @item (not:@var{m} @var{x})
5255: Represents the bitwise complement of the value represented by @var{x},
5256: carried out in mode @var{m}, which must be a fixed-point machine mode.
5257: @var{x} must be valid for mode @var{m}, which must be a fixed-point mode.
5258:
5259: @item (and:@var{m} @var{x} @var{y})
5260: Represents the bitwise logical-and of the values represented by
5261: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
5262: valid only if @var{x} and @var{y} both are valid for mode @var{m},
5263: which must be a fixed-point mode.
5264:
5265: @item (ior:@var{m} @var{x} @var{y})
5266: Represents the bitwise inclusive-or of the values represented by
5267: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
5268: valid only if @var{x} and @var{y} both are valid for mode @var{m},
5269: which must be a fixed-point mode.
5270:
5271: @item (xor:@var{m} @var{x} @var{y})
5272: Represents the bitwise exclusive-or of the values represented by
5273: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
5274: valid only if @var{x} and @var{y} both are valid for mode @var{m},
5275: which must be a fixed-point mode.
5276:
5277: @item (lshift:@var{m} @var{x} @var{c})
5278: Represents the result of logically shifting @var{x} left by @var{c}
5279: places. @var{x} must be valid for the mode @var{m}, a fixed-point
5280: machine mode. @var{c} must be valid for a fixed-point mode;
5281: which mode is determined by the mode called for in the machine
5282: description entry for the left-shift instruction. For example,
5283: on the Vax, the mode of @var{c} is @code{QImode} regardless of @var{m}.
5284:
5285: On some machines, negative values of @var{c} may be meaningful; this
5286: is why logical left shift and arithmetic left shift are distinguished.
5287: For example, Vaxes have no right-shift instructions, and right shifts
5288: are represented as left-shift instructions whose counts happen
5289: to be negative constants or else computed (in a previous instruction)
5290: by negation.
5291:
5292: @item (ashift:@var{m} @var{x} @var{c})
1.1.1.8 root 5293: Like @code{lshift} but for arithmetic left shift.
1.1 root 5294:
5295: @item (lshiftrt:@var{m} @var{x} @var{c})
5296: @itemx (ashiftrt:@var{m} @var{x} @var{c})
1.1.1.8 root 5297: Like @code{lshift} and @code{ashift} but for right shift.
1.1 root 5298:
5299: @item (rotate:@var{m} @var{x} @var{c})
5300: @itemx (rotatert:@var{m} @var{x} @var{c})
5301: Similar but represent left and right rotate.
5302:
5303: @item (abs:@var{m} @var{x})
5304: Represents the absolute value of @var{x}, computed in mode @var{m}.
5305: @var{x} must be valid for @var{m}.
5306:
5307: @item (sqrt:@var{m} @var{x})
5308: Represents the square root of @var{x}, computed in mode @var{m}.
5309: @var{x} must be valid for @var{m}. Most often @var{m} will be
5310: a floating point mode.
5311:
5312: @item (ffs:@var{m} @var{x})
1.1.1.10 root 5313: Represents one plus the index of the least significant 1-bit in
1.1 root 5314: @var{x}, represented as an integer of mode @var{m}. (The value is
5315: zero if @var{x} is zero.) The mode of @var{x} need not be @var{m};
5316: depending on the target machine, various mode combinations may be
5317: valid.
5318: @end table
5319:
5320: @node Comparisons, Bit Fields, Arithmetic, RTL
5321: @section Comparison Operations
5322:
1.1.1.10 root 5323: Comparison operators test a relation on two operands and are considered
5324: to represent a machine-dependent nonzero value (@code{STORE_FLAG_VALUE})
5325: if the relation holds, or zero if it does not. The mode of the
5326: comparison is determined by the operands; they must both be valid for a
5327: common machine mode. A comparison with both operands constant would be
5328: invalid as the machine mode could not be deduced from it, but such a
5329: comparison should never exist in RTL due to constant folding.
1.1 root 5330:
5331: Inequality comparisons come in two flavors, signed and unsigned. Thus,
1.1.1.8 root 5332: there are distinct expression codes @code{gt} and @code{gtu} for signed and
1.1 root 5333: unsigned greater-than. These can produce different results for the same
5334: pair of integer values: for example, 1 is signed greater-than -1 but not
5335: unsigned greater-than, because -1 when regarded as unsigned is actually
5336: @code{0xffffffff} which is greater than 1.
5337:
5338: The signed comparisons are also used for floating point values. Floating
5339: point comparisons are distinguished by the machine modes of the operands.
5340:
5341: The comparison operators may be used to compare the condition codes
5342: @code{(cc0)} against zero, as in @code{(eq (cc0) (const_int 0))}. Such a
5343: construct actually refers to the result of the preceding instruction in
5344: which the condition codes were set. The above example stands for 1 if the
5345: condition codes were set to say ``zero'' or ``equal'', 0 otherwise.
5346: Although the same comparison operators are used for this as may be used in
5347: other contexts on actual data, no confusion can result since the machine
5348: description would never allow both kinds of uses in the same context.
5349:
5350: @table @code
5351: @item (eq @var{x} @var{y})
5352: 1 if the values represented by @var{x} and @var{y} are equal,
5353: otherwise 0.
5354:
5355: @item (ne @var{x} @var{y})
5356: 1 if the values represented by @var{x} and @var{y} are not equal,
5357: otherwise 0.
5358:
5359: @item (gt @var{x} @var{y})
5360: 1 if the @var{x} is greater than @var{y}. If they are fixed-point,
5361: the comparison is done in a signed sense.
5362:
5363: @item (gtu @var{x} @var{y})
1.1.1.8 root 5364: Like @code{gt} but does unsigned comparison, on fixed-point numbers only.
1.1 root 5365:
5366: @item (lt @var{x} @var{y})
5367: @item (ltu @var{x} @var{y})
1.1.1.8 root 5368: Like @code{gt} and @code{gtu} but test for ``less than''.
1.1 root 5369:
5370: @item (ge @var{x} @var{y})
5371: @item (geu @var{x} @var{y})
1.1.1.8 root 5372: Like @code{gt} and @code{gtu} but test for ``greater than or equal''.
1.1 root 5373:
5374: @item (le @var{x} @var{y})
5375: @item (leu @var{x} @var{y})
1.1.1.8 root 5376: Like @code{gt} and @code{gtu} but test for ``less than or equal''.
1.1 root 5377:
5378: @item (if_then_else @var{cond} @var{then} @var{else})
5379: This is not a comparison operation but is listed here because it is
5380: always used in conjunction with a comparison operation. To be
5381: precise, @var{cond} is a comparison expression. This expression
5382: represents a choice, according to @var{cond}, between the value
5383: represented by @var{then} and the one represented by @var{else}.
5384:
1.1.1.8 root 5385: On most machines, @code{if_then_else} expressions are valid only
1.1 root 5386: to express conditional jumps.
5387: @end table
5388:
5389: @node Bit Fields, Conversions, Comparisons, RTL
5390: @section Bit-fields
5391:
5392: Special expression codes exist to represent bit-field instructions.
5393: These types of expressions are lvalues in RTL; they may appear
1.1.1.10 root 5394: on the left side of an assignment, indicating insertion of a value
1.1 root 5395: into the specified bit field.
5396:
5397: @table @code
5398: @item (sign_extract:SI @var{loc} @var{size} @var{pos})
5399: This represents a reference to a sign-extended bit-field contained or
5400: starting in @var{loc} (a memory or register reference). The bit field
5401: is @var{size} bits wide and starts at bit @var{pos}. The compilation
5402: option @code{BITS_BIG_ENDIAN} says which end of the memory unit
5403: @var{pos} counts from.
5404:
5405: Which machine modes are valid for @var{loc} depends on the machine,
5406: but typically @var{loc} should be a single byte when in memory
5407: or a full word in a register.
5408:
5409: @item (zero_extract:SI @var{loc} @var{size} @var{pos})
1.1.1.8 root 5410: Like @code{sign_extract} but refers to an unsigned or zero-extended
1.1 root 5411: bit field. The same sequence of bits are extracted, but they
5412: are filled to an entire word with zeros instead of by sign-extension.
5413: @end table
5414:
5415: @node Conversions, RTL Declarations, Bit Fields, RTL
5416: @section Conversions
5417:
5418: All conversions between machine modes must be represented by
5419: explicit conversion operations. For example, an expression
5420: which is the sum of a byte and a full word cannot be written as
1.1.1.8 root 5421: @code{(plus:SI (reg:QI 34) (reg:SI 80))} because the @code{plus}
1.1 root 5422: operation requires two operands of the same machine mode.
5423: Therefore, the byte-sized operand is enclosed in a conversion
5424: operation, as in
5425:
5426: @example
5427: (plus:SI (sign_extend:SI (reg:QI 34)) (reg:SI 80))
5428: @end example
5429:
5430: The conversion operation is not a mere placeholder, because there
5431: may be more than one way of converting from a given starting mode
5432: to the desired final mode. The conversion operation code says how
5433: to do it.
5434:
5435: @table @code
5436: @item (sign_extend:@var{m} @var{x})
5437: Represents the result of sign-extending the value @var{x}
5438: to machine mode @var{m}. @var{m} must be a fixed-point mode
5439: and @var{x} a fixed-point value of a mode narrower than @var{m}.
5440:
5441: @item (zero_extend:@var{m} @var{x})
5442: Represents the result of zero-extending the value @var{x}
5443: to machine mode @var{m}. @var{m} must be a fixed-point mode
5444: and @var{x} a fixed-point value of a mode narrower than @var{m}.
5445:
5446: @item (float_extend:@var{m} @var{x})
5447: Represents the result of extending the value @var{x}
5448: to machine mode @var{m}. @var{m} must be a floating point mode
5449: and @var{x} a floating point value of a mode narrower than @var{m}.
5450:
5451: @item (truncate:@var{m} @var{x})
5452: Represents the result of truncating the value @var{x}
5453: to machine mode @var{m}. @var{m} must be a fixed-point mode
5454: and @var{x} a fixed-point value of a mode wider than @var{m}.
5455:
5456: @item (float_truncate:@var{m} @var{x})
5457: Represents the result of truncating the value @var{x}
5458: to machine mode @var{m}. @var{m} must be a floating point mode
5459: and @var{x} a floating point value of a mode wider than @var{m}.
5460:
5461: @item (float:@var{m} @var{x})
5462: Represents the result of converting fixed point value @var{x},
5463: regarded as signed, to floating point mode @var{m}.
5464:
5465: @item (unsigned_float:@var{m} @var{x})
5466: Represents the result of converting fixed point value @var{x},
5467: regarded as unsigned, to floating point mode @var{m}.
5468:
5469: @item (fix:@var{m} @var{x})
5470: When @var{m} is a fixed point mode, represents the result of
5471: converting floating point value @var{x} to mode @var{m}, regarded as
5472: signed. How rounding is done is not specified, so this operation may
5473: be used validly in compiling C code only for integer-valued operands.
5474:
5475: @item (unsigned_fix:@var{m} @var{x})
5476: Represents the result of converting floating point value @var{x} to
5477: fixed point mode @var{m}, regarded as unsigned. How rounding is done
5478: is not specified.
5479:
5480: @item (fix:@var{m} @var{x})
5481: When @var{m} is a floating point mode, represents the result of
5482: converting floating point value @var{x} (valid for mode @var{m}) to an
5483: integer, still represented in floating point mode @var{m}, by rounding
5484: towards zero.
5485: @end table
5486:
5487: @node RTL Declarations, Side Effects, Conversions, RTL
5488: @section Declarations
5489:
5490: Declaration expression codes do not represent arithmetic operations
5491: but rather state assertions about their operands.
5492:
5493: @table @code
5494: @item (strict_low_part (subreg:@var{m} (reg:@var{n} @var{r}) 0))
5495: This expression code is used in only one context: operand 0 of a
1.1.1.8 root 5496: @code{set} expression. In addition, the operand of this expression
5497: must be a @code{subreg} expression.
1.1 root 5498:
1.1.1.8 root 5499: The presence of @code{strict_low_part} says that the part of the
1.1 root 5500: register which is meaningful in mode @var{n}, but is not part of
5501: mode @var{m}, is not to be altered. Normally, an assignment to such
5502: a subreg is allowed to have undefined effects on the rest of the
5503: register when @var{m} is less than a word.
5504: @end table
5505:
5506: @node Side Effects, Incdec, RTL Declarations, RTL
5507: @section Side Effect Expressions
5508:
5509: The expression codes described so far represent values, not actions.
5510: But machine instructions never produce values; they are meaningful
5511: only for their side effects on the state of the machine. Special
5512: expression codes are used to represent side effects.
5513:
5514: The body of an instruction is always one of these side effect codes;
5515: the codes described above, which represent values, appear only as
5516: the operands of these.
5517:
5518: @table @code
5519: @item (set @var{lval} @var{x})
5520: Represents the action of storing the value of @var{x} into the place
5521: represented by @var{lval}. @var{lval} must be an expression
1.1.1.8 root 5522: representing a place that can be stored in: @code{reg} (or
5523: @code{subreg} or @code{strict_low_part}), @code{mem}, @code{pc} or
5524: @code{cc0}.@refill
1.1 root 5525:
1.1.1.8 root 5526: If @var{lval} is a @code{reg}, @code{subreg} or @code{mem}, it has a
1.1 root 5527: machine mode; then @var{x} must be valid for that mode.@refill
5528:
1.1.1.8 root 5529: If @var{lval} is a @code{reg} whose machine mode is less than the full
1.1 root 5530: width of the register, then it means that the part of the register
5531: specified by the machine mode is given the specified value and the
5532: rest of the register receives an undefined value. Likewise, if
1.1.1.8 root 5533: @var{lval} is a @code{subreg} whose machine mode is narrower than
1.1 root 5534: @code{SImode}, the rest of the register can be changed in an undefined way.
5535:
1.1.1.8 root 5536: If @var{lval} is a @code{strict_low_part} of a @code{subreg}, then the
1.1 root 5537: part of the register specified by the machine mode of the
1.1.1.8 root 5538: @code{subreg} is given the value @var{x} and the rest of the register
1.1 root 5539: is not changed.@refill
5540:
5541: If @var{lval} is @code{(cc0)}, it has no machine mode, and @var{x} may
5542: have any mode. This represents a ``test'' or ``compare'' instruction.@refill
5543:
5544: If @var{lval} is @code{(pc)}, we have a jump instruction, and the
5545: possibilities for @var{x} are very limited. It may be a
1.1.1.8 root 5546: @code{label_ref} expression (unconditional jump). It may be an
5547: @code{if_then_else} (conditional jump), in which case either the
1.1 root 5548: second or the third operand must be @code{(pc)} (for the case which
1.1.1.8 root 5549: does not jump) and the other of the two must be a @code{label_ref}
5550: (for the case which does jump). @var{x} may also be a @code{mem} or
5551: @code{(plus:SI (pc) @var{y})}, where @var{y} may be a @code{reg} or a
5552: @code{mem}; these unusual patterns are used to represent jumps through
1.1 root 5553: branch tables.@refill
5554:
5555: @item (return)
5556: Represents a return from the current function, on machines where this
5557: can be done with one instruction, such as Vaxes. On machines where a
5558: multi-instruction ``epilogue'' must be executed in order to return
5559: from the function, returning is done by jumping to a label which
1.1.1.8 root 5560: precedes the epilogue, and the @code{return} expression code is never
1.1 root 5561: used.
5562:
5563: @item (call @var{function} @var{nargs})
1.1.1.8 root 5564: Represents a function call. @var{function} is a @code{mem} expression
1.1 root 5565: whose address is the address of the function to be called.
5566: @var{nargs} is an expression which can be used for two purposes: on
5567: some machines it represents the number of bytes of stack argument; on
5568: others, it represents the number of argument registers.
5569:
5570: Each machine has a standard machine mode which @var{function} must
5571: have. The machine description defines macro @code{FUNCTION_MODE} to
5572: expand into the requisite mode name. The purpose of this mode is to
5573: specify what kind of addressing is allowed, on machines where the
5574: allowed kinds of addressing depend on the machine mode being
5575: addressed.
5576:
5577: @item (clobber @var{x})
5578: Represents the storing or possible storing of an unpredictable,
1.1.1.8 root 5579: undescribed value into @var{x}, which must be a @code{reg} or
5580: @code{mem} expression.
1.1 root 5581:
5582: One place this is used is in string instructions that store standard
5583: values into particular hard registers. It may not be worth the
5584: trouble to describe the values that are stored, but it is essential to
5585: inform the compiler that the registers will be altered, lest it
5586: attempt to keep data in them across the string instruction.
5587:
5588: @var{x} may also be null---a null C pointer, no expression at all.
5589: Such a @code{(clobber (null))} expression means that all memory
5590: locations must be presumed clobbered.
5591:
5592: Note that the machine description classifies certain hard registers as
5593: ``call-clobbered''. All function call instructions are assumed by
5594: default to clobber these registers, so there is no need to use
1.1.1.8 root 5595: @code{clobber} expressions to indicate this fact. Also, each function
1.1.1.6 root 5596: call is assumed to have the potential to alter any memory location,
5597: unless the function is declared @code{const}.
1.1 root 5598:
1.1.1.8 root 5599: When a @code{clobber} expression for a register appears inside a
5600: @code{parallel} with other side effects, GNU CC guarantees that the
1.1.1.4 root 5601: register is unoccupied both before and after that insn. Therefore, it
5602: is safe for the assembler code produced by the insn to use the
5603: register as a temporary. You can clobber either a specific hard
5604: register or a pseudo register; in the latter case, GNU CC will
5605: allocate a hard register that is available there for use as a
5606: temporary.
5607:
1.1.1.8 root 5608: If you clobber a pseudo register in this way, use a pseudo register
5609: which appears nowhere else---generate a new one each time. Otherwise,
5610: you may confuse CSE.
5611:
5612: There is one other known use for clobbering a pseudo register in a
5613: @code{parallel}: when one of the input operands of the insn is also
5614: clobbered by the insn. In this case, using the same pseudo register in
5615: the clobber and elsewhere in the insn produces the expected results.
5616:
1.1 root 5617: @item (use @var{x})
5618: Represents the use of the value of @var{x}. It indicates that the
5619: value in @var{x} at this point in the program is needed, even though
5620: it may not be apparent why this is so. Therefore, the compiler will
1.1.1.4 root 5621: not attempt to delete previous instructions whose only effect is to
1.1.1.8 root 5622: store a value in @var{x}. @var{x} must be a @code{reg} expression.
1.1 root 5623:
5624: @item (parallel [@var{x0} @var{x1} @dots{}])
5625: Represents several side effects performed in parallel. The square
1.1.1.8 root 5626: brackets stand for a vector; the operand of @code{parallel} is a
1.1 root 5627: vector of expressions. @var{x0}, @var{x1} and so on are individual
1.1.1.8 root 5628: side effect expressions---expressions of code @code{set}, @code{call},
5629: @code{return}, @code{clobber} or @code{use}.@refill
1.1 root 5630:
5631: ``In parallel'' means that first all the values used in the individual
5632: side-effects are computed, and second all the actual side-effects are
5633: performed. For example,
5634:
5635: @example
5636: (parallel [(set (reg:SI 1) (mem:SI (reg:SI 1)))
5637: (set (mem:SI (reg:SI 1)) (reg:SI 1))])
5638: @end example
5639:
5640: @noindent
5641: says unambiguously that the values of hard register 1 and the memory
5642: location addressed by it are interchanged. In both places where
5643: @code{(reg:SI 1)} appears as a memory address it refers to the value
1.1.1.4 root 5644: in register 1 @emph{before} the execution of the insn.
5645:
1.1.1.8 root 5646: It follows that it is @emph{incorrect} to use @code{parallel} and
5647: expect the result of one @code{set} to be available for the next one.
1.1.1.4 root 5648: For example, people sometimes attempt to represent a jump-if-zero
5649: instruction this way:
5650:
5651: @example
5652: (parallel [(set (cc0) (reg:SI 34))
1.1.1.9 root 5653: (set (pc) (if_then_else
5654: (eq (cc0) (const_int 0))
5655: (label_ref @dots{})
5656: (pc)))])
1.1.1.4 root 5657: @end example
5658:
5659: @noindent
5660: But this is incorrect, because it says that the jump condition depends
5661: on the condition code value @emph{before} this instruction, not on the
5662: new value that is set by this instruction.
1.1 root 5663:
1.1.1.5 root 5664: Peephole optimization, which takes place in together with final assembly
1.1.1.8 root 5665: code output, can produce insns whose patterns consist of a @code{parallel}
1.1 root 5666: whose elements are the operands needed to output the resulting
1.1.1.8 root 5667: assembler code---often @code{reg}, @code{mem} or constant expressions.
1.1 root 5668: This would not be well-formed RTL at any other stage in compilation,
5669: but it is ok then because no further optimization remains to be done.
1.1.1.4 root 5670: However, the definition of the macro @code{NOTICE_UPDATE_CC} must
5671: deal with such insns if you define any peephole optimizations.
1.1 root 5672:
5673: @item (sequence [@var{insns} @dots{}])
5674: Represents a sequence of insns. Each of the @var{insns} that appears
5675: in the vector is suitable for appearing in the chain of insns, so it
1.1.1.8 root 5676: must be an @code{insn}, @code{jump_insn}, @code{call_insn},
5677: @code{code_label}, @code{barrier} or @code{note}.
1.1 root 5678:
1.1.1.8 root 5679: A @code{sequence} RTX never appears in an actual insn. It represents
5680: the sequence of insns that result from a @code{define_expand}
1.1 root 5681: @emph{before} those insns are passed to @code{emit_insn} to insert
5682: them in the chain of insns. When actually inserted, the individual
1.1.1.8 root 5683: sub-insns are separated out and the @code{sequence} is forgotten.
1.1 root 5684: @end table
5685:
5686: Three expression codes appear in place of a side effect, as the body of an
5687: insn, though strictly speaking they do not describe side effects as such:
5688:
5689: @table @code
5690: @item (asm_input @var{s})
5691: Represents literal assembler code as described by the string @var{s}.
5692:
5693: @item (addr_vec:@var{m} [@var{lr0} @var{lr1} @dots{}])
5694: Represents a table of jump addresses. The vector elements @var{lr0},
1.1.1.8 root 5695: etc., are @code{label_ref} expressions. The mode @var{m} specifies
1.1 root 5696: how much space is given to each address; normally @var{m} would be
5697: @code{Pmode}.
5698:
5699: @item (addr_diff_vec:@var{m} @var{base} [@var{lr0} @var{lr1} @dots{}])
5700: Represents a table of jump addresses expressed as offsets from
1.1.1.8 root 5701: @var{base}. The vector elements @var{lr0}, etc., are @code{label_ref}
1.1 root 5702: expressions and so is @var{base}. The mode @var{m} specifies how much
5703: space is given to each address-difference.@refill
5704: @end table
5705:
5706: @node Incdec, Assembler, Side Effects, RTL
5707: @section Embedded Side-Effects on Addresses
5708:
5709: Four special side-effect expression codes appear as memory addresses.
5710:
5711: @table @code
5712: @item (pre_dec:@var{m} @var{x})
5713: Represents the side effect of decrementing @var{x} by a standard
5714: amount and represents also the value that @var{x} has after being
1.1.1.8 root 5715: decremented. @var{x} must be a @code{reg} or @code{mem}, but most
5716: machines allow only a @code{reg}. @var{m} must be the machine mode
1.1 root 5717: for pointers on the machine in use. The amount @var{x} is decremented
5718: by is the length in bytes of the machine mode of the containing memory
5719: reference of which this expression serves as the address. Here is an
5720: example of its use:@refill
5721:
5722: @example
5723: (mem:DF (pre_dec:SI (reg:SI 39)))
5724: @end example
5725:
5726: @noindent
5727: This says to decrement pseudo register 39 by the length of a @code{DFmode}
5728: value and use the result to address a @code{DFmode} value.
5729:
5730: @item (pre_inc:@var{m} @var{x})
5731: Similar, but specifies incrementing @var{x} instead of decrementing it.
5732:
5733: @item (post_dec:@var{m} @var{x})
1.1.1.8 root 5734: Represents the same side effect as @code{pre_dec} but a different
1.1 root 5735: value. The value represented here is the value @var{x} has @i{before}
5736: being decremented.
5737:
5738: @item (post_inc:@var{m} @var{x})
5739: Similar, but specifies incrementing @var{x} instead of decrementing it.
5740: @end table
5741:
5742: These embedded side effect expressions must be used with care. Instruction
5743: patterns may not use them. Until the @samp{flow} pass of the compiler,
5744: they may occur only to represent pushes onto the stack. The @samp{flow}
5745: pass finds cases where registers are incremented or decremented in one
5746: instruction and used as an address shortly before or after; these cases are
5747: then transformed to use pre- or post-increment or -decrement.
5748:
5749: Explicit popping of the stack could be represented with these embedded
5750: side effect operators, but that would not be safe; the instruction
5751: combination pass could move the popping past pushes, thus changing
5752: the meaning of the code.
5753:
5754: An instruction that can be represented with an embedded side effect
1.1.1.8 root 5755: could also be represented using @code{parallel} containing an additional
5756: @code{set} to describe how the address register is altered. This is not
1.1 root 5757: done because machines that allow these operations at all typically
5758: allow them wherever a memory address is called for. Describing them as
5759: additional parallel stores would require doubling the number of entries
5760: in the machine description.
5761:
5762: @node Assembler, Insns, IncDec, RTL
5763: @section Assembler Instructions as Expressions
5764:
1.1.1.8 root 5765: The RTX code @code{asm_operands} represents a value produced by a
1.1 root 5766: user-specified assembler instruction. It is used to represent
5767: an @code{asm} statement with arguments. An @code{asm} statement with
5768: a single output operand, like this:
5769:
5770: @example
1.1.1.6 root 5771: asm ("foo %1,%2,%0" : "=a" (outputvar) : "g" (x + y), "di" (*z));
1.1 root 5772: @end example
5773:
5774: @noindent
1.1.1.8 root 5775: is represented using a single @code{asm_operands} RTX which represents
1.1 root 5776: the value that is stored in @code{outputvar}:
5777:
5778: @example
5779: (set @var{rtx-for-outputvar}
5780: (asm_operands "foo %1,%2,%0" "a" 0
5781: [@var{rtx-for-addition-result} @var{rtx-for-*z}]
5782: [(asm_input:@var{m1} "g")
5783: (asm_input:@var{m2} "di")]))
5784: @end example
5785:
5786: @noindent
1.1.1.8 root 5787: Here the operands of the @code{asm_operands} RTX are the assembler
1.1 root 5788: template string, the output-operand's constraint, the index-number of the
5789: output operand among the output operands specified, a vector of input
5790: operand RTX's, and a vector of input-operand modes and constraints. The
5791: mode @var{m1} is the mode of the sum @code{x+y}; @var{m2} is that of
5792: @code{*z}.
5793:
5794: When an @code{asm} statement has multiple output values, its insn has
1.1.1.8 root 5795: several such @code{set} RTX's inside of a @code{parallel}. Each @code{set}
5796: contains a @code{asm_operands}; all of these share the same assembler
1.1 root 5797: template and vectors, but each contains the constraint for the respective
5798: output operand. They are also distinguished by the output-operand index
5799: number, which is 0, 1, @dots{} for successive output operands.
5800:
5801: @node Insns, Calls, Assembler, RTL
5802: @section Insns
5803:
5804: The RTL representation of the code for a function is a doubly-linked
5805: chain of objects called @dfn{insns}. Insns are expressions with
5806: special codes that are used for no other purpose. Some insns are
5807: actual instructions; others represent dispatch tables for @code{switch}
5808: statements; others represent labels to jump to or various sorts of
5809: declarative information.
5810:
5811: In addition to its own specific data, each insn must have a unique id-number
5812: that distinguishes it from all other insns in the current function, and
5813: chain pointers to the preceding and following insns. These three fields
5814: occupy the same position in every insn, independent of the expression code
5815: of the insn. They could be accessed with @code{XEXP} and @code{XINT},
5816: but instead three special macros are always used:
5817:
5818: @table @code
5819: @item INSN_UID (@var{i})
5820: Accesses the unique id of insn @var{i}.
5821:
5822: @item PREV_INSN (@var{i})
5823: Accesses the chain pointer to the insn preceding @var{i}.
5824: If @var{i} is the first insn, this is a null pointer.
5825:
5826: @item NEXT_INSN (@var{i})
5827: Accesses the chain pointer to the insn following @var{i}.
5828: If @var{i} is the last insn, this is a null pointer.
5829: @end table
5830:
5831: The @code{NEXT_INSN} and @code{PREV_INSN} pointers must always
1.1.1.6 root 5832: correspond: if @var{insn} is not the first insn,
1.1 root 5833:
5834: @example
5835: NEXT_INSN (PREV_INSN (@var{insn})) == @var{insn}
5836: @end example
5837:
5838: @noindent
5839: is always true.
5840:
5841: Every insn has one of the following six expression codes:
5842:
1.1.1.8 root 5843: @table @code
1.1 root 5844: @item insn
1.1.1.8 root 5845: The expression code @code{insn} is used for instructions that do not jump
5846: and do not do function calls. Insns with code @code{insn} have four
1.1 root 5847: additional fields beyond the three mandatory ones listed above.
5848: These four are described in a table below.
5849:
5850: @item jump_insn
1.1.1.8 root 5851: The expression code @code{jump_insn} is used for instructions that may jump
5852: (or, more generally, may contain @code{label_ref} expressions).
5853: @code{jump_insn} insns have the same extra fields as @code{insn} insns,
1.1.1.10 root 5854: accessed in the same way. If there is an instruction to return from the
5855: current function, it is recorded as a @code{jump_insn}.
1.1 root 5856:
5857: @item call_insn
1.1.1.8 root 5858: The expression code @code{call_insn} is used for instructions that may do
1.1 root 5859: function calls. It is important to distinguish these instructions because
5860: they imply that certain registers and memory locations may be altered
5861: unpredictably.
5862:
1.1.1.8 root 5863: @code{call_insn} insns have the same extra fields as @code{insn} insns,
1.1 root 5864: accessed in the same way.
5865:
5866: @item code_label
1.1.1.8 root 5867: A @code{code_label} insn represents a label that a jump insn can jump to.
1.1 root 5868: It contains one special field of data in addition to the three standard ones.
5869: It is used to hold the @dfn{label number}, a number that identifies this
5870: label uniquely among all the labels in the compilation (not just in the
5871: current function). Ultimately, the label is represented in the assembler
5872: output as an assembler label @samp{L@var{n}} where @var{n} is the label number.
5873:
5874: @item barrier
5875: Barriers are placed in the instruction stream after unconditional
5876: jump instructions to indicate that the jumps are unconditional.
5877: They contain no information beyond the three standard fields.
5878:
5879: @item note
1.1.1.8 root 5880: @code{note} insns are used to represent additional debugging and
1.1 root 5881: declarative information. They contain two nonstandard fields, an
5882: integer which is accessed with the macro @code{NOTE_LINE_NUMBER} and a
5883: string accessed with @code{NOTE_SOURCE_FILE}.
5884:
5885: If @code{NOTE_LINE_NUMBER} is positive, the note represents the
5886: position of a source line and @code{NOTE_SOURCE_FILE} is the source file name
5887: that the line came from. These notes control generation of line
5888: number data in the assembler output.
5889:
5890: Otherwise, @code{NOTE_LINE_NUMBER} is not really a line number but a
5891: code with one of the following values (and @code{NOTE_SOURCE_FILE}
5892: must contain a null pointer):
5893:
5894: @table @code
5895: @item NOTE_INSN_DELETED
5896: Such a note is completely ignorable. Some passes of the compiler
5897: delete insns by altering them into notes of this kind.
5898:
5899: @item NOTE_INSN_BLOCK_BEG
5900: @itemx NOTE_INSN_BLOCK_END
5901: These types of notes indicate the position of the beginning and end
5902: of a level of scoping of variable names. They control the output
5903: of debugging information.
5904:
5905: @item NOTE_INSN_LOOP_BEG
5906: @itemx NOTE_INSN_LOOP_END
5907: These types of notes indicate the position of the beginning and end
5908: of a @code{while} or @code{for} loop. They enable the loop optimizer
5909: to find loops quickly.
1.1.1.6 root 5910: @item NOTE_INSN_FUNCTION_END
5911: Appears near the end of the function body, just before the label that
5912: @code{return} statements jump to (on machine where a single instruction
5913: does not suffice for returning). This note may be deleted by jump
5914: optimization.
5915: @item NOTE_INSN_SETJMP
5916: Appears following each call to @code{setjmp} or a related function.
1.1.1.7 root 5917:
1.1.1.10 root 5918: @item NOTE_INSN_LOOP_CONT
1.1.1.7 root 5919: Appears at the place in a loop that @code{continue} statements jump to.
1.1 root 5920: @end table
1.1.1.7 root 5921:
5922: These codes are printed symbolically when they appear in debugging dumps.
1.1 root 5923: @end table
5924:
1.1.1.6 root 5925: The machine mode of an insn is normally zero (@code{VOIDmode}), but the
5926: reload pass sets it to @code{QImode} if the insn needs reloading.
5927:
1.1.1.8 root 5928: Here is a table of the extra fields of @code{insn}, @code{jump_insn}
5929: and @code{call_insn} insns:
1.1 root 5930:
5931: @table @code
5932: @item PATTERN (@var{i})
5933: An expression for the side effect performed by this insn.
5934:
1.1.1.6 root 5935: @item INSN_CODE (@var{i})
5936: An integer that says which pattern in the machine description matches
5937: this insn, or -1 if the matching has not yet been attempted.
5938:
5939: Such matching is never attempted and this field is not used on an insn
1.1.1.8 root 5940: whose pattern consists of a single @code{use}, @code{clobber},
5941: @code{asm}, @code{addr_vec} or @code{addr_diff_vec} expression.
1.1 root 5942:
5943: @item LOG_LINKS (@var{i})
1.1.1.8 root 5944: A list (chain of @code{insn_list} expressions) of previous ``related''
1.1 root 5945: insns: insns which store into registers values that are used for the
5946: first time in this insn. (An additional constraint is that neither a
5947: jump nor a label may come between the related insns). This list is
5948: set up by the flow analysis pass; it is a null pointer until then.
5949:
1.1.1.6 root 5950: @item REG_NOTES (@var{i})
1.1.1.8 root 5951: A list (chain of @code{expr_list} expressions) giving information
1.1.1.6 root 5952: about the usage of registers in this insn. This list is set up by the
5953: flow analysis pass; it is a null pointer until then.
1.1 root 5954: @end table
5955:
1.1.1.8 root 5956: The @code{LOG_LINKS} field of an insn is a chain of @code{insn_list}
1.1 root 5957: expressions. Each of these has two operands: the first is an insn,
1.1.1.8 root 5958: and the second is another @code{insn_list} expression (the next one in
5959: the chain). The last @code{insn_list} in the chain has a null pointer
1.1 root 5960: as second operand. The significant thing about the chain is which
1.1.1.8 root 5961: insns appear in it (as first operands of @code{insn_list}
1.1 root 5962: expressions). Their order is not significant.
5963:
5964: The @code{REG_NOTES} field of an insn is a similar chain but of
1.1.1.8 root 5965: @code{expr_list} expressions instead of @code{insn_list}. There are
1.1.1.5 root 5966: several kinds of register notes, which are distinguished by the machine
1.1.1.8 root 5967: mode of the @code{expr_list}, which in a register note is really
1.1.1.5 root 5968: understood as being an @code{enum reg_note}. The first operand @var{op}
1.1.1.8 root 5969: of the @code{expr_list} is data whose meaning depends on the kind of
1.1.1.5 root 5970: note. Here are the kinds of register note:
1.1 root 5971:
5972: @table @code
5973: @item REG_DEAD
5974: The register @var{op} dies in this insn; that is to say, altering the
5975: value immediately after this insn would not affect the future behavior
5976: of the program.
5977:
5978: @item REG_INC
5979: The register @var{op} is incremented (or decremented; at this level
5980: there is no distinction) by an embedded side effect inside this insn.
1.1.1.8 root 5981: This means it appears in a @code{post_inc}, @code{pre_inc},
5982: @code{post_dec} or @code{pre_dec} RTX.
1.1 root 5983:
5984: @item REG_EQUIV
5985: The register that is set by this insn will be equal to @var{op} at run
5986: time, and could validly be replaced in all its occurrences by
5987: @var{op}. (``Validly'' here refers to the data flow of the program;
5988: simple replacement may make some insns invalid.)
5989:
5990: The value which the insn explicitly copies into the register may look
5991: different from @var{op}, but they will be equal at run time.
5992:
5993: For example, when a constant is loaded into a register that is never
5994: assigned any other value, this kind of note is used.
5995:
5996: When a parameter is copied into a pseudo-register at entry to a function,
5997: a note of this kind records that the register is equivalent to the stack
5998: slot where the parameter was passed. Although in this case the register
5999: may be set by other insns, it is still valid to replace the register
6000: by the stack slot throughout the function.
6001:
6002: @item REG_EQUAL
6003: The register that is set by this insn will be equal to @var{op} at run
6004: time at the end of this insn (but not necessarily elsewhere in the
6005: function).
6006:
6007: The RTX @var{op} is typically an arithmetic expression. For example,
6008: when a sequence of insns such as a library call is used to perform an
6009: arithmetic operation, this kind of note is attached to the insn that
6010: produces or copies the final value. It tells the CSE pass how to
6011: think of that value.
6012:
6013: @item REG_RETVAL
6014: This insn copies the value of a library call, and @var{op} is the
6015: first insn that was generated to set up the arguments for the library
6016: call.
6017:
6018: Flow analysis uses this note to delete all of a library call whose
6019: result is dead.
6020:
6021: @item REG_WAS_0
6022: The register @var{op} contained zero before this insn. You can rely
6023: on this note if it is present; its absence implies nothing.
6024:
6025: @item REG_LIBCALL
6026: This is the inverse of @code{REG_RETVAL}: it is placed on the first
6027: insn of a library call, and it points to the last one.
6028:
6029: Loop optimization uses this note to move an entire library call out
6030: of a loop when its value is constant.
6031:
6032: @item REG_NONNEG
6033: The register @var{op} is known to have nonnegative value when this
6034: insn is reached.
6035: @end table
6036:
1.1.1.8 root 6037: For convenience, the machine mode in an @code{insn_list} or
6038: @code{expr_list} is printed using these symbolic codes in debugging dumps.
1.1.1.7 root 6039:
1.1.1.8 root 6040: The only difference between the expression codes @code{insn_list} and
6041: @code{expr_list} is that the first operand of an @code{insn_list} is
1.1 root 6042: assumed to be an insn and is printed in debugging dumps as the insn's
1.1.1.8 root 6043: unique id; the first operand of an @code{expr_list} is printed in the
1.1.1.7 root 6044: ordinary way as an expression.
1.1 root 6045:
6046: @node Calls, Sharing, Insns, RTL
6047: @section RTL Representation of Function-Call Insns
6048:
1.1.1.8 root 6049: Insns that call subroutines have the RTL expression code @code{call_insn}.
1.1 root 6050: These insns must satisfy special rules, and their bodies must use a special
1.1.1.8 root 6051: RTL expression code, @code{call}.
1.1 root 6052:
1.1.1.8 root 6053: A @code{call} expression has two operands, as follows:
1.1 root 6054:
6055: @example
1.1.1.6 root 6056: (call (mem:@var{fm} @var{addr}) @var{nbytes})
1.1 root 6057: @end example
6058:
6059: @noindent
6060: Here @var{nbytes} is an operand that represents the number of bytes of
6061: argument data being passed to the subroutine, @var{fm} is a machine mode
6062: (which must equal as the definition of the @code{FUNCTION_MODE} macro in
6063: the machine description) and @var{addr} represents the address of the
6064: subroutine.
6065:
1.1.1.8 root 6066: For a subroutine that returns no value, the @code{call} RTX as shown above
1.1 root 6067: is the entire body of the insn.
6068:
6069: For a subroutine that returns a value whose mode is not @code{BLKmode},
6070: the value is returned in a hard register. If this register's number is
6071: @var{r}, then the body of the call insn looks like this:
6072:
6073: @example
6074: (set (reg:@var{m} @var{r})
1.1.1.9 root 6075: (call (mem:@var{fm} @var{addr}) @var{nbytes}))
1.1 root 6076: @end example
6077:
6078: @noindent
6079: This RTL expression makes it clear (to the optimizer passes) that the
6080: appropriate register receives a useful value in this insn.
6081:
6082: Immediately after RTL generation, if the value of the subroutine is
6083: actually used, this call insn is always followed closely by an insn which
6084: refers to the register @var{r}. This remains true through all the
6085: optimizer passes until cross jumping occurs.
6086:
6087: The following insn has one of two forms. Either it copies the value into a
6088: pseudo-register, like this:
6089:
6090: @example
6091: (set (reg:@var{m} @var{p}) (reg:@var{m} @var{r}))
6092: @end example
6093:
6094: @noindent
6095: or (in the case where the calling function will simply return whatever
6096: value the call produced, and no operation is needed to do this):
6097:
6098: @example
6099: (use (reg:@var{m} @var{r}))
6100: @end example
6101:
6102: @noindent
6103: Between the call insn and this following insn there may intervene only a
1.1.1.8 root 6104: stack-adjustment insn (and perhaps some @code{note} insns).
1.1 root 6105:
6106: When a subroutine returns a @code{BLKmode} value, it is handled by
6107: passing to the subroutine the address of a place to store the value.
6108: So the call insn itself does not ``return'' any value, and it has the
6109: same RTL form as a call that returns nothing.
6110:
6111: @node Sharing,, Calls, RTL
6112: @section Structure Sharing Assumptions
6113:
6114: The compiler assumes that certain kinds of RTL expressions are unique;
6115: there do not exist two distinct objects representing the same value.
6116: In other cases, it makes an opposite assumption: that no RTL expression
6117: object of a certain kind appears in more than one place in the
6118: containing structure.
6119:
6120: These assumptions refer to a single function; except for the RTL
6121: objects that describe global variables and external functions,
6122: no RTL objects are common to two functions.
6123:
6124: @itemize @bullet
6125: @item
1.1.1.8 root 6126: Each pseudo-register has only a single @code{reg} object to represent it,
1.1 root 6127: and therefore only a single machine mode.
6128:
6129: @item
1.1.1.8 root 6130: For any symbolic label, there is only one @code{symbol_ref} object
1.1 root 6131: referring to it.
6132:
6133: @item
1.1.1.8 root 6134: There is only one @code{const_int} expression with value zero,
1.1 root 6135: and only one with value one.
6136:
6137: @item
1.1.1.8 root 6138: There is only one @code{pc} expression.
1.1 root 6139:
6140: @item
1.1.1.8 root 6141: There is only one @code{cc0} expression.
1.1 root 6142:
6143: @item
1.1.1.8 root 6144: There is only one @code{const_double} expression with mode
1.1 root 6145: @code{SFmode} and value zero, and only one with mode @code{DFmode} and
6146: value zero.
6147:
6148: @item
1.1.1.8 root 6149: No @code{label_ref} appears in more than one place in the RTL
1.1 root 6150: structure; in other words, it is safe to do a tree-walk of all the
1.1.1.8 root 6151: insns in the function and assume that each time a @code{label_ref} is
1.1 root 6152: seen it is distinct from all others that are seen.
6153:
6154: @item
1.1.1.8 root 6155: Only one @code{mem} object is normally created for each static
1.1 root 6156: variable or stack slot, so these objects are frequently shared in all
6157: the places they appear. However, separate but equal objects for these
6158: variables are occasionally made.
6159:
6160: @item
1.1.1.5 root 6161: When a single @code{asm} statement has multiple output operands,
6162: a distinct @code{asm_operands} RTX is made for each output operand.
6163: However, these all share the vector which contains the sequence of
6164: input operands. Because this sharing is used later on to test whether
6165: two @code{asm_operands} RTX's come from the same statement, the sharing
6166: must be guaranteed to be preserved.
6167:
6168: @item
1.1 root 6169: No RTL object appears in more than one place in the RTL structure
6170: except as described above. Many passes of the compiler rely on this
6171: by assuming that they can modify RTL objects in place without unwanted
6172: side-effects on other insns.
6173:
6174: @item
6175: During initial RTL generation, shared structure is freely introduced.
6176: After all the RTL for a function has been generated, all shared
6177: structure is copied by @code{unshare_all_rtl} in @file{emit-rtl.c},
6178: after which the above rules are guaranteed to be followed.
6179:
6180: @item
6181: During the combiner pass, shared structure with an insn can exist
6182: temporarily. However, the shared structure is copied before the
6183: combiner is finished with the insn. This is done by
1.1.1.8 root 6184: @code{copy_substitutions} in @file{combine.c}.
1.1 root 6185: @end itemize
6186:
6187: @node Machine Desc, Machine Macros, RTL, Top
6188: @chapter Machine Descriptions
6189:
6190: A machine description has two parts: a file of instruction patterns
6191: (@file{.md} file) and a C header file of macro definitions.
6192:
6193: The @file{.md} file for a target machine contains a pattern for each
6194: instruction that the target machine supports (or at least each instruction
6195: that is worth telling the compiler about). It may also contain comments.
6196: A semicolon causes the rest of the line to be a comment, unless the semicolon
6197: is inside a quoted string.
6198:
6199: See the next chapter for information on the C header file.
6200:
6201: @menu
6202: * Patterns:: How to write instruction patterns.
1.1.1.8 root 6203: * Example:: An explained example of a @code{define_insn} pattern.
1.1 root 6204: * RTL Template:: The RTL template defines what insns match a pattern.
6205: * Output Template:: The output template says how to make assembler code
6206: from such an insn.
6207: * Output Statement:: For more generality, write C code to output
6208: the assembler code.
6209: * Constraints:: When not all operands are general operands.
6210: * Standard Names:: Names mark patterns to use for code generation.
6211: * Pattern Ordering:: When the order of patterns makes a difference.
6212: * Dependent Patterns:: Having one pattern may make you need another.
6213: * Jump Patterns:: Special considerations for patterns for jump insns.
6214: * Peephole Definitions::Defining machine-specific peephole optimizations.
6215: * Expander Definitions::Generating a sequence of several RTL insns
6216: for a standard operation.
6217: @end menu
6218:
6219: @node Patterns, Example, Machine Desc, Machine Desc
6220: @section Everything about Instruction Patterns
6221:
6222: Each instruction pattern contains an incomplete RTL expression, with pieces
6223: to be filled in later, operand constraints that restrict how the pieces can
6224: be filled in, and an output pattern or C code to generate the assembler
1.1.1.8 root 6225: output, all wrapped up in a @code{define_insn} expression.
1.1 root 6226:
1.1.1.8 root 6227: A @code{define_insn} is an RTL expression containing four or five operands:
1.1 root 6228:
6229: @enumerate
6230: @item
6231: An optional name. The presence of a name indicate that this instruction
6232: pattern can perform a certain standard job for the RTL-generation
6233: pass of the compiler. This pass knows certain names and will use
6234: the instruction patterns with those names, if the names are defined
6235: in the machine description.
6236:
6237: The absence of a name is indicated by writing an empty string
6238: where the name should go. Nameless instruction patterns are never
6239: used for generating RTL code, but they may permit several simpler insns
6240: to be combined later on.
6241:
6242: Names that are not thus known and used in RTL-generation have no
6243: effect; they are equivalent to no name at all.
6244:
6245: @item
6246: The @dfn{RTL template} (@pxref{RTL Template}) is a vector of
6247: incomplete RTL expressions which show what the instruction should look
1.1.1.8 root 6248: like. It is incomplete because it may contain @code{match_operand}
6249: and @code{match_dup} expressions that stand for operands of the
1.1 root 6250: instruction.
6251:
1.1.1.10 root 6252: If the vector has only one element, that element is the template for the
6253: instruction pattern. If the vector has multiple elements, then the
6254: instruction pattern is a @code{parallel} expression containing the
6255: elements described.
1.1 root 6256:
6257: @item
6258: A condition. This is a string which contains a C expression that is
6259: the final test to decide whether an insn body matches this pattern.
6260:
6261: For a named pattern, the condition (if present) may not depend on
6262: the data in the insn being matched, but only the target-machine-type
6263: flags. The compiler needs to test these conditions during
6264: initialization in order to learn exactly which named instructions are
6265: available in a particular run.
6266:
6267: For nameless patterns, the condition is applied only when matching an
6268: individual insn, and only after the insn has matched the pattern's
6269: recognition template. The insn's operands may be found in the vector
6270: @code{operands}.
6271:
6272: @item
6273: The @dfn{output template}: a string that says how to output matching
6274: insns as assembler code. @samp{%} in this string specifies where
6275: to substitute the value of an operand. @xref{Output Template}.
6276:
6277: When simple substitution isn't general enough, you can specify a piece
6278: of C code to compute the output. @xref{Output Statement}.
6279:
6280: @item
6281: Optionally, some @dfn{machine-specific information}. The meaning
6282: of this information is defined only by an individual machine description;
6283: typically it might say whether this insn alters the condition codes,
6284: or how many bytes of output it generates.
6285:
6286: This operand is written as a string containing a C initializer
6287: (complete with braces) for the structure type @code{INSN_MACHINE_INFO},
6288: whose definition is up to you (@pxref{Misc}).
6289: @end enumerate
6290:
6291: @node Example, RTL Template, Patterns, Machine Desc
1.1.1.8 root 6292: @section Example of @code{define_insn}
1.1 root 6293:
6294: Here is an actual example of an instruction pattern, for the 68000/68020.
6295:
6296: @example
6297: (define_insn "tstsi"
6298: [(set (cc0)
6299: (match_operand:SI 0 "general_operand" "rm"))]
6300: ""
6301: "*
6302: @{ if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
6303: return \"tstl %0\";
6304: return \"cmpl #0,%0\"; @}")
6305: @end example
6306:
6307: This is an instruction that sets the condition codes based on the value of
6308: a general operand. It has no condition, so any insn whose RTL description
6309: has the form shown may be handled according to this pattern. The name
6310: @samp{tstsi} means ``test a @code{SImode} value'' and tells the RTL generation
6311: pass that, when it is necessary to test such a value, an insn to do so
6312: can be constructed using this pattern.
6313:
6314: The output control string is a piece of C code which chooses which
6315: output template to return based on the kind of operand and the specific
6316: type of CPU for which code is being generated.
6317:
6318: @samp{"rm"} is an operand constraint. Its meaning is explained below.
6319:
6320: @node RTL Template, Output Template, Example, Machine Desc
6321: @section RTL Template for Generating and Recognizing Insns
6322:
6323: The RTL template is used to define which insns match the particular pattern
6324: and how to find their operands. For named patterns, the RTL template also
6325: says how to construct an insn from specified operands.
6326:
6327: Construction involves substituting specified operands into a copy of the
6328: template. Matching involves determining the values that serve as the
6329: operands in the insn being matched. Both of these activities are
6330: controlled by special expression types that direct matching and
6331: substitution of the operands.
6332:
6333: @table @code
1.1.1.8 root 6334: @item (match_operand:@var{m} @var{n} @var{pred} @var{constraint})
1.1 root 6335: This expression is a placeholder for operand number @var{n} of
6336: the insn. When constructing an insn, operand number @var{n}
6337: will be substituted at this point. When matching an insn, whatever
6338: appears at this position in the insn will be taken as operand
1.1.1.8 root 6339: number @var{n}; but it must satisfy @var{pred} or this instruction
1.1 root 6340: pattern will not match at all.
6341:
6342: Operand numbers must be chosen consecutively counting from zero in
1.1.1.8 root 6343: each instruction pattern. There may be only one @code{match_operand}
1.1 root 6344: expression in the pattern for each operand number. Usually operands
1.1.1.8 root 6345: are numbered in the order of appearance in @code{match_operand}
1.1 root 6346: expressions.
6347:
1.1.1.8 root 6348: @var{pred} is a string that is the name of a C function that accepts
6349: two arguments, an expression and a machine mode. During matching, the
6350: function will be called with the putative operand as the expression
6351: and @var{m} as the mode argument. If it returns zero, this
6352: instruction pattern fails to match. @var{pred} may be an empty
6353: string; then it means no test is to be done on the operand,
6354: so anything which occurs in this position is valid.
6355:
6356: @var{constraint} controls reloading and the choice of the best register
6357: class to use for a value, as explained later (@pxref{Constraints}).
6358:
6359: People are often unclear on the difference between the constraint and the
6360: predicate. The predicate helps decide whether a given insn matches the
6361: pattern. The constraint plays no role in this decision; instead, it
6362: controls various decisions in the case of an insn which does match.
6363:
6364: Most often, @var{pred} is @code{"general_operand"}. This function checks
6365: that the putative operand is either a constant, a register or a memory
6366: reference, and that it is valid for mode @var{m}.
1.1 root 6367:
1.1.1.8 root 6368: For an operand that must be a register, @var{pred} should be
1.1 root 6369: @code{"register_operand"}. It would be valid to use
6370: @code{"general_operand"}, since the reload pass would copy any
6371: non-register operands through registers, but this would make GNU CC do
6372: extra work, and it would prevent the register allocator from doing the
6373: best possible job.
6374:
1.1.1.8 root 6375: For an operand that must be a constant, either @var{pred} should be
1.1 root 6376: @code{"immediate_operand"}, or the instruction pattern's extra
6377: condition should check for constants, or both. You cannot expect the
6378: constraints to do this work! If the constraints allow only constants,
6379: but the predicate allows something else, the compiler will crash when
6380: that case arises.
6381:
6382: @item (match_dup @var{n})
6383: This expression is also a placeholder for operand number @var{n}.
6384: It is used when the operand needs to appear more than once in the
6385: insn.
6386:
1.1.1.8 root 6387: In construction, @code{match_dup} behaves exactly like
6388: @code{match_operand}: the operand is substituted into the insn being
6389: constructed. But in matching, @code{match_dup} behaves differently.
1.1 root 6390: It assumes that operand number @var{n} has already been determined by
1.1.1.8 root 6391: a @code{match_operand} appearing earlier in the recognition template,
1.1 root 6392: and it matches only an identical-looking expression.
6393:
1.1.1.4 root 6394: @item (match_operator:@var{m} @var{n} "@var{predicate}" [@var{operands}@dots{}])
6395: This pattern is a kind of placeholder for a variable RTL expression
6396: code.
6397:
6398: When constructing an insn, it stands for an RTL expression whose
6399: expression code is taken from that of operand @var{n}, and whose
6400: operands are constructed from the patterns @var{operands}.
6401:
6402: When matching an expression, it matches an expression if the function
6403: @var{predicate} returns nonzero on that expression @emph{and} the
6404: patterns @var{operands} match the operands of the expression.
6405:
6406: Suppose that the function @code{commutative_operator} is defined as
6407: follows, to match any expression whose operator is one of the six
6408: commutative arithmetic operators of RTL and whose mode is @var{mode}:
6409:
6410: @example
6411: int
6412: commutative_operator (x, mode)
6413: rtx x;
6414: enum machine_mode mode;
6415: @{
6416: enum rtx_code code = GET_CODE (x);
6417: if (GET_MODE (x) != mode)
6418: return 0;
6419: return (code == PLUS || code == MULT || code == UMULT
6420: || code == AND || code == IOR || code == XOR);
6421: @}
6422: @end example
6423:
6424: Then the following pattern will match any RTL expression consisting
6425: of a commutative operator applied to two general operands:
6426:
6427: @example
6428: (match_operator:SI 2 "commutative_operator"
6429: [(match_operand:SI 3 "general_operand" "g")
6430: (match_operand:SI 4 "general_operand" "g")])
6431: @end example
6432:
6433: Here the vector @code{[@var{operands}@dots{}]} contains two patterns
6434: because the expressions to be matched all contain two operands.
6435:
6436: When this pattern does match, the two operands of the commutative
6437: operator are recorded as operands 3 and 4 of the insn. (This is done
1.1.1.8 root 6438: by the two instances of @code{match_operand}.) Operand 2 of the insn
1.1.1.4 root 6439: will be the entire commutative expression: use @code{GET_CODE
6440: (operands[2])} to see which commutative operator was used.
6441:
1.1.1.8 root 6442: The machine mode @var{m} of @code{match_operator} works like that of
6443: @code{match_operand}: it is passed as the second argument to the
1.1.1.4 root 6444: predicate function, and that function is solely responsible for
6445: deciding whether the expression to be matched ``has'' that mode.
6446:
6447: When constructing an insn, argument 2 of the gen-function will specify
6448: the operation (i.e. the expression code) for the expression to be
6449: made. It should be an RTL expression, whose expression code is copied
6450: into a new expression whose operands are arguments 3 and 4 of the
6451: gen-function. The subexpressions of argument 2 are not used;
6452: only its expression code matters.
6453:
1.1.1.8 root 6454: There is no way to specify constraints in @code{match_operator}. The
6455: operand of the insn which corresponds to the @code{match_operator}
1.1.1.4 root 6456: never has any constraints because it is never reloaded as a whole.
6457: However, if parts of its @var{operands} are matched by
1.1.1.8 root 6458: @code{match_operand} patterns, those parts may have constraints of
1.1.1.4 root 6459: their own.
6460:
1.1 root 6461: @item (address (match_operand:@var{m} @var{n} "address_operand" ""))
6462: This complex of expressions is a placeholder for an operand number
6463: @var{n} in a ``load address'' instruction: an operand which specifies
6464: a memory location in the usual way, but for which the actual operand
6465: value used is the address of the location, not the contents of the
6466: location.
6467:
1.1.1.8 root 6468: @code{address} expressions never appear in RTL code, only in machine
1.1 root 6469: descriptions. And they are used only in machine descriptions that do
6470: not use the operand constraint feature. When operand constraints are
6471: in use, the letter @samp{p} in the constraint serves this purpose.
6472:
6473: @var{m} is the machine mode of the @emph{memory location being
6474: addressed}, not the machine mode of the address itself. That mode is
6475: always the same on a given target machine (it is @code{Pmode}, which
6476: normally is @code{SImode}), so there is no point in mentioning it;
1.1.1.8 root 6477: thus, no machine mode is written in the @code{address} expression. If
1.1 root 6478: some day support is added for machines in which addresses of different
6479: kinds of objects appear differently or are used differently (such as
6480: the PDP-10), different formats would perhaps need different machine
1.1.1.8 root 6481: modes and these modes might be written in the @code{address}
1.1 root 6482: expression.
6483: @end table
6484:
6485: @node Output Template, Output Statement, RTL Template, Machine Desc
6486: @section Output Templates and Operand Substitution
6487:
1.1.1.6 root 6488: The @dfn{output template} is a string which specifies how to output the
6489: assembler code for an instruction pattern. Most of the template is a
6490: fixed string which is output literally. The character @samp{%} is used
6491: to specify where to substitute an operand; it can also be used to
6492: identify places where different variants of the assembler require
1.1 root 6493: different syntax.
6494:
6495: In the simplest case, a @samp{%} followed by a digit @var{n} says to output
6496: operand @var{n} at that point in the string.
6497:
6498: @samp{%} followed by a letter and a digit says to output an operand in an
6499: alternate fashion. Four letters have standard, built-in meanings described
6500: below. The machine description macro @code{PRINT_OPERAND} can define
6501: additional letters with nonstandard meanings.
6502:
6503: @samp{%c@var{digit}} can be used to substitute an operand that is a
6504: constant value without the syntax that normally indicates an immediate
6505: operand.
6506:
6507: @samp{%n@var{digit}} is like @samp{%c@var{digit}} except that the value of
6508: the constant is negated before printing.
6509:
6510: @samp{%a@var{digit}} can be used to substitute an operand as if it were a
6511: memory reference, with the actual operand treated as the address. This may
6512: be useful when outputting a ``load address'' instruction, because often the
6513: assembler syntax for such an instruction requires you to write the operand
6514: as if it were a memory reference.
6515:
6516: @samp{%l@var{digit}} is used to substitute a @code{label_ref} into a jump
6517: instruction.
6518:
6519: @samp{%} followed by a punctuation character specifies a substitution that
6520: does not use an operand. Only one case is standard: @samp{%%} outputs a
6521: @samp{%} into the assembler code. Other nonstandard cases can be
1.1.1.8 root 6522: defined in the @code{PRINT_OPERAND} macro. You must also define
6523: which punctuation characters are valid with the
6524: @code{PRINT_OPERAND_PUNCT_VALID_P} macro.
1.1 root 6525:
6526: The template may generate multiple assembler instructions. Write the text
6527: for the instructions, with @samp{\;} between them.
6528:
1.1.1.6 root 6529: When the RTL contains two operands which are required by constraint to match
1.1 root 6530: each other, the output template must refer only to the lower-numbered operand.
6531: Matching operands are not always identical, and the rest of the compiler
6532: arranges to put the proper RTL expression for printing into the lower-numbered
6533: operand.
6534:
6535: One use of nonstandard letters or punctuation following @samp{%} is to
6536: distinguish between different assembler languages for the same machine; for
6537: example, Motorola syntax versus MIT syntax for the 68000. Motorola syntax
6538: requires periods in most opcode names, while MIT syntax does not. For
6539: example, the opcode @samp{movel} in MIT syntax is @samp{move.l} in Motorola
6540: syntax. The same file of patterns is used for both kinds of output syntax,
6541: but the character sequence @samp{%.} is used in each place where Motorola
6542: syntax wants a period. The @code{PRINT_OPERAND} macro for Motorola syntax
6543: defines the sequence to output a period; the macro for MIT syntax defines
6544: it to do nothing.
6545:
6546: @node Output Statement, Constraints, Output Template, Machine Desc
6547: @section C Statements for Generating Assembler Output
6548:
6549: Often a single fixed template string cannot produce correct and efficient
6550: assembler code for all the cases that are recognized by a single
6551: instruction pattern. For example, the opcodes may depend on the kinds of
6552: operands; or some unfortunate combinations of operands may require extra
6553: machine instructions.
6554:
6555: If the output control string starts with a @samp{*}, then it is not an
6556: output template but rather a piece of C program that should compute a
6557: template. It should execute a @code{return} statement to return the
6558: template-string you want. Most such templates use C string literals, which
6559: require doublequote characters to delimit them. To include these
6560: doublequote characters in the string, prefix each one with @samp{\}.
6561:
6562: The operands may be found in the array @code{operands}, whose C data type
6563: is @code{rtx []}.
6564:
6565: It is possible to output an assembler instruction and then go on to output
6566: or compute more of them, using the subroutine @code{output_asm_insn}. This
6567: receives two arguments: a template-string and a vector of operands. The
6568: vector may be @code{operands}, or it may be another array of @code{rtx}
6569: that you declare locally and initialize yourself.
6570:
6571: When an insn pattern has multiple alternatives in its constraints, often
1.1.1.5 root 6572: the appearance of the assembler code is determined mostly by which alternative
1.1 root 6573: was matched. When this is so, the C code can test the variable
6574: @code{which_alternative}, which is the ordinal number of the alternative
6575: that was actually satisfied (0 for the first, 1 for the second alternative,
6576: etc.).
6577:
6578: For example, suppose there are two opcodes for storing zero, @samp{clrreg}
6579: for registers and @samp{clrmem} for memory locations. Here is how
6580: a pattern could use @code{which_alternative} to choose between them:
6581:
6582: @example
6583: (define_insn ""
1.1.1.13! root 6584: [(set (match_operand:SI 0 "general_operand" "=r,m")
1.1 root 6585: (const_int 0))]
6586: ""
6587: "*
6588: return (which_alternative == 0
6589: ? \"clrreg %0\" : \"clrmem %0\");
6590: ")
6591: @end example
6592:
6593: @node Constraints, Standard Names, Output Statement, Machine Desc
6594: @section Operand Constraints
6595:
1.1.1.8 root 6596: Each @code{match_operand} in an instruction pattern can specify a
1.1 root 6597: constraint for the type of operands allowed. Constraints can say whether
6598: an operand may be in a register, and which kinds of register; whether the
6599: operand can be a memory reference, and which kinds of address; whether the
6600: operand may be an immediate constant, and which possible values it may
6601: have. Constraints can also require two operands to match.
6602:
6603: @menu
6604: * Simple Constraints:: Basic use of constraints.
6605: * Multi-Alternative:: When an insn has two alternative constraint-patterns.
6606: * Class Preferences:: Constraints guide which hard register to put things in.
6607: * Modifiers:: More precise control over effects of constraints.
6608: * No Constraints:: Describing a clean machine without constraints.
6609: @end menu
6610:
6611: @node Simple Constraints, Multi-Alternative, Constraints, Constraints
6612: @subsection Simple Constraints
6613:
6614: The simplest kind of constraint is a string full of letters, each of
6615: which describes one kind of operand that is permitted. Here are
6616: the letters that are allowed:
6617:
6618: @table @asis
6619: @item @samp{m}
6620: A memory operand is allowed, with any kind of address that the machine
6621: supports in general.
6622:
6623: @item @samp{o}
6624: A memory operand is allowed, but only if the address is
1.1.1.8 root 6625: @dfn{offsettable}. This means that adding a small integer (actually,
1.1 root 6626: the width in bytes of the operand, as determined by its machine mode)
6627: may be added to the address and the result is also a valid memory
6628: address.
6629:
1.1.1.8 root 6630: For example, an address which is constant is offsettable; so is an
1.1 root 6631: address that is the sum of a register and a constant (as long as a
6632: slightly larger constant is also within the range of address-offsets
6633: supported by the machine); but an autoincrement or autodecrement
1.1.1.8 root 6634: address is not offsettable. More complicated indirect/indexed
6635: addresses may or may not be offsettable depending on the other
1.1 root 6636: addressing modes that the machine supports.
6637:
6638: Note that in an output operand which can be matched by another
6639: operand, the constraint letter @samp{o} is valid only when accompanied
6640: by both @samp{<} (if the target machine has predecrement addressing)
6641: and @samp{>} (if the target machine has preincrement addressing).
6642:
6643: When the constraint letter @samp{o} is used, the reload pass may
1.1.1.8 root 6644: generate instructions which copy a nonoffsettable address into an index
1.1 root 6645: register. The idea is that the register can be used as a replacement
1.1.1.8 root 6646: offsettable address. But this method requires that there be patterns
1.1 root 6647: to copy any kind of address into a register. Auto-increment
6648: and auto-decrement addresses are an exception; there need not be an
6649: instruction that can copy such an address into a register, because
6650: reload handles these cases specially.
6651:
6652: Most older machine designs have ``load address'' instructions which do
6653: just what is needed here. Some RISC machines do not advertise such
6654: instructions, but the possible addresses on these machines are very
6655: limited, so it is easy to fake them.
6656:
6657: @item @samp{<}
6658: A memory operand with autodecrement addressing (either predecrement or
6659: postdecrement) is allowed.
6660:
6661: @item @samp{>}
6662: A memory operand with autoincrement addressing (either preincrement or
6663: postincrement) is allowed.
6664:
6665: @item @samp{r}
6666: A register operand is allowed provided that it is in a general
6667: register.
6668:
6669: @item @samp{d}, @samp{a}, @samp{f}, @dots{}
6670: Other letters can be defined in machine-dependent fashion to stand for
6671: particular classes of registers. @samp{d}, @samp{a} and @samp{f} are
6672: defined on the 68000/68020 to stand for data, address and floating
6673: point registers.
6674:
6675: @item @samp{i}
6676: An immediate integer operand (one with constant value) is allowed.
6677: This includes symbolic constants whose values will be known only at
6678: assembly time.
6679:
6680: @item @samp{n}
6681: An immediate integer operand with a known numeric value is allowed.
6682: Many systems cannot support assembly-time constants for operands less
6683: than a word wide. Constraints for these operands should use @samp{n}
6684: rather than @samp{i}.
6685:
6686: @item @samp{I}, @samp{J}, @samp{K}, @dots{}
6687: Other letters in the range @samp{I} through @samp{M} may be defined in
6688: a machine-dependent fashion to permit immediate integer operands with
6689: explicit integer values in specified ranges. For example, on the
6690: 68000, @samp{I} is defined to stand for the range of values 1 to 8.
6691: This is the range permitted as a shift count in the shift
6692: instructions.
6693:
6694: @item @samp{F}
1.1.1.8 root 6695: An immediate floating operand (expression code @code{const_double}) is
1.1 root 6696: allowed.
6697:
6698: @item @samp{G}, @samp{H}
6699: @samp{G} and @samp{H} may be defined in a machine-dependent fashion to
6700: permit immediate floating operands in particular ranges of values.
6701:
6702: @item @samp{s}
6703: An immediate integer operand whose value is not an explicit integer is
6704: allowed.
6705:
6706: This might appear strange; if an insn allows a constant operand with a
6707: value not known at compile time, it certainly must allow any known
6708: value. So why use @samp{s} instead of @samp{i}? Sometimes it allows
6709: better code to be generated.
6710:
6711: For example, on the 68000 in a fullword instruction it is possible to
1.1.1.9 root 6712: use an immediate operand; but if the immediate value is between -128
6713: and 127, better code results from loading the value into a register and
1.1 root 6714: using the register. This is because the load into the register can be
6715: done with a @samp{moveq} instruction. We arrange for this to happen
6716: by defining the letter @samp{K} to mean ``any integer outside the
1.1.1.9 root 6717: range -128 to 127'', and then specifying @samp{Ks} in the operand
1.1 root 6718: constraints.
6719:
6720: @item @samp{g}
6721: Any register, memory or immediate integer operand is allowed, except for
6722: registers that are not general registers.
6723:
6724: @item @samp{@var{n}} (a digit)
6725: An operand that matches operand number @var{n} is allowed.
6726: If a digit is used together with letters, the digit should come last.
6727:
6728: This is called a @dfn{matching constraint} and what it really means is
6729: that the assembler has only a single operand that fills two roles
6730: considered separate in the RTL insn. For example, an add insn has two
6731: input operands and one output operand in the RTL, but on most machines
6732: an add instruction really has only two operands, one of them an
6733: input-output operand.
6734:
6735: Matching constraints work only in circumstances like that add insn.
6736: More precisely, the matching constraint must appear in an input-only
6737: operand and the operand that it matches must be an output-only operand
1.1.1.5 root 6738: with a lower number. Thus, operand @var{n} must have @samp{=} in its
6739: constraint.
1.1 root 6740:
6741: For operands to match in a particular case usually means that they
6742: are identical-looking RTL expressions. But in a few special cases
6743: specific kinds of dissimilarity are allowed. For example, @code{*x}
6744: as an input operand will match @code{*x++} as an output operand.
6745: For proper results in such cases, the output template should always
6746: use the output-operand's number when printing the operand.
6747:
6748: @item @samp{p}
6749: An operand that is a valid memory address is allowed. This is
6750: for ``load address'' and ``push address'' instructions.
6751:
1.1.1.8 root 6752: @samp{p} in the constraint must be accompanies by @code{address_operand}
6753: as the predicate in the @code{match_operand}.
1.1 root 6754: @end table
6755:
6756: In order to have valid assembler code, each operand must satisfy
6757: its constraint. But a failure to do so does not prevent the pattern
6758: from applying to an insn. Instead, it directs the compiler to modify
6759: the code so that the constraint will be satisfied. Usually this is
6760: done by copying an operand into a register.
6761:
6762: Contrast, therefore, the two instruction patterns that follow:
6763:
6764: @example
6765: (define_insn ""
1.1.1.13! root 6766: [(set (match_operand:SI 0 "general_operand" "=r")
1.1 root 6767: (plus:SI (match_dup 0)
6768: (match_operand:SI 1 "general_operand" "r")))]
6769: ""
6770: "@dots{}")
6771: @end example
6772:
6773: @noindent
6774: which has two operands, one of which must appear in two places, and
6775:
6776: @example
6777: (define_insn ""
1.1.1.13! root 6778: [(set (match_operand:SI 0 "general_operand" "=r")
1.1 root 6779: (plus:SI (match_operand:SI 1 "general_operand" "0")
6780: (match_operand:SI 2 "general_operand" "r")))]
6781: ""
6782: "@dots{}")
6783: @end example
6784:
6785: @noindent
6786: which has three operands, two of which are required by a constraint to be
6787: identical. If we are considering an insn of the form
6788:
6789: @example
6790: (insn @var{n} @var{prev} @var{next}
6791: (set (reg:SI 3)
6792: (plus:SI (reg:SI 6) (reg:SI 109)))
6793: @dots{})
6794: @end example
6795:
6796: @noindent
6797: the first pattern would not apply at all, because this insn does not
6798: contain two identical subexpressions in the right place. The pattern would
6799: say, ``That does not look like an add instruction; try other patterns.''
6800: The second pattern would say, ``Yes, that's an add instruction, but there
6801: is something wrong with it.'' It would direct the reload pass of the
6802: compiler to generate additional insns to make the constraint true. The
6803: results might look like this:
6804:
6805: @example
6806: (insn @var{n2} @var{prev} @var{n}
6807: (set (reg:SI 3) (reg:SI 6))
6808: @dots{})
6809:
6810: (insn @var{n} @var{n2} @var{next}
6811: (set (reg:SI 3)
6812: (plus:SI (reg:SI 3) (reg:SI 109)))
6813: @dots{})
6814: @end example
6815:
6816: It is up to you to make sure that each operand, in each pattern, has
6817: constraints that can handle any RTL expression that could be present for
6818: that operand. (When multiple alternatives are in use, each pattern must,
6819: for each possible combination of operand expressions, have at least one
6820: alternative which can handle that combination of operands.) The
6821: constraints don't need to @emph{allow} any possible operand---when this is
6822: the case, they do not constrain---but they must at least point the way to
6823: reloading any possible operand so that it will fit.
6824:
6825: @itemize @bullet
6826: @item
6827: If the constraint accepts whatever operands the predicate permits,
6828: there is no problem: reloading is never necessary for this operand.
6829:
6830: For example, an operand whose constraints permit everything except
6831: registers is safe provided its predicate rejects registers.
6832:
6833: An operand whose predicate accepts only constant values is safe
6834: provided its constraints include the letter @samp{i}. If any possible
6835: constant value is accepted, then nothing less than @samp{i} will do;
1.1.1.5 root 6836: if the predicate is more selective, then the constraints may also be
1.1 root 6837: more selective.
6838:
6839: @item
6840: Any operand expression can be reloaded by copying it into a register.
6841: So if an operand's constraints allow some kind of register, it is
6842: certain to be safe. It need not permit all classes of registers; the
6843: compiler knows how to copy a register into another register of the
6844: proper class in order to make an instruction valid.
6845:
6846: @item
1.1.1.8 root 6847: A nonoffsettable memory reference can be reloaded by copying the
1.1 root 6848: address into a register. So if the constraint uses the letter
6849: @samp{o}, all memory references are taken care of.
6850:
6851: @item
1.1.1.8 root 6852: A constant operand can be reloaded by allocating space in memory to
6853: hold it as preinitialized data. Then the memory reference can be used
6854: in place of the constant. So if the constraint uses the letters
6855: @samp{o} or @samp{m}, constant operands are not a problem.
1.1 root 6856: @end itemize
6857:
6858: If the operand's predicate can recognize registers, but the constraint does
6859: not permit them, it can make the compiler crash. When this operand happens
6860: to be a register, the reload pass will be stymied, because it does not know
6861: how to copy a register temporarily into memory.
6862:
6863: @node Multi-Alternative, Class Preferences, Simple Constraints, Constraints
6864: @subsection Multiple Alternative Constraints
6865:
6866: Sometimes a single instruction has multiple alternative sets of possible
6867: operands. For example, on the 68000, a logical-or instruction can combine
6868: register or an immediate value into memory, or it can combine any kind of
6869: operand into a register; but it cannot combine one memory location into
6870: another.
6871:
6872: These constraints are represented as multiple alternatives. An alternative
6873: can be described by a series of letters for each operand. The overall
6874: constraint for an operand is made from the letters for this operand
6875: from the first alternative, a comma, the letters for this operand from
6876: the second alternative, a comma, and so on until the last alternative.
6877: Here is how it is done for fullword logical-or on the 68000:
6878:
6879: @example
6880: (define_insn "iorsi3"
1.1.1.9 root 6881: [(set (match_operand:SI 0 "general_operand" "=m,d")
6882: (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
1.1 root 6883: (match_operand:SI 2 "general_operand" "dKs,dmKs")))]
6884: @dots{})
6885: @end example
6886:
6887: The first alternative has @samp{m} (memory) for operand 0, @samp{0} for
1.1.1.9 root 6888: operand 1 (meaning it must match operand 0), and @samp{dKs} for operand
6889: 2. The second alternative has @samp{d} (data register) for operand 0,
6890: @samp{0} for operand 1, and @samp{dmKs} for operand 2. The @samp{=} and
6891: @samp{%} in the constraints apply to all the alternatives; their meaning
1.1 root 6892: is explained in the next section.
6893:
6894: If all the operands fit any one alternative, the instruction is valid.
6895: Otherwise, for each alternative, the compiler counts how many instructions
6896: must be added to copy the operands so that that alternative applies.
6897: The alternative requiring the least copying is chosen. If two alternatives
6898: need the same amount of copying, the one that comes first is chosen.
6899: These choices can be altered with the @samp{?} and @samp{!} characters:
6900:
6901: @table @samp
6902: @item ?
6903: Disparage slightly the alternative that the @samp{?} appears in,
6904: as a choice when no alternative applies exactly. The compiler regards
6905: this alternative as one unit more costly for each @samp{?} that appears
6906: in it.
6907:
6908: @item !
6909: Disparage severely the alternative that the @samp{!} appears in.
6910: When operands must be copied into registers, the compiler will
6911: never choose this alternative as the one to strive for.
6912: @end table
6913:
1.1.1.5 root 6914: When an insn pattern has multiple alternatives in its constraints, often
6915: the appearance of the assembler code is determined mostly by which
1.1 root 6916: alternative was matched. When this is so, the C code for writing the
6917: assembler code can use the variable @code{which_alternative}, which is
1.1.1.5 root 6918: the ordinal number of the alternative that was actually satisfied (0 for
6919: the first, 1 for the second alternative, etc.). For example:
1.1 root 6920:
6921: @example
6922: (define_insn ""
1.1.1.13! root 6923: [(set (match_operand:SI 0 "general_operand" "=r,m")
1.1 root 6924: (const_int 0))]
6925: ""
6926: "*
6927: return (which_alternative == 0
6928: ? \"clrreg %0\" : \"clrmem %0\");
6929: ")
6930: @end example
6931:
6932: @node Class Preferences, Modifiers, Multi-Alternative, Constraints
6933: @subsection Register Class Preferences
6934:
6935: The operand constraints have another function: they enable the compiler
6936: to decide which kind of hardware register a pseudo register is best
6937: allocated to. The compiler examines the constraints that apply to the
6938: insns that use the pseudo register, looking for the machine-dependent
6939: letters such as @samp{d} and @samp{a} that specify classes of registers.
6940: The pseudo register is put in whichever class gets the most ``votes''.
6941: The constraint letters @samp{g} and @samp{r} also vote: they vote in
6942: favor of a general register. The machine description says which registers
6943: are considered general.
6944:
6945: Of course, on some machines all registers are equivalent, and no register
6946: classes are defined. Then none of this complexity is relevant.
6947:
6948: @node Modifiers, No Constraints, Class Preferences, Constraints
6949: @subsection Constraint Modifier Characters
6950:
6951: @table @samp
6952: @item =
6953: Means that this operand is write-only for this instruction: the previous
6954: value is discarded and replaced by output data.
6955:
6956: @item +
6957: Means that this operand is both read and written by the instruction.
6958:
6959: When the compiler fixes up the operands to satisfy the constraints,
6960: it needs to know which operands are inputs to the instruction and
6961: which are outputs from it. @samp{=} identifies an output; @samp{+}
6962: identifies an operand that is both input and output; all other operands
6963: are assumed to be input only.
6964:
6965: @item &
6966: Means (in a particular alternative) that this operand is written
6967: before the instruction is finished using the input operands.
6968: Therefore, this operand may not lie in a register that is used as an
6969: input operand or as part of any memory address.
6970:
6971: @samp{&} applies only to the alternative in which it is written. In
6972: constraints with multiple alternatives, sometimes one alternative
6973: requires @samp{&} while others do not. See, for example, the
6974: @samp{movdf} insn of the 68000.
6975:
6976: @samp{&} does not obviate the need to write @samp{=}.
6977:
6978: @item %
6979: Declares the instruction to be commutative for this operand and the
6980: following operand. This means that the compiler may interchange the
6981: two operands if that is the cheapest way to make all operands fit the
6982: constraints. This is often used in patterns for addition instructions
6983: that really have only two operands: the result must go in one of the
6984: arguments. Here for example, is how the 68000 halfword-add
6985: instruction is defined:
6986:
6987: @example
6988: (define_insn "addhi3"
6989: [(set (match_operand:HI 0 "general_operand" "=m,r")
6990: (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
6991: (match_operand:HI 2 "general_operand" "di,g")))]
6992: @dots{})
6993: @end example
6994:
6995: Note that in previous versions of GNU CC the @samp{%} constraint
6996: modifier always applied to operands 1 and 2 regardless of which
6997: operand it was written in. The usual custom was to write it in
6998: operand 0. Now it must be in operand 1 if the operands to be
6999: exchanged are 1 and 2.
7000:
7001: @item #
7002: Says that all following characters, up to the next comma, are to be
7003: ignored as a constraint. They are significant only for choosing
7004: register preferences.
7005:
7006: @item *
7007: Says that the following character should be ignored when choosing
7008: register preferences. @samp{*} has no effect on the meaning of the
7009: constraint as a constraint.
7010:
7011: Here is an example: the 68000 has an instruction to sign-extend a
7012: halfword in a data register, and can also sign-extend a value by
7013: copying it into an address register. While either kind of register is
7014: acceptable, the constraints on an address-register destination are
7015: less strict, so it is best if register allocation makes an address
7016: register its goal. Therefore, @samp{*} is used so that the @samp{d}
7017: constraint letter (for data register) is ignored when computing
7018: register preferences.
7019:
7020: @example
7021: (define_insn "extendhisi2"
7022: [(set (match_operand:SI 0 "general_operand" "=*d,a")
7023: (sign_extend:SI
7024: (match_operand:HI 1 "general_operand" "0,g")))]
7025: @dots{})
7026: @end example
7027: @end table
7028:
7029: @node No Constraints,, Modifiers, Constraints
7030: @subsection Not Using Constraints
7031:
7032: Some machines are so clean that operand constraints are not required. For
7033: example, on the Vax, an operand valid in one context is valid in any other
7034: context. On such a machine, every operand constraint would be @samp{g},
7035: excepting only operands of ``load address'' instructions which are
7036: written as if they referred to a memory location's contents but actual
7037: refer to its address. They would have constraint @samp{p}.
7038:
7039: For such machines, instead of writing @samp{g} and @samp{p} for all
7040: the constraints, you can choose to write a description with empty constraints.
1.1.1.8 root 7041: Then you write @samp{""} for the constraint in every @code{match_operand}.
7042: Address operands are identified by writing an @code{address} expression
7043: around the @code{match_operand}, not by their constraints.
1.1 root 7044:
7045: When the machine description has just empty constraints, certain parts
1.1.1.6 root 7046: of compilation are skipped, making the compiler faster. However,
7047: few machines actually do not need constraints; all machine descriptions
7048: now in existence use constraints.
1.1 root 7049:
7050: @node Standard Names, Pattern Ordering, Constraints, Machine Desc
7051: @section Standard Names for Patterns Used in Generation
7052:
7053: Here is a table of the instruction names that are meaningful in the RTL
7054: generation pass of the compiler. Giving one of these names to an
7055: instruction pattern tells the RTL generation pass that it can use the
7056: pattern in to accomplish a certain task.
7057:
7058: @table @asis
7059: @item @samp{mov@var{m}}
1.1.1.8 root 7060: Here @var{m} stands for a two-letter machine mode name, in lower case.
7061: This instruction pattern moves data with that machine mode from operand
7062: 1 to operand 0. For example, @samp{movsi} moves full-word data.
1.1 root 7063:
1.1.1.8 root 7064: If operand 0 is a @code{subreg} with mode @var{m} of a register whose
7065: own mode is wider than @var{m}, the effect of this instruction is
1.1 root 7066: to store the specified value in the part of the register that corresponds
7067: to mode @var{m}. The effect on the rest of the register is undefined.
7068:
7069: This class of patterns is special in several ways. First of all, each
7070: of these names @emph{must} be defined, because there is no other way
7071: to copy a datum from one place to another.
7072:
7073: Second, these patterns are not used solely in the RTL generation pass.
7074: Even the reload pass can generate move insns to copy values from stack
1.1.1.8 root 7075: slots into temporary registers. When it does so, one of the operands is
7076: a hard register and the other is an operand that can need to be reloaded
7077: into a register.
7078:
7079: Therefore, when given such a pair of operands, the pattern must generate
7080: RTL which needs no reloading and needs no temporary registers---no
7081: registers other than the operands. For example, if you support the
7082: pattern with a @code{define_expand}, then in such a case the
7083: @code{define_expand} mustn't call @code{force_reg} or any other such
7084: function which might generate new pseudo registers.
1.1 root 7085:
7086: This requirement exists even for subword modes on a RISC machine where
7087: fetching those modes from memory normally requires several insns and
7088: some temporary registers. Look in @file{spur.md} to see how the
1.1.1.8 root 7089: requirement can be satisfied.
1.1 root 7090:
7091: The variety of operands that have reloads depends on the rest of the
7092: machine description, but typically on a RISC machine these can only be
7093: pseudo registers that did not get hard registers, while on other
7094: machines explicit memory references will get optional reloads.
7095:
1.1.1.9 root 7096: The constraints on a @samp{move@var{m}} must allow any hard register to
7097: be moved to any other hard register (provided that
7098: @code{HARD_REGNO_MODE_OK} permits mode @var{m} in both registers).
7099:
7100: It is obligatory to support floating point @samp{move@var{m}}
7101: instructions into and out of any registers that can hold fixed point
7102: values, because unions and structures (which have modes @code{SImode} or
7103: @code{DImode}) can be in those registers and they may have floating
7104: point members.
7105:
7106: There may also be a need to support fixed point @samp{move@var{m}}
7107: instructions in and out of floating point registers. Unfortunately, I
7108: have forgotten why this was so, and I don't know whether it is still
7109: true. If @code{HARD_REGNO_MODE_OK} rejects fixed point values in
7110: floating point registers, then the constraints of the fixed point
7111: @samp{move@var{m}} instructions must be designed to avoid ever trying to
7112: reload into a floating point register.
1.1 root 7113:
7114: @item @samp{movstrict@var{m}}
1.1.1.8 root 7115: Like @samp{mov@var{m}} except that if operand 0 is a @code{subreg}
1.1 root 7116: with mode @var{m} of a register whose natural mode is wider,
7117: the @samp{movstrict@var{m}} instruction is guaranteed not to alter
7118: any of the register except the part which belongs to mode @var{m}.
7119:
1.1.1.13! root 7120: @item @samp{movsi_unaligned}
! 7121: Like @samp{movsi} except that the memory reference will not trap
! 7122: if loading or storing into unaligned memory. You must define this
! 7123: pattern if you can pass structures or unions in registers when they
! 7124: have less than a full word of alignment.
! 7125:
1.1 root 7126: @item @samp{add@var{m}3}
7127: Add operand 2 and operand 1, storing the result in operand 0. All operands
7128: must have mode @var{m}. This can be used even on two-address machines, by
7129: means of constraints requiring operands 1 and 0 to be the same location.
7130:
7131: @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}
7132: Similar, for other arithmetic operations.
7133:
7134: There are special considerations for register classes for logical-and
7135: instructions, affecting also the macro @code{PREFERRED_RELOAD_CLASS}.
7136: They apply not only to the patterns with these standard names, but to
7137: any patterns that will match such an instruction. @xref{Register
7138: Classes}.
7139:
7140: @item @samp{mulhisi3}
7141: Multiply operands 1 and 2, which have mode @code{HImode}, and store
7142: a @code{SImode} product in operand 0.
7143:
7144: @item @samp{mulqihi3}, @samp{mulsidi3}
7145: Similar widening-multiplication instructions of other widths.
7146:
7147: @item @samp{umulqihi3}, @samp{umulhisi3}, @samp{umulsidi3}
7148: Similar widening-multiplication instructions that do unsigned
7149: multiplication.
7150:
7151: @item @samp{divmod@var{m}4}
7152: Signed division that produces both a quotient and a remainder.
7153: Operand 1 is divided by operand 2 to produce a quotient stored
7154: in operand 0 and a remainder stored in operand 3.
7155:
7156: @item @samp{udivmod@var{m}4}
7157: Similar, but does unsigned division.
7158:
7159: @item @samp{ashl@var{m}3}
7160: Arithmetic-shift operand 1 left by a number of bits specified by
7161: operand 2, and store the result in operand 0. Operand 2 has
7162: mode @code{SImode}, not mode @var{m}.
7163:
7164: @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}
7165: Other shift and rotate instructions.
7166:
7167: Logical and arithmetic left shift are the same. Machines that do not
7168: allow negative shift counts often have only one instruction for
7169: shifting left. On such machines, you should define a pattern named
7170: @samp{ashl@var{m}3} and leave @samp{lshl@var{m}3} undefined.
7171:
7172: There are special considerations for register classes for shift
7173: instructions, affecting also the macro @code{PREFERRED_RELOAD_CLASS}.
7174: They apply not only to the patterns with these standard names, but to
7175: any patterns that will match such an instruction. @xref{Register
7176: Classes}.
7177:
7178: @item @samp{neg@var{m}2}
7179: Negate operand 1 and store the result in operand 0.
7180:
7181: @item @samp{abs@var{m}2}
7182: Store the absolute value of operand 1 into operand 0.
7183:
7184: @item @samp{sqrt@var{m}2}
7185: Store the square root of operand 1 into operand 0.
7186:
7187: @item @samp{ffs@var{m}2}
7188: Store into operand 0 one plus the index of the least significant 1-bit
7189: of operand 1. If operand 1 is zero, store zero. @var{m} is the mode
7190: of operand 0; operand 1's mode is specified by the instruction
7191: pattern, and the compiler will convert the operand to that mode before
7192: generating the instruction.
7193:
7194: @item @samp{one_cmpl@var{m}2}
7195: Store the bitwise-complement of operand 1 into operand 0.
7196:
7197: @item @samp{cmp@var{m}}
7198: Compare operand 0 and operand 1, and set the condition codes.
7199: The RTL pattern should look like this:
7200:
7201: @example
1.1.1.6 root 7202: (set (cc0) (compare (match_operand:@var{m} 0 @dots{})
7203: (match_operand:@var{m} 1 @dots{})))
1.1 root 7204: @end example
7205:
7206: Each such definition in the machine description, for integer mode
7207: @var{m}, must have a corresponding @samp{tst@var{m}} pattern, because
7208: optimization can simplify the compare into a test when operand 1 is
7209: zero.
7210:
7211: @item @samp{tst@var{m}}
7212: Compare operand 0 against zero, and set the condition codes.
7213: The RTL pattern should look like this:
7214:
7215: @example
7216: (set (cc0) (match_operand:@var{m} 0 @dots{}))
7217: @end example
7218:
7219: @item @samp{movstr@var{m}}
7220: Block move instruction. The addresses of the destination and source
7221: strings are the first two operands, and both are in mode @code{Pmode}.
7222: The number of bytes to move is the third operand, in mode @var{m}.
1.1.1.5 root 7223: The fourth operand is the known shared alignment of the source and
7224: destination, in the form of a @code{const_int} rtx.
1.1 root 7225:
7226: @item @samp{cmpstr@var{m}}
7227: Block compare instruction, with operands like @samp{movstr@var{m}}
7228: except that the two memory blocks are compared byte by byte
7229: in lexicographic order. The effect of the instruction is to set
7230: the condition codes.
7231:
7232: @item @samp{float@var{m}@var{n}2}
1.1.1.9 root 7233: Convert signed integer operand 1 (valid for fixed point mode @var{m}) to
7234: floating point mode @var{n} and store in operand 0 (which has mode
7235: @var{n}).
7236:
7237: @item @samp{floatuns@var{m}@var{n}2}
7238: Convert unsigned integer operand 1 (valid for fixed point mode @var{m})
7239: to floating point mode @var{n} and store in operand 0 (which has mode
7240: @var{n}).
1.1 root 7241:
7242: @item @samp{fix@var{m}@var{n}2}
7243: Convert operand 1 (valid for floating point mode @var{m}) to fixed
7244: point mode @var{n} as a signed number and store in operand 0 (which
7245: has mode @var{n}). This instruction's result is defined only when
7246: the value of operand 1 is an integer.
7247:
7248: @item @samp{fixuns@var{m}@var{n}2}
7249: Convert operand 1 (valid for floating point mode @var{m}) to fixed
7250: point mode @var{n} as an unsigned number and store in operand 0 (which
7251: has mode @var{n}). This instruction's result is defined only when the
7252: value of operand 1 is an integer.
7253:
7254: @item @samp{ftrunc@var{m}2}
7255: Convert operand 1 (valid for floating point mode @var{m}) to an
7256: integer value, still represented in floating point mode @var{m}, and
7257: store it in operand 0 (valid for floating point mode @var{m}).
7258:
7259: @item @samp{fix_trunc@var{m}@var{n}2}
7260: Like @samp{fix@var{m}@var{n}2} but works for any floating point value
7261: of mode @var{m} by converting the value to an integer.
7262:
7263: @item @samp{fixuns_trunc@var{m}@var{n}2}
7264: Like @samp{fixuns@var{m}@var{n}2} but works for any floating point
7265: value of mode @var{m} by converting the value to an integer.
7266:
7267: @item @samp{trunc@var{m}@var{n}}
7268: Truncate operand 1 (valid for mode @var{m}) to mode @var{n} and
7269: store in operand 0 (which has mode @var{n}). Both modes must be fixed
7270: point or both floating point.
7271:
7272: @item @samp{extend@var{m}@var{n}}
7273: Sign-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
7274: store in operand 0 (which has mode @var{n}). Both modes must be fixed
7275: point or both floating point.
7276:
7277: @item @samp{zero_extend@var{m}@var{n}}
7278: Zero-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
7279: store in operand 0 (which has mode @var{n}). Both modes must be fixed
7280: point.
7281:
7282: @item @samp{extv}
7283: Extract a bit-field from operand 1 (a register or memory operand),
7284: where operand 2 specifies the width in bits and operand 3 the starting
1.1.1.10 root 7285: bit, and store it in operand 0. Operand 0 must have @code{SImode}.
1.1 root 7286: Operand 1 may have mode @code{QImode} or @code{SImode}; often
7287: @code{SImode} is allowed only for registers. Operands 2 and 3 must be
7288: valid for @code{SImode}.
7289:
7290: The RTL generation pass generates this instruction only with constants
7291: for operands 2 and 3.
7292:
7293: The bit-field value is sign-extended to a full word integer
7294: before it is stored in operand 0.
7295:
7296: @item @samp{extzv}
7297: Like @samp{extv} except that the bit-field value is zero-extended.
7298:
7299: @item @samp{insv}
7300: Store operand 3 (which must be valid for @code{SImode}) into a
7301: bit-field in operand 0, where operand 1 specifies the width in bits
7302: and operand 2 the starting bit. Operand 0 may have mode @code{QImode}
7303: or @code{SImode}; often @code{SImode} is allowed only for registers.
7304: Operands 1 and 2 must be valid for @code{SImode}.
7305:
7306: The RTL generation pass generates this instruction only with constants
7307: for operands 1 and 2.
7308:
7309: @item @samp{s@var{cond}}
7310: Store zero or nonzero in the operand according to the condition codes.
7311: Value stored is nonzero iff the condition @var{cond} is true.
7312: @var{cond} is the name of a comparison operation expression code, such
1.1.1.8 root 7313: as @code{eq}, @code{lt} or @code{leu}.
1.1 root 7314:
7315: You specify the mode that the operand must have when you write the
7316: @code{match_operand} expression. The compiler automatically sees
7317: which mode you have used and supplies an operand of that mode.
7318:
1.1.1.8 root 7319: The value stored for a true condition must have 1 as its low bit, or
7320: else must be negative. Otherwise the instruction is not suitable and
7321: must be omitted from the machine description. You must tell the
7322: compiler exactly which value is stored by defining the macro
7323: @code{STORE_FLAG_VALUE}.
1.1 root 7324:
7325: @item @samp{b@var{cond}}
1.1.1.8 root 7326: Conditional branch instruction. Operand 0 is a @code{label_ref}
1.1 root 7327: that refers to the label to jump to. Jump if the condition codes
7328: meet condition @var{cond}.
7329:
7330: @item @samp{call}
7331: Subroutine call instruction returning no value. Operand 0 is the
7332: function to call; operand 1 is the number of bytes of arguments pushed
1.1.1.8 root 7333: (in mode @code{SImode}, except it is normally a @code{const_int});
1.1 root 7334: operand 2 is the number of registers used as operands.
7335:
7336: On most machines, operand 2 is not actually stored into the RTL
7337: pattern. It is supplied for the sake of some RISC machines which need
7338: to put this information into the assembler code; they can put it in
7339: the RTL instead of operand 1.
7340:
1.1.1.8 root 7341: Operand 0 should be a @code{mem} RTX whose address is the address of
1.1 root 7342: the function.
7343:
7344: @item @samp{call_value}
7345: Subroutine call instruction returning a value. Operand 0 is the hard
7346: register in which the value is returned. There are three more
7347: operands, the same as the three operands of the @samp{call}
7348: instruction (but with numbers increased by one).
7349:
7350: Subroutines that return @code{BLKmode} objects use the @samp{call}
7351: insn.
7352:
7353: @item @samp{return}
7354: Subroutine return instruction. This instruction pattern name should be
7355: defined only if a single instruction can do all the work of returning
7356: from a function.
7357:
1.1.1.8 root 7358: @item @samp{nop}
7359: No-op instruction. This instruction pattern name should always be defined
7360: to output a no-op in assembler code. @code{(const_int 0)} will do as an
7361: RTL pattern.
7362:
1.1 root 7363: @item @samp{casesi}
7364: Instruction to jump through a dispatch table, including bounds checking.
7365: This instruction takes five operands:
7366:
7367: @enumerate
7368: @item
7369: The index to dispatch on, which has mode @code{SImode}.
7370:
7371: @item
7372: The lower bound for indices in the table, an integer constant.
7373:
7374: @item
1.1.1.6 root 7375: The total range of indices in the table---the largest index
7376: minus the smallest one (both inclusive).
1.1 root 7377:
7378: @item
7379: A label to jump to if the index has a value outside the bounds.
7380: (If the machine-description macro @code{CASE_DROPS_THROUGH} is defined,
7381: then an out-of-bounds index drops through to the code following
7382: the jump table instead of jumping to this label. In that case,
7383: this label is not actually used by the @samp{casesi} instruction,
7384: but it is always provided as an operand.)
7385:
7386: @item
7387: A label that precedes the table itself.
7388: @end enumerate
7389:
1.1.1.8 root 7390: The table is a @code{addr_vec} or @code{addr_diff_vec} inside of a
7391: @code{jump_insn}. The number of elements in the table is one plus the
1.1 root 7392: difference between the upper bound and the lower bound.
7393:
7394: @item @samp{tablejump}
7395: Instruction to jump to a variable address. This is a low-level
7396: capability which can be used to implement a dispatch table when there
7397: is no @samp{casesi} pattern.
7398:
7399: This pattern requires two operands: the address or offset, and a label
7400: which should immediately precede the jump table. If the macro
7401: @code{CASE_VECTOR_PC_RELATIVE} is defined then the first operand is an
1.1.1.10 root 7402: offset that counts from the address of the table; otherwise, it is an
7403: absolute address to jump to.
1.1 root 7404:
7405: The @samp{tablejump} insn is always the last insn before the jump
7406: table it uses. Its assembler code normally has no need to use the
7407: second operand, but you should incorporate it in the RTL pattern so
7408: that the jump optimizer will not delete the table as unreachable code.
7409: @end table
7410:
7411: @node Pattern Ordering, Dependent Patterns, Standard Names, Machine Desc
7412: @section When the Order of Patterns Matters
7413:
7414: Sometimes an insn can match more than one instruction pattern. Then the
7415: pattern that appears first in the machine description is the one used.
7416: Therefore, more specific patterns (patterns that will match fewer things)
7417: and faster instructions (those that will produce better code when they
7418: do match) should usually go first in the description.
7419:
7420: In some cases the effect of ordering the patterns can be used to hide
7421: a pattern when it is not valid. For example, the 68000 has an
7422: instruction for converting a fullword to floating point and another
7423: for converting a byte to floating point. An instruction converting
7424: an integer to floating point could match either one. We put the
7425: pattern to convert the fullword first to make sure that one will
7426: be used rather than the other. (Otherwise a large integer might
7427: be generated as a single-byte immediate quantity, which would not work.)
7428: Instead of using this pattern ordering it would be possible to make the
7429: pattern for convert-a-byte smart enough to deal properly with any
7430: constant value.
7431:
7432: @node Dependent Patterns, Jump Patterns, Pattern Ordering, Machine Desc
7433: @section Interdependence of Patterns
7434:
7435: Every machine description must have a named pattern for each of the
7436: conditional branch names @samp{b@var{cond}}. The recognition template
7437: must always have the form
7438:
7439: @example
7440: (set (pc)
7441: (if_then_else (@var{cond} (cc0) (const_int 0))
7442: (label_ref (match_operand 0 "" ""))
7443: (pc)))
7444: @end example
7445:
7446: @noindent
7447: In addition, every machine description must have an anonymous pattern
7448: for each of the possible reverse-conditional branches. These patterns
7449: look like
7450:
7451: @example
7452: (set (pc)
7453: (if_then_else (@var{cond} (cc0) (const_int 0))
7454: (pc)
7455: (label_ref (match_operand 0 "" ""))))
7456: @end example
7457:
7458: @noindent
7459: They are necessary because jump optimization can turn direct-conditional
7460: branches into reverse-conditional branches.
7461:
7462: The compiler does more with RTL than just create it from patterns
7463: and recognize the patterns: it can perform arithmetic expression codes
7464: when constant values for their operands can be determined. As a result,
7465: sometimes having one pattern can require other patterns. For example, the
7466: Vax has no `and' instruction, but it has `and not' instructions. Here
7467: is the definition of one of them:
7468:
7469: @example
7470: (define_insn "andcbsi2"
7471: [(set (match_operand:SI 0 "general_operand" "")
7472: (and:SI (match_dup 0)
7473: (not:SI (match_operand:SI
7474: 1 "general_operand" ""))))]
7475: ""
7476: "bicl2 %1,%0")
7477: @end example
7478:
7479: @noindent
7480: If operand 1 is an explicit integer constant, an instruction constructed
7481: using that pattern can be simplified into an `and' like this:
7482:
7483: @example
7484: (set (reg:SI 41)
7485: (and:SI (reg:SI 41)
7486: (const_int 0xffff7fff)))
7487: @end example
7488:
7489: @noindent
7490: (where the integer constant is the one's complement of what
7491: appeared in the original instruction).
7492:
7493: To avoid a fatal error, the compiler must have a pattern that recognizes
7494: such an instruction. Here is what is used:
7495:
7496: @example
7497: (define_insn ""
7498: [(set (match_operand:SI 0 "general_operand" "")
7499: (and:SI (match_dup 0)
7500: (match_operand:SI 1 "general_operand" "")))]
7501: "GET_CODE (operands[1]) == CONST_INT"
7502: "*
7503: @{ operands[1]
7504: = gen_rtx (CONST_INT, VOIDmode, ~INTVAL (operands[1]));
7505: return \"bicl2 %1,%0\";
7506: @}")
7507: @end example
7508:
7509: @noindent
7510: Whereas a pattern to match a general `and' instruction is impossible to
7511: support on the Vax, this pattern is possible because it matches only a
7512: constant second argument: a special case that can be output as an `and not'
7513: instruction.
7514:
7515: A ``compare'' instruction whose RTL looks like this:
7516:
7517: @example
1.1.1.6 root 7518: (set (cc0) (compare @var{operand} (const_int 0)))
1.1 root 7519: @end example
7520:
7521: @noindent
7522: may be simplified by optimization into a ``test'' like this:
7523:
7524: @example
7525: (set (cc0) @var{operand})
7526: @end example
7527:
7528: @noindent
7529: So in the machine description, each ``compare'' pattern for an integer
7530: mode must have a corresponding ``test'' pattern that will match the
7531: result of such simplification.
7532:
7533: In some cases machines support instructions identical except for the
7534: machine mode of one or more operands. For example, there may be
7535: ``sign-extend halfword'' and ``sign-extend byte'' instructions whose
7536: patterns are
7537:
7538: @example
7539: (set (match_operand:SI 0 @dots{})
7540: (extend:SI (match_operand:HI 1 @dots{})))
7541:
7542: (set (match_operand:SI 0 @dots{})
7543: (extend:SI (match_operand:QI 1 @dots{})))
7544: @end example
7545:
7546: @noindent
7547: Constant integers do not specify a machine mode, so an instruction to
7548: extend a constant value could match either pattern. The pattern it
7549: actually will match is the one that appears first in the file. For correct
7550: results, this must be the one for the widest possible mode (@code{HImode},
7551: here). If the pattern matches the @code{QImode} instruction, the results
7552: will be incorrect if the constant value does not actually fit that mode.
7553:
7554: Such instructions to extend constants are rarely generated because they are
7555: optimized away, but they do occasionally happen in nonoptimized
7556: compilations.
7557:
7558: When an instruction has the constraint letter @samp{o}, the reload
1.1.1.8 root 7559: pass may generate instructions which copy a nonoffsettable address into
1.1 root 7560: an index register. The idea is that the register can be used as a
1.1.1.8 root 7561: replacement offsettable address. In order for these generated
1.1 root 7562: instructions to work, there must be patterns to copy any kind of valid
7563: address into a register.
7564:
7565: Most older machine designs have ``load address'' instructions which do
7566: just what is needed here. Some RISC machines do not advertise such
7567: instructions, but the possible addresses on these machines are very
7568: limited, so it is easy to fake them.
7569:
7570: Auto-increment and auto-decrement addresses are an exception; there
7571: need not be an instruction that can copy such an address into a
7572: register, because reload handles these cases in a different manner.
7573:
7574: @node Jump Patterns, Peephole Definitions, Dependent Patterns, Machine Desc
7575: @section Defining Jump Instruction Patterns
7576:
7577: GNU CC assumes that the machine has a condition code. A comparison insn
7578: sets the condition code, recording the results of both signed and unsigned
7579: comparison of the given operands. A separate branch insn tests the
7580: condition code and branches or not according its value. The branch insns
7581: come in distinct signed and unsigned flavors. Many common machines, such
7582: as the Vax, the 68000 and the 32000, work this way.
7583:
7584: Some machines have distinct signed and unsigned compare instructions, and
7585: only one set of conditional branch instructions. The easiest way to handle
7586: these machines is to treat them just like the others until the final stage
7587: where assembly code is written. At this time, when outputting code for the
7588: compare instruction, peek ahead at the following branch using
7589: @code{NEXT_INSN (insn)}. (The variable @code{insn} refers to the insn
7590: being output, in the output-writing code in an instruction pattern.) If
7591: the RTL says that is an unsigned branch, output an unsigned compare;
7592: otherwise output a signed compare. When the branch itself is output, you
7593: can treat signed and unsigned branches identically.
7594:
7595: The reason you can do this is that GNU CC always generates a pair of
7596: consecutive RTL insns, one to set the condition code and one to test it,
7597: and keeps the pair inviolate until the end.
7598:
7599: To go with this technique, you must define the machine-description macro
7600: @code{NOTICE_UPDATE_CC} to do @code{CC_STATUS_INIT}; in other words, no
7601: compare instruction is superfluous.
7602:
7603: Some machines have compare-and-branch instructions and no condition code.
7604: A similar technique works for them. When it is time to ``output'' a
7605: compare instruction, record its operands in two static variables. When
7606: outputting the branch-on-condition-code instruction that follows, actually
7607: output a compare-and-branch instruction that uses the remembered operands.
7608:
7609: It also works to define patterns for compare-and-branch instructions.
7610: In optimizing compilation, the pair of compare and branch instructions
1.1.1.5 root 7611: will be combined according to these patterns. But this does not happen
1.1 root 7612: if optimization is not requested. So you must use one of the solutions
7613: above in addition to any special patterns you define.
7614:
7615: @node Peephole Definitions, Expander Definitions, Jump Patterns, Machine Desc
7616: @section Defining Machine-Specific Peephole Optimizers
7617:
7618: In addition to instruction patterns the @file{md} file may contain
7619: definitions of machine-specific peephole optimizations.
7620:
7621: The combiner does not notice certain peephole optimizations when the data
7622: flow in the program does not suggest that it should try them. For example,
7623: sometimes two consecutive insns related in purpose can be combined even
7624: though the second one does not appear to use a register computed in the
7625: first one. A machine-specific peephole optimizer can detect such
7626: opportunities.
7627:
7628: A definition looks like this:
7629:
7630: @example
7631: (define_peephole
7632: [@var{insn-pattern-1}
7633: @var{insn-pattern-2}
7634: @dots{}]
7635: "@var{condition}"
7636: "@var{template}"
7637: "@var{machine-specific info}")
7638: @end example
7639:
7640: @noindent
7641: The last string operand may be omitted if you are not using any
7642: machine-specific information in this machine description. If present,
1.1.1.8 root 7643: it must obey the same rules as in a @code{define_insn}.
1.1 root 7644:
7645: In this skeleton, @var{insn-pattern-1} and so on are patterns to match
1.1.1.5 root 7646: consecutive insns. The optimization applies to a sequence of insns when
7647: @var{insn-pattern-1} matches the first one, @var{insn-pattern-2} matches
7648: the next, and so on.@refill
1.1 root 7649:
1.1.1.8 root 7650: Each of the insns matched by a peephole must also match a
7651: @code{define_insn}. Peepholes are checked only at the last stage just
7652: before code generation, and only optionally. Therefore, any insn which
7653: would match a peephole but no @code{define_insn} will cause a crash in code
7654: generation in an unoptimized compilation, or at various optimization
7655: stages.
1.1 root 7656:
1.1.1.5 root 7657: The operands of the insns are matched with @code{match_operands} and
7658: @code{match_dup}, as usual. What is not usual is that the operand numbers
7659: apply to all the insn patterns in the definition. So, you can check for
7660: identical operands in two insns by using @code{match_operand} in one insn
7661: and @code{match_dup} in the other.
1.1 root 7662:
7663: The operand constraints used in @code{match_operand} patterns do not have
1.1.1.8 root 7664: any direct effect on the applicability of the peephole, but they will
7665: be validated afterward, so make sure your constraints are general enough
7666: to apply whenever the peephole matches. If the peephole matches
7667: but the constraints are not satisfied, the compiler will crash.
7668:
7669: It is safe to omit constraints in all the operands of the peephole; or
7670: you can write constraints which serve as a double-check on the criteria
7671: previously tested.
1.1 root 7672:
1.1.1.5 root 7673: Once a sequence of insns matches the patterns, the @var{condition} is
7674: checked. This is a C expression which makes the final decision whether to
7675: perform the optimization (we do so if the expression is nonzero). If
1.1 root 7676: @var{condition} is omitted (in other words, the string is empty) then the
1.1.1.5 root 7677: optimization is applied to every sequence of insns that matches the
1.1 root 7678: patterns.
7679:
1.1.1.5 root 7680: The defined peephole optimizations are applied after register allocation
7681: is complete. Therefore, the peephole definition can check which
7682: operands have ended up in which kinds of registers, just by looking at
7683: the operands.
1.1 root 7684:
7685: The way to refer to the operands in @var{condition} is to write
7686: @code{operands[@var{i}]} for operand number @var{i} (as matched by
7687: @code{(match_operand @var{i} @dots{})}). Use the variable @code{insn} to
7688: refer to the last of the insns being matched; use @code{PREV_INSN} to find
1.1.1.8 root 7689: the preceding insns (but be careful to skip over any @code{note} insns that
1.1 root 7690: intervene).@refill
7691:
7692: When optimizing computations with intermediate results, you can use
7693: @var{condition} to match only when the intermediate results are not used
7694: elsewhere. Use the C expression @code{dead_or_set_p (@var{insn},
7695: @var{op})}, where @var{insn} is the insn in which you expect the value to
7696: be used for the last time (from the value of @code{insn}, together with use
7697: of @code{PREV_INSN}), and @var{op} is the intermediate value (from
7698: @code{operands[@var{i}]}).@refill
7699:
1.1.1.5 root 7700: Applying the optimization means replacing the sequence of insns with one
7701: new insn. The @var{template} controls ultimate output of assembler code
7702: for this combined insn. It works exactly like the template of a
7703: @code{define_insn}. Operand numbers in this template are the same ones
7704: used in matching the original sequence of insns.
1.1 root 7705:
7706: The result of a defined peephole optimizer does not need to match any of
1.1.1.5 root 7707: the insn patterns in the machine description; it does not even have an
7708: opportunity to match them. The peephole optimizer definition itself serves
7709: as the insn pattern to control how the insn is output.
7710:
7711: Defined peephole optimizers are run as assembler code is being output,
7712: so the insns they produce are never combined or rearranged in any way.
1.1 root 7713:
7714: Here is an example, taken from the 68000 machine description:
7715:
7716: @example
7717: (define_peephole
7718: [(set (reg:SI 15) (plus:SI (reg:SI 15) (const_int 4)))
1.1.1.13! root 7719: (set (match_operand:DF 0 "register_operand" "=f")
1.1 root 7720: (match_operand:DF 1 "register_operand" "ad"))]
7721: "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
7722: "*
7723: @{
7724: rtx xoperands[2];
7725: xoperands[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
7726: #ifdef MOTOROLA
7727: output_asm_insn (\"move.l %1,(sp)\", xoperands);
7728: output_asm_insn (\"move.l %1,-(sp)\", operands);
7729: return \"fmove.d (sp)+,%0\";
7730: #else
7731: output_asm_insn (\"movel %1,sp@@\", xoperands);
7732: output_asm_insn (\"movel %1,sp@@-\", operands);
7733: return \"fmoved sp@@+,%0\";
7734: #endif
7735: @}
7736: ")
7737: @end example
7738:
7739: The effect of this optimization is to change
7740:
7741: @example
7742: jbsr _foobar
7743: addql #4,sp
7744: movel d1,sp@@-
7745: movel d0,sp@@-
7746: fmoved sp@@+,fp0
7747: @end example
7748:
7749: @noindent
7750: into
7751:
7752: @example
7753: jbsr _foobar
7754: movel d1,sp@@
7755: movel d0,sp@@-
7756: fmoved sp@@+,fp0
7757: @end example
7758:
1.1.1.5 root 7759: @ignore
7760: If a peephole matches a sequence including one or more jump insns, you must
7761: take account of the flags such as @code{CC_REVERSED} which specify that the
7762: condition codes are represented in an unusual manner. The compiler
7763: automatically alters any ordinary conditional jumps which occur in such
7764: situations, but the compiler cannot alter jumps which have been replaced by
7765: peephole optimizations. So it is up to you to alter the assembler code
7766: that the peephole produces. Supply C code to write the assembler output,
7767: and in this C code check the condition code status flags and change the
7768: assembler code as appropriate.
7769: @end ignore
7770:
1.1.1.8 root 7771: @var{insn-pattern-1} and so on look @emph{almost} like the second
7772: operand of @code{define_insn}. There is one important difference: the
7773: second operand of @code{define_insn} consists of one or more RTX's
7774: enclosed in square brackets. Usually, there is only one: then the same
7775: action can be written as an element of a @code{define_peephole}. But
7776: when there are multiple actions in a @code{define_insn}, they are
7777: implicitly enclosed in a @code{parallel}. Then you must explicitly
7778: write the @code{parallel}, and the square brackets within it, in the
7779: @code{define_peephole}. Thus, if an insn pattern looks like this,
7780:
7781: @example
7782: (define_insn "divmodsi4"
7783: [(set (match_operand:SI 0 "general_operand" "=d")
7784: (div:SI (match_operand:SI 1 "general_operand" "0")
7785: (match_operand:SI 2 "general_operand" "dmsK")))
7786: (set (match_operand:SI 3 "general_operand" "=d")
7787: (mod:SI (match_dup 1) (match_dup 2)))]
7788: "TARGET_68020"
7789: "divsl%.l %2,%3:%0")
7790: @end example
7791:
7792: @noindent
7793: then the way to mention this insn in a peephole is as follows:
7794:
7795: @example
7796: (define_peephole
7797: [@dots{}
7798: (parallel
7799: [(set (match_operand:SI 0 "general_operand" "=d")
7800: (div:SI (match_operand:SI 1 "general_operand" "0")
7801: (match_operand:SI 2 "general_operand" "dmsK")))
7802: (set (match_operand:SI 3 "general_operand" "=d")
7803: (mod:SI (match_dup 1) (match_dup 2)))])
7804: @dots{}]
7805: @dots{})
7806: @end example
7807:
1.1 root 7808: @node Expander Definitions,, Peephole Definitions, Machine Desc
7809: @section Defining RTL Sequences for Code Generation
7810:
7811: On some target machines, some standard pattern names for RTL generation
7812: cannot be handled with single insn, but a sequence of RTL insns can
7813: represent them. For these target machines, you can write a
1.1.1.8 root 7814: @code{define_expand} to specify how to generate the sequence of RTL.
1.1 root 7815:
1.1.1.8 root 7816: A @code{define_expand} is an RTL expression that looks almost like a
7817: @code{define_insn}; but, unlike the latter, a @code{define_expand} is used
1.1 root 7818: only for RTL generation and it can produce more than one RTL insn.
7819:
1.1.1.8 root 7820: A @code{define_expand} RTX has four operands:
1.1 root 7821:
7822: @itemize @bullet
7823: @item
1.1.1.8 root 7824: The name. Each @code{define_expand} must have a name, since the only
1.1 root 7825: use for it is to refer to it by name.
7826:
7827: @item
7828: The RTL template. This is just like the RTL template for a
1.1.1.8 root 7829: @code{define_peephole} in that it is a vector of RTL expressions
1.1 root 7830: each being one insn.
7831:
7832: @item
7833: The condition, a string containing a C expression. This expression is
7834: used to express how the availability of this pattern depends on
7835: subclasses of target machine, selected by command-line options when
7836: GNU CC is run. This is just like the condition of a
1.1.1.8 root 7837: @code{define_insn} that has a standard name.
1.1 root 7838:
7839: @item
7840: The preparation statements, a string containing zero or more C
7841: statements which are to be executed before RTL code is generated from
7842: the RTL template.
7843:
7844: Usually these statements prepare temporary registers for use as
7845: internal operands in the RTL template, but they can also generate RTL
1.1.1.8 root 7846: insns directly by calling routines such as @code{emit_insn}, etc.
1.1 root 7847: Any such insns precede the ones that come from the RTL template.
7848: @end itemize
7849:
1.1.1.8 root 7850: Every RTL insn emitted by a @code{define_expand} must match some
7851: @code{define_insn} in the machine description. Otherwise, the compiler
7852: will crash when trying to generate code for the insn or trying to optimize
7853: it.
7854:
1.1 root 7855: The RTL template, in addition to controlling generation of RTL insns,
7856: also describes the operands that need to be specified when this pattern
7857: is used. In particular, it gives a predicate for each operand.
7858:
7859: A true operand, which need to be specified in order to generate RTL from
1.1.1.8 root 7860: the pattern, should be described with a @code{match_operand} in its first
1.1 root 7861: occurrence in the RTL template. This enters information on the operand's
7862: predicate into the tables that record such things. GNU CC uses the
7863: information to preload the operand into a register if that is required for
7864: valid RTL code. If the operand is referred to more than once, subsequent
1.1.1.8 root 7865: references should use @code{match_dup}.
1.1 root 7866:
7867: The RTL template may also refer to internal ``operands'' which are
7868: temporary registers or labels used only within the sequence made by the
1.1.1.8 root 7869: @code{define_expand}. Internal operands are substituted into the RTL
7870: template with @code{match_dup}, never with @code{match_operand}. The
1.1 root 7871: values of the internal operands are not passed in as arguments by the
7872: compiler when it requests use of this pattern. Instead, they are computed
7873: within the pattern, in the preparation statements. These statements
7874: compute the values and store them into the appropriate elements of
1.1.1.8 root 7875: @code{operands} so that @code{match_dup} can find them.
1.1 root 7876:
7877: There are two special macros defined for use in the preparation statements:
7878: @code{DONE} and @code{FAIL}. Use them with a following semicolon,
7879: as a statement.
7880:
7881: @table @code
7882: @item DONE
7883: Use the @code{DONE} macro to end RTL generation for the pattern. The
7884: only RTL insns resulting from the pattern on this occasion will be
7885: those already emitted by explicit calls to @code{emit_insn} within the
7886: preparation statements; the RTL template will not be generated.
7887:
7888: @item FAIL
7889: Make the pattern fail on this occasion. When a pattern fails, it means
7890: that the pattern was not truly available. The calling routines in the
7891: compiler will try other strategies for code generation using other patterns.
7892:
7893: Failure is currently supported only for binary operations (addition,
7894: multiplication, shifting, etc.).
7895:
7896: Do not emit any insns explicitly with @code{emit_insn} before failing.
7897: @end table
7898:
7899: Here is an example, the definition of left-shift for the SPUR chip:
7900:
7901: @example
7902: (define_expand "ashlsi3"
7903: [(set (match_operand:SI 0 "register_operand" "")
7904: (ashift:SI
7905: (match_operand:SI 1 "register_operand" "")
7906: (match_operand:SI 2 "nonmemory_operand" "")))]
7907: ""
7908: "
7909: @{
7910: if (GET_CODE (operands[2]) != CONST_INT
7911: || (unsigned) INTVAL (operands[2]) > 3)
7912: FAIL;
7913: @}")
7914: @end example
7915:
7916: @noindent
1.1.1.8 root 7917: This example uses @code{define_expand} so that it can generate an RTL insn
1.1 root 7918: for shifting when the shift-count is in the supported range of 0 to 3 but
7919: fail in other cases where machine insns aren't available. When it fails,
7920: the compiler tries another strategy using different patterns (such as, a
7921: library call).
7922:
7923: If the compiler were able to handle nontrivial condition-strings in
1.1.1.8 root 7924: patterns with names, then it would be possible to use a
7925: @code{define_insn} in that case. Here is another case (zero-extension
7926: on the 68000) which makes more use of the power of @code{define_expand}:
1.1 root 7927:
7928: @example
7929: (define_expand "zero_extendhisi2"
7930: [(set (match_operand:SI 0 "general_operand" "")
7931: (const_int 0))
7932: (set (strict_low_part
7933: (subreg:HI
1.1.1.8 root 7934: (match_dup 0)
1.1 root 7935: 0))
7936: (match_operand:HI 1 "general_operand" ""))]
7937: ""
7938: "operands[1] = make_safe_from (operands[1], operands[0]);")
7939: @end example
7940:
7941: @noindent
7942: Here two RTL insns are generated, one to clear the entire output operand
7943: and the other to copy the input operand into its low half. This sequence
7944: is incorrect if the input operand refers to [the old value of] the output
7945: operand, so the preparation statement makes sure this isn't so. The
7946: function @code{make_safe_from} copies the @code{operands[1]} into a
7947: temporary register if it refers to @code{operands[0]}. It does this
7948: by emitting another RTL insn.
7949:
7950: Finally, a third example shows the use of an internal operand.
1.1.1.8 root 7951: Zero-extension on the SPUR chip is done by @code{and}-ing the result
1.1 root 7952: against a halfword mask. But this mask cannot be represented by a
1.1.1.8 root 7953: @code{const_int} because the constant value is too large to be legitimate
1.1 root 7954: on this machine. So it must be copied into a register with
1.1.1.8 root 7955: @code{force_reg} and then the register used in the @code{and}.
1.1 root 7956:
7957: @example
7958: (define_expand "zero_extendhisi2"
7959: [(set (match_operand:SI 0 "register_operand" "")
7960: (and:SI (subreg:SI
7961: (match_operand:HI 1 "register_operand" "")
7962: 0)
7963: (match_dup 2)))]
7964: ""
7965: "operands[2]
7966: = force_reg (SImode, gen_rtx (CONST_INT,
7967: VOIDmode, 65535)); ")
7968: @end example
7969:
1.1.1.8 root 7970: @strong{Note:} If the @code{define_expand} is used to serve a standard
7971: binary or unary arithmetic operation, then the last insn it generates
7972: must not be a @code{code_label}, @code{barrier} or @code{note}. It must
7973: be an @code{insn}, @code{jump_insn} or @code{call_insn}.
7974:
1.1 root 7975: @node Machine Macros, Config, Machine Desc, Top
7976: @chapter Machine Description Macros
7977:
7978: The other half of the machine description is a C header file conventionally
7979: given the name @file{tm-@var{machine}.h}. The file @file{tm.h} should be a
7980: link to it. The header file @file{config.h} includes @file{tm.h} and most
7981: compiler source files include @file{config.h}.
7982:
7983: @menu
1.1.1.9 root 7984: * Run-time Target:: Defining @samp{-m} options like @samp{-m68000} and @samp{-m68020}.
1.1 root 7985: * Storage Layout:: Defining sizes and alignments of data types.
7986: * Registers:: Naming and describing the hardware registers.
7987: * Register Classes:: Defining the classes of hardware registers.
7988: * Stack Layout:: Defining which way the stack grows and by how much.
1.1.1.12 root 7989: * Library Calls:: Specifying how to call certain library routines.
1.1 root 7990: * Addressing Modes:: Defining addressing modes valid for memory operands.
1.1.1.8 root 7991: * Delayed Branch:: Do branches execute the following instruction?
1.1 root 7992: * Condition Code:: Defining how insns update the condition code.
1.1.1.5 root 7993: * Cross-compilation:: Handling floating point for cross-compilers.
1.1 root 7994: * Misc:: Everything else.
1.1.1.11 root 7995: * Assembler Format:: Defining how to write insns and pseudo-ops to output.
1.1 root 7996: @end menu
7997:
7998: @node Run-time Target, Storage Layout, Machine Macros, Machine Macros
7999: @section Run-time Target Specification
8000:
8001: @table @code
8002: @item CPP_PREDEFINES
8003: Define this to be a string constant containing @samp{-D} options to
8004: define the predefined macros that identify this machine and system.
8005: These macros will be predefined unless the @samp{-ansi} option is
8006: specified.
8007:
1.1.1.4 root 8008: In addition, a parallel set of macros are predefined, whose names are
8009: made by appending @samp{__} at the beginning and at the end. These
8010: @samp{__} macros are permitted by the ANSI standard, so they are
8011: predefined regardless of whether @samp{-ansi} is specified.
8012:
8013: For example, on the Sun, one can use the following value:
1.1 root 8014:
8015: @example
8016: "-Dmc68000 -Dsun -Dunix"
8017: @end example
8018:
1.1.1.8 root 8019: The result is to define the macros @code{__mc68000__}, @code{__sun__}
8020: and @code{__unix__} unconditionally, and the macros @code{mc68000},
8021: @code{sun} and @code{unix} provided @samp{-ansi} is not specified.
1.1.1.4 root 8022:
1.1 root 8023: @item CPP_SPEC
8024: A C string constant that tells the GNU CC driver program options to
8025: pass to CPP. It can also specify how to translate options you
8026: give to GNU CC into options for GNU CC to pass to the CPP.
8027:
8028: Do not define this macro if it does not need to do anything.
8029:
8030: @item CC1_SPEC
8031: A C string constant that tells the GNU CC driver program options to
8032: pass to CC1. It can also specify how to translate options you
8033: give to GNU CC into options for GNU CC to pass to the CC1.
8034:
8035: Do not define this macro if it does not need to do anything.
8036:
8037: @item extern int target_flags;
8038: This declaration should be present.
8039:
8040: @item TARGET_@dots{}
8041: This series of macros is to allow compiler command arguments to
8042: enable or disable the use of optional features of the target machine.
8043: For example, one machine description serves both the 68000 and
8044: the 68020; a command argument tells the compiler whether it should
8045: use 68020-only instructions or not. This command argument works
8046: by means of a macro @code{TARGET_68020} that tests a bit in
8047: @code{target_flags}.
8048:
8049: Define a macro @code{TARGET_@var{featurename}} for each such option.
8050: Its definition should test a bit in @code{target_flags}; for example:
8051:
8052: @example
8053: #define TARGET_68020 (target_flags & 1)
8054: @end example
8055:
8056: One place where these macros are used is in the condition-expressions
8057: of instruction patterns. Note how @code{TARGET_68020} appears
8058: frequently in the 68000 machine description file, @file{m68k.md}.
8059: Another place they are used is in the definitions of the other
8060: macros in the @file{tm-@var{machine}.h} file.
8061:
8062: @item TARGET_SWITCHES
8063: This macro defines names of command options to set and clear
8064: bits in @code{target_flags}. Its definition is an initializer
8065: with a subgrouping for each command option.
8066:
8067: Each subgrouping contains a string constant, that defines the option
8068: name, and a number, which contains the bits to set in
8069: @code{target_flags}. A negative number says to clear bits instead;
8070: the negative of the number is which bits to clear. The actual option
8071: name is made by appending @samp{-m} to the specified name.
8072:
8073: One of the subgroupings should have a null string. The number in
8074: this grouping is the default value for @code{target_flags}. Any
8075: target options act starting with that value.
8076:
8077: Here is an example which defines @samp{-m68000} and @samp{-m68020}
8078: with opposite meanings, and picks the latter as the default:
8079:
8080: @example
8081: #define TARGET_SWITCHES \
8082: @{ @{ "68020", 1@}, \
8083: @{ "68000", -1@}, \
8084: @{ "", 1@}@}
8085: @end example
8086:
8087: @item OVERRIDE_OPTIONS
8088: Sometimes certain combinations of command options do not make sense on
8089: a particular target machine. You can define a macro
8090: @code{OVERRIDE_OPTIONS} to take account of this. This macro, if
8091: defined, is executed once just after all the command options have been
8092: parsed.
8093: @end table
8094:
8095: @node Storage Layout, Registers, Run-time Target, Machine Macros
8096: @section Storage Layout
8097:
8098: Note that the definitions of the macros in this table which are sizes or
8099: alignments measured in bits do not need to be constant. They can be C
8100: expressions that refer to static variables, such as the @code{target_flags}.
8101: @xref{Run-time Target}.
8102:
8103: @table @code
8104: @item BITS_BIG_ENDIAN
8105: Define this macro if the most significant bit in a byte has the lowest
8106: number. This means that bit-field instructions count from the most
8107: significant bit. If the machine has no bit-field instructions, this
8108: macro is irrelevant.
8109:
1.1.1.8 root 8110: This macro does not affect the way structure fields are packed into
8111: bytes or words; that is controlled by @code{BYTES_BIG_ENDIAN}.
8112:
1.1 root 8113: @item BYTES_BIG_ENDIAN
8114: Define this macro if the most significant byte in a word has the
8115: lowest number.
8116:
8117: @item WORDS_BIG_ENDIAN
8118: Define this macro if, in a multiword object, the most significant
8119: word has the lowest number.
8120:
8121: @item BITS_PER_UNIT
8122: Number of bits in an addressable storage unit (byte); normally 8.
8123:
8124: @item BITS_PER_WORD
8125: Number of bits in a word; normally 32.
8126:
8127: @item UNITS_PER_WORD
8128: Number of storage units in a word; normally 4.
8129:
8130: @item POINTER_SIZE
8131: Width of a pointer, in bits.
8132:
8133: @item POINTER_BOUNDARY
8134: Alignment required for pointers stored in memory, in bits.
8135:
8136: @item PARM_BOUNDARY
1.1.1.7 root 8137: Normal alignment required for function parameters on the stack, in
8138: bits. All stack parameters receive least this much alignment
8139: regardless of data type. On most machines, this is the same as the
8140: size of an integer.
8141:
8142: @item MAX_PARM_BOUNDARY
8143: Largest alignment required for any stack parameters, in bits. If the
8144: data type of the parameter calls for more alignment than
8145: @code{PARM_BOUNDARY}, then it is given extra padding up to this limit.
8146:
8147: Don't define this macro if it would be equal to @code{PARM_BOUNDARY};
8148: in other words, if the alignment of a stack parameter should not
8149: depend on its data type (as is the case on most machines).
1.1 root 8150:
8151: @item STACK_BOUNDARY
8152: Define this macro if you wish to preserve a certain alignment for
8153: the stack pointer at all times. The definition is a C expression
8154: for the desired alignment (measured in bits).
8155:
8156: @item FUNCTION_BOUNDARY
8157: Alignment required for a function entry point, in bits.
8158:
8159: @item BIGGEST_ALIGNMENT
8160: Biggest alignment that any data type can require on this machine, in bits.
8161:
1.1.1.8 root 8162: @item CONSTANT_ALIGNMENT (@var{code}, @var{typealign})
8163: A C expression to compute the alignment for a constant. The argument
8164: @var{typealign} is the alignment required for the constant's data type.
8165: @var{code} is the tree code of the constant itself.
8166:
8167: If this macro is not defined, the default is to use @var{typealign}. If
8168: you do define this macro, the value must be a multiple of
8169: @var{typealign}.
8170:
8171: The purpose of defining this macro is usually to cause string constants
8172: to be word aligned so that @file{dhrystone} can be made to run faster.
8173:
1.1 root 8174: @item EMPTY_FIELD_BOUNDARY
8175: Alignment in bits to be given to a structure bit field that follows an
8176: empty field such as @code{int : 0;}.
8177:
8178: @item STRUCTURE_SIZE_BOUNDARY
8179: Number of bits which any structure or union's size must be a multiple of.
8180: Each structure or union's size is rounded up to a multiple of this.
8181:
8182: If you do not define this macro, the default is the same as
8183: @code{BITS_PER_UNIT}.
8184:
8185: @item STRICT_ALIGNMENT
8186: Define this if instructions will fail to work if given data not
8187: on the nominal alignment. If instructions will merely go slower
8188: in that case, do not define this macro.
8189:
8190: @item PCC_BITFIELD_TYPE_MATTERS
8191: Define this if you wish to imitate a certain bizarre behavior pattern
8192: of some instances of PCC: a bit field whose declared type is
8193: @code{int} has the same effect on the size and alignment of a
8194: structure as an actual @code{int} would have.
8195:
1.1.1.10 root 8196: If the macro is defined, then its definition should be a C expression;
8197: a nonzero value for the expression enables PCC-compatible behavior.
8198:
1.1 root 8199: Just what effect that is in GNU CC depends on other parameters, but on
8200: most machines it would force the structure's alignment and size to a
8201: multiple of 32 or @code{BIGGEST_ALIGNMENT} bits.
8202:
1.1.1.7 root 8203: @item MAX_FIXED_MODE_SIZE
8204: An integer expression for the largest integer machine mode that should
8205: actually be used. All integer machine modes of this size or smaller
8206: can be used for structures and unions with the appropriate sizes.
8207:
1.1 root 8208: @item CHECK_FLOAT_VALUE (@var{mode}, @var{value})
8209: A C statement to validate the value @var{value} (or type
8210: @code{double}) for mode @var{mode}. This means that you check whether
8211: @var{value} fits within the possible range of values for mode
8212: @var{mode} on this target machine. The mode @var{mode} is always
8213: @code{SFmode} or @code{DFmode}.
8214:
8215: If @var{value} is not valid, you should call @code{error} to print an
8216: error message and then assign some valid value to @var{value}.
8217: Allowing an invalid value to go through the compiler can produce
8218: incorrect assembler code which may even cause Unix assemblers to
8219: crash.
8220:
8221: This macro need not be defined if there is no work for it to do.
8222: @end table
8223:
8224: @node Registers, Register Classes, Storage Layout, Machine Macros
8225: @section Register Usage
8226:
8227: @table @code
8228: @item FIRST_PSEUDO_REGISTER
8229: Number of hardware registers known to the compiler. They receive
8230: numbers 0 through @code{FIRST_PSEUDO_REGISTER-1}; thus, the first
8231: pseudo register's number really is assigned the number
8232: @code{FIRST_PSEUDO_REGISTER}.
8233:
8234: @item FIXED_REGISTERS
8235: An initializer that says which registers are used for fixed purposes
8236: all throughout the compiled code and are therefore not available for
8237: general allocation. These would include the stack pointer, the frame
8238: pointer (except on machines where that can be used as a general
8239: register when no frame pointer is needed), the program counter on
8240: machines where that is considered one of the addressable registers,
8241: and any other numbered register with a standard use.
8242:
8243: This information is expressed as a sequence of numbers, separated by
8244: commas and surrounded by braces. The @var{n}th number is 1 if
8245: register @var{n} is fixed, 0 otherwise.
8246:
8247: The table initialized from this macro, and the table initialized by
8248: the following one, may be overridden at run time either automatically,
8249: by the actions of the macro @code{CONDITIONAL_REGISTER_USAGE}, or by
8250: the user with the command options @samp{-ffixed-@var{reg}},
8251: @samp{-fcall-used-@var{reg}} and @samp{-fcall-saved-@var{reg}}.
8252:
8253: @item CALL_USED_REGISTERS
8254: Like @code{FIXED_REGISTERS} but has 1 for each register that is
8255: clobbered (in general) by function calls as well as for fixed
8256: registers. This macro therefore identifies the registers that are not
8257: available for general allocation of values that must live across
8258: function calls.
8259:
8260: If a register has 0 in @code{CALL_USED_REGISTERS}, the compiler
8261: automatically saves it on function entry and restores it on function
8262: exit, if the register is used within the function.
8263:
1.1.1.6 root 8264: @item DEFAULT_CALLER_SAVES
1.1.1.8 root 8265: Define this macro if function calls on the target machine do not preserve
1.1.1.6 root 8266: any registers; in other words, if @code{CALL_USED_REGISTERS} has 1
8267: for all registers. This macro enables @samp{-fcaller-saves} by default.
8268: Eventually that option will be enabled by default on all machines and both
8269: the option and this macro will be eliminated.
8270:
1.1 root 8271: @item CONDITIONAL_REGISTER_USAGE
8272: Zero or more C statements that may conditionally modify two variables
8273: @code{fixed_regs} and @code{call_used_regs} (both of type @code{char
8274: []}) after they have been initialized from the two preceding macros.
8275:
8276: This is necessary in case the fixed or call-clobbered registers depend
8277: on target flags.
8278:
8279: You need not define this macro if it has no work to do.
8280:
8281: If the usage of an entire class of registers depends on the target
1.1.1.5 root 8282: flags, you may indicate this to GCC by using this macro to modify
1.1 root 8283: @code{fixed_regs} and @code{call_used_regs} to 1 for each of the
1.1.1.5 root 8284: registers in the classes which should not be used by GCC. Also define
1.1 root 8285: the macro @code{REG_CLASS_FROM_LETTER} to return @code{NO_REGS} if it
8286: is called with a letter for a class that shouldn't be used.
8287:
8288: (However, if this class is not included in @code{GENERAL_REGS} and all
8289: of the insn patterns whose constraints permit this class are
8290: controlled by target switches, then GCC will automatically avoid using
8291: these registers when the target switches are opposed to them.)
8292:
8293: @item OVERLAPPING_REGNO_P (@var{regno})
1.1.1.5 root 8294: If defined, this is a C expression whose value is nonzero if hard
8295: register number @var{regno} is an overlapping register. This means a
8296: hard register which overlaps a hard register with a different number.
8297: (Such overlap is undesirable, but occasionally it allows a machine to
8298: be supported which otherwise could not be.) This macro must return
8299: nonzero for @emph{all} the registers which overlap each other. GNU CC
8300: can use an overlapping register only in certain limited ways. It can
8301: be used for allocation within a basic block, and may be spilled for
8302: reloading; that is all.
1.1 root 8303:
8304: If this macro is not defined, it means that none of the hard registers
8305: overlap each other. This is the usual situation.
8306:
8307: @item INSN_CLOBBERS_REGNO_P (@var{insn}, @var{regno})
8308: If defined, this is a C expression whose value should be nonzero if
8309: the insn @var{insn} has the effect of mysteriously clobbering the
8310: contents of hard register number @var{regno}. By ``mysterious'' we
8311: mean that the insn's RTL expression doesn't describe such an effect.
8312:
8313: If this macro is not defined, it means that no insn clobbers registers
8314: mysteriously. This is the usual situation; all else being equal,
8315: it is best for the RTL expression to show all the activity.
8316:
8317: @item PRESERVE_DEATH_INFO_REGNO_P (@var{regno})
8318: If defined, this is a C expression whose value is nonzero if accurate
8319: @code{REG_DEAD} notes are needed for hard register number @var{regno}
8320: at the time of outputting the assembler code. When this is so, a few
8321: optimizations that take place after register allocation and could
8322: invalidate the death notes are not done when this register is
8323: involved.
8324:
1.1.1.8 root 8325: You would arrange to preserve death info for a register when some of the
8326: code in the machine description which is executed to write the assembler
8327: code looks at the death notes. This is necessary only when the actual
8328: hardware feature which GNU CC thinks of as a register is not actually a
8329: register of the usual sort. (It might, for example, be a hardware
8330: stack.)
1.1 root 8331:
8332: If this macro is not defined, it means that no death notes need to be
8333: preserved. This is the usual situation.
8334:
1.1.1.10 root 8335: @item HARD_REGNO_NREGS (@var{regno}, @var{mode})
1.1 root 8336: A C expression for the number of consecutive hard registers, starting
8337: at register number @var{regno}, required to hold a value of mode
8338: @var{mode}.
8339:
8340: On a machine where all registers are exactly one word, a suitable
8341: definition of this macro is
8342:
8343: @example
8344: #define HARD_REGNO_NREGS(REGNO, MODE) \
8345: ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
8346: / UNITS_PER_WORD))
8347: @end example
8348:
8349: @item HARD_REGNO_MODE_OK (@var{regno}, @var{mode})
8350: A C expression that is nonzero if it is permissible to store a value
8351: of mode @var{mode} in hard register number @var{regno} (or in several
8352: registers starting with that one). For a machine where all registers
8353: are equivalent, a suitable definition is
8354:
8355: @example
8356: #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
8357: @end example
8358:
1.1.1.8 root 8359: It is not necessary for this macro to check for the numbers of fixed
8360: registers, because the allocation mechanism considers them to be always
8361: occupied.
8362:
8363: On some machines, double-precision values must be kept in even/odd
8364: register pairs. The way to implement that is to define this macro
8365: to reject odd register numbers for such modes.
8366:
8367: GNU CC assumes that it can always move values between registers and
8368: (suitably addressed) memory locations. If it is impossible to move a
8369: value of a certain mode between memory and certain registers, then
8370: @code{HARD_REGNO_MODE_OK} must not allow this mode in those registers.
1.1 root 8371:
8372: Many machines have special registers for floating point arithmetic.
8373: Often people assume that floating point machine modes are allowed only
8374: in floating point registers. This is not true. Any registers that
8375: can hold integers can safely @emph{hold} a floating point machine
8376: mode, whether or not floating arithmetic can be done on it in those
8377: registers.
8378:
1.1.1.9 root 8379: On some machines, though, the converse is true: fixed-point machine
8380: modes may not go in floating registers. This is true if the floating
8381: registers normalize any value stored in them, because storing a
8382: non-floating value there would garble it. In this case,
8383: @code{HARD_REGNO_MODE_OK} should reject fixed-point machine modes in
8384: floating registers. But if the floating registers do not automatically
8385: normalize, if you can store any bit pattern in one and retrieve it
8386: unchanged without a trap, then any machine mode may go in a floating
8387: register and this macro should say so.
8388:
8389: The primary significance of special floating registers is rather that
8390: they are the registers acceptable in floating point arithmetic
8391: instructions. However, this is of no concern to
8392: @code{HARD_REGNO_MODE_OK}. You handle it by writing the proper
8393: constraints for those instructions.
8394:
8395: On some machines, the floating registers are especially slow to access,
8396: so that it is better to store a value in a stack frame than in such a
8397: register if floating point arithmetic is not being done. As long as the
8398: floating registers are not in class @code{GENERAL_REGS}, they will not
8399: be used unless some insn's constraint asks for one.
1.1 root 8400:
8401: @item MODES_TIEABLE_P (@var{mode1}, @var{mode2})
8402: A C expression that is nonzero if it is desirable to choose register
8403: allocation so as to avoid move instructions between a value of mode
8404: @var{mode1} and a value of mode @var{mode2}.
8405:
8406: If @code{HARD_REGNO_MODE_OK (@var{r}, @var{mode1})} and
8407: @code{HARD_REGNO_MODE_OK (@var{r}, @var{mode2})} are ever different
8408: for any @var{r}, then @code{MODES_TIEABLE_P (@var{mode1},
8409: @var{mode2})} must be zero.
8410:
8411: @item PC_REGNUM
8412: If the program counter has a register number, define this as that
8413: register number. Otherwise, do not define it.
8414:
8415: @item STACK_POINTER_REGNUM
8416: The register number of the stack pointer register, which must also be
8417: a fixed register according to @code{FIXED_REGISTERS}. On many
8418: machines, the hardware determines which register this is.
8419:
8420: @item FRAME_POINTER_REGNUM
8421: The register number of the frame pointer register, which is used to
8422: access automatic variables in the stack frame. On some machines, the
8423: hardware determines which register this is. On other machines, you
8424: can choose any register you wish for this purpose.
8425:
8426: @item FRAME_POINTER_REQUIRED
1.1.1.9 root 8427: A C expression which is nonzero if a function must have and use a frame
8428: pointer. This expression is evaluated twice: at the beginning of
8429: generating RTL, and in the reload pass. If its value is nonzero at
8430: either time, then the function will have a frame pointer.
8431:
8432: The expression can in principle examine the current function and decide
8433: according to the facts, but on most machines the constant 0 or the
8434: constant 1 suffices. Use 0 when the machine allows code to be generated
8435: with no frame pointer, and doing so saves some time or space. Use 1
8436: when there is no possible advantage to avoiding a frame pointer.
1.1 root 8437:
1.1.1.5 root 8438: In certain cases, the compiler does not know how to produce valid code
8439: without a frame pointer. The compiler recognizes those cases and
8440: automatically gives the function a frame pointer regardless of what
1.1 root 8441: @code{FRAME_POINTER_REQUIRED} says. You don't need to worry about
8442: them.@refill
8443:
8444: In a function that does not require a frame pointer, the frame pointer
8445: register can be allocated for ordinary usage, unless you mark it as a
8446: fixed register. See @code{FIXED_REGISTERS} for more information.
8447:
8448: @item ARG_POINTER_REGNUM
8449: The register number of the arg pointer register, which is used to
8450: access the function's argument list. On some machines, this is the
8451: same as the frame pointer register. On some machines, the hardware
8452: determines which register this is. On other machines, you can choose
8453: any register you wish for this purpose. If this is not the same
8454: register as the frame pointer register, then you must mark it as a
8455: fixed register according to @code{FIXED_REGISTERS}.
8456:
8457: @item STATIC_CHAIN_REGNUM
8458: The register number used for passing a function's static chain
8459: pointer. This is needed for languages such as Pascal and Algol where
8460: functions defined within other functions can access the local
8461: variables of the outer functions; it is not currently used because C
8462: does not provide this feature, but you must define the macro.
8463:
8464: The static chain register need not be a fixed register.
8465:
8466: @item STRUCT_VALUE_REGNUM
8467: When a function's value's mode is @code{BLKmode}, the value is not
8468: returned according to @code{FUNCTION_VALUE}. Instead, the caller
8469: passes the address of a block of memory in which the value should be
8470: stored.
8471:
8472: If this value is passed in a register, then @code{STRUCT_VALUE_REGNUM}
8473: should be the number of that register.
8474:
8475: @item STRUCT_VALUE
8476: If the structure value address is not passed in a register, define
8477: @code{STRUCT_VALUE} as an expression returning an RTX for the place
1.1.1.8 root 8478: where the address is passed. If it returns a @code{mem} RTX, the
1.1 root 8479: address is passed as an ``invisible'' first argument.
8480:
8481: @item STRUCT_VALUE_INCOMING_REGNUM
8482: On some architectures the place where the structure value address
8483: is found by the called function is not the same place that the
8484: caller put it. This can be due to register windows, or it could
8485: be because the function prologue moves it to a different place.
8486:
8487: If the incoming location of the structure value address is in a
8488: register, define this macro as the register number.
8489:
8490: @item STRUCT_VALUE_INCOMING
8491: If the incoming location is not a register, define
8492: @code{STRUCT_VALUE_INCOMING} as an expression for an RTX for where the
8493: called function should find the value. If it should find the value on
1.1.1.8 root 8494: the stack, define this to create a @code{mem} which refers to the
8495: frame pointer. If the value is a @code{mem}, the compiler assumes it
1.1 root 8496: is for an invisible first argument, and leaves space for it when
8497: finding the first real argument.
8498:
8499: @item REG_ALLOC_ORDER
8500: If defined, an initializer for a vector of integers, containing the
8501: numbers of hard registers in the order in which the GNU CC should
8502: prefer to use them (from most preferred to least).
8503:
8504: If this macro is not defined, registers are used lowest numbered first
8505: (all else being equal).
8506:
8507: One use of this macro is on the 360, where the highest numbered
8508: registers must always be saved and the save-multiple-registers
8509: instruction supports only sequences of consecutive registers. This
8510: macro is defined to cause the highest numbered allocatable registers
8511: to be used first.
8512: @end table
8513:
8514: @node Register Classes, Stack Layout, Registers, Machine Macros
8515: @section Register Classes
8516:
8517: On many machines, the numbered registers are not all equivalent.
8518: For example, certain registers may not be allowed for indexed addressing;
8519: certain registers may not be allowed in some instructions. These machine
8520: restrictions are described to the compiler using @dfn{register classes}.
8521:
8522: You define a number of register classes, giving each one a name and saying
8523: which of the registers belong to it. Then you can specify register classes
8524: that are allowed as operands to particular instruction patterns.
8525:
8526: In general, each register will belong to several classes. In fact, one
8527: class must be named @code{ALL_REGS} and contain all the registers. Another
8528: class must be named @code{NO_REGS} and contain no registers. Often the
8529: union of two classes will be another class; however, this is not required.
8530:
8531: One of the classes must be named @code{GENERAL_REGS}. There is nothing
8532: terribly special about the name, but the operand constraint letters
8533: @samp{r} and @samp{g} specify this class. If @code{GENERAL_REGS} is
8534: the same as @code{ALL_REGS}, just define it as a macro which expands
8535: to @code{ALL_REGS}.
8536:
8537: The way classes other than @code{GENERAL_REGS} are specified in operand
8538: constraints is through machine-dependent operand constraint letters.
8539: You can define such letters to correspond to various classes, then use
8540: them in operand constraints.
8541:
8542: You should define a class for the union of two classes whenever some
8543: instruction allows both classes. For example, if an instruction allows
8544: either a floating-point (coprocessor) register or a general register for a
8545: certain operand, you should define a class @code{FLOAT_OR_GENERAL_REGS}
8546: which includes both of them. Otherwise you will get suboptimal code.
8547:
8548: You must also specify certain redundant information about the register
8549: classes: for each class, which classes contain it and which ones are
8550: contained in it; for each pair of classes, the largest class contained
8551: in their union.
8552:
1.1.1.8 root 8553: When a value occupying several consecutive registers is expected in a
8554: certain class, all the registers used must belong to that class.
8555: Therefore, register classes cannot be used to enforce a requirement for
8556: a register pair to start with an even-numbered register. The way to
8557: specify this requirement is with @code{HARD_REGNO_MODE_OK}.
8558:
1.1 root 8559: Register classes used for input-operands of bitwise-and or shift
8560: instructions have a special requirement: each such class must have, for
8561: each fixed-point machine mode, a subclass whose registers can transfer that
8562: mode to or from memory. For example, on some machines, the operations for
8563: single-byte values (@code{QImode}) are limited to certain registers. When
8564: this is so, each register class that is used in a bitwise-and or shift
8565: instruction must have a subclass consisting of registers from which
8566: single-byte values can be loaded or stored. This is so that
8567: @code{PREFERRED_RELOAD_CLASS} can always have a possible value to return.
8568:
8569: @table @code
8570: @item enum reg_class
8571: An enumeral type that must be defined with all the register class names
8572: as enumeral values. @code{NO_REGS} must be first. @code{ALL_REGS}
8573: must be the last register class, followed by one more enumeral value,
8574: @code{LIM_REG_CLASSES}, which is not a register class but rather
8575: tells how many classes there are.
8576:
8577: Each register class has a number, which is the value of casting
8578: the class name to type @code{int}. The number serves as an index
8579: in many of the tables described below.
8580:
8581: @item N_REG_CLASSES
8582: The number of distinct register classes, defined as follows:
8583:
8584: @example
8585: #define N_REG_CLASSES (int) LIM_REG_CLASSES
8586: @end example
8587:
8588: @item REG_CLASS_NAMES
8589: An initializer containing the names of the register classes as C string
8590: constants. These names are used in writing some of the debugging dumps.
8591:
8592: @item REG_CLASS_CONTENTS
8593: An initializer containing the contents of the register classes, as integers
8594: which are bit masks. The @var{n}th integer specifies the contents of class
8595: @var{n}. The way the integer @var{mask} is interpreted is that
8596: register @var{r} is in the class if @code{@var{mask} & (1 << @var{r})} is 1.
8597:
8598: When the machine has more than 32 registers, an integer does not suffice.
8599: Then the integers are replaced by sub-initializers, braced groupings containing
8600: several integers. Each sub-initializer must be suitable as an initializer
8601: for the type @code{HARD_REG_SET} which is defined in @file{hard-reg-set.h}.
8602:
8603: @item REGNO_REG_CLASS (@var{regno})
8604: A C expression whose value is a register class containing hard register
8605: @var{regno}. In general there is more that one such class; choose a class
8606: which is @dfn{minimal}, meaning that no smaller class also contains the
8607: register.
8608:
8609: @item BASE_REG_CLASS
8610: A macro whose definition is the name of the class to which a valid
8611: base register must belong. A base register is one used in an address
8612: which is the register value plus a displacement.
8613:
8614: @item INDEX_REG_CLASS
8615: A macro whose definition is the name of the class to which a valid
8616: index register must belong. An index register is one used in an
8617: address where its value is either multiplied by a scale factor or
8618: added to another register (as well as added to a displacement).
8619:
8620: @item REG_CLASS_FROM_LETTER (@var{char})
8621: A C expression which defines the machine-dependent operand constraint
8622: letters for register classes. If @var{char} is such a letter, the
8623: value should be the register class corresponding to it. Otherwise,
8624: the value should be @code{NO_REGS}.
8625:
8626: @item REGNO_OK_FOR_BASE_P (@var{num})
8627: A C expression which is nonzero if register number @var{num} is
8628: suitable for use as a base register in operand addresses. It may be
8629: either a suitable hard register or a pseudo register that has been
8630: allocated such a hard register.
8631:
8632: @item REGNO_OK_FOR_INDEX_P (@var{num})
8633: A C expression which is nonzero if register number @var{num} is
8634: suitable for use as an index register in operand addresses. It may be
8635: either a suitable hard register or a pseudo register that has been
8636: allocated such a hard register.
8637:
8638: The difference between an index register and a base register is that
8639: the index register may be scaled. If an address involves the sum of
8640: two registers, neither one of them scaled, then either one may be
8641: labeled the ``base'' and the other the ``index''; but whichever
8642: labeling is used must fit the machine's constraints of which registers
8643: may serve in each capacity. The compiler will try both labelings,
8644: looking for one that is valid, and will reload one or both registers
8645: only if neither labeling works.
8646:
8647: @item PREFERRED_RELOAD_CLASS (@var{x}, @var{class})
8648: A C expression that places additional restrictions on the register class
8649: to use when it is necessary to copy value @var{x} into a register in class
8650: @var{class}. The value is a register class; perhaps @var{class}, or perhaps
8651: another, smaller class. On many machines, the definition
8652:
8653: @example
8654: #define PREFERRED_RELOAD_CLASS(X,CLASS) CLASS
8655: @end example
8656:
8657: @noindent
8658: is safe.
8659:
8660: Sometimes returning a more restrictive class makes better code. For
8661: example, on the 68000, when @var{x} is an integer constant that is in range
8662: for a @samp{moveq} instruction, the value of this macro is always
8663: @code{DATA_REGS} as long as @var{class} includes the data registers.
8664: Requiring a data register guarantees that a @samp{moveq} will be used.
8665:
1.1.1.8 root 8666: If @var{x} is a @code{const_double}, by returning @code{NO_REGS}
1.1 root 8667: you can force @var{x} into a memory constant. This is useful on
8668: certain machines where immediate floating values cannot be loaded into
8669: certain kinds of registers.
8670:
8671: In a shift instruction or a bitwise-and instruction, the mode of @var{x},
8672: the value being reloaded, may not be the same as the mode of the
8673: instruction's operand. (They will both be fixed-point modes, however.) In
8674: such a case, @var{class} may not be a safe value to return. @var{class} is
8675: certainly valid for the instruction, but it may not be valid for reloading
8676: @var{x}. This problem can occur on machines such as the 68000 and 80386
8677: where some registers can handle full-word values but cannot handle
8678: single-byte values.
8679:
8680: On such machines, this macro must examine the mode of @var{x} and return a
8681: subclass of @var{class} which can handle loads and stores of that mode. On
8682: the 68000, where address registers cannot handle @code{QImode}, if @var{x}
8683: has @code{QImode} then you must return @code{DATA_REGS}. If @var{class} is
8684: @code{ADDR_REGS}, then there is no correct value to return; but the shift
8685: and bitwise-and instructions don't use @code{ADDR_REGS}, so this fatal case
8686: never arises.
8687:
8688: @item CLASS_MAX_NREGS (@var{class}, @var{mode})
8689: A C expression for the maximum number of consecutive registers
8690: of class @var{class} needed to hold a value of mode @var{mode}.
8691:
8692: This is closely related to the macro @code{HARD_REGNO_NREGS}.
8693: In fact, the value of the macro @code{CLASS_MAX_NREGS (@var{class}, @var{mode})}
8694: should be the maximum value of @code{HARD_REGNO_NREGS (@var{regno}, @var{mode})}
8695: for all @var{regno} values in the class @var{class}.
8696:
8697: This macro helps control the handling of multiple-word values
8698: in the reload pass.
8699: @end table
8700:
8701: Two other special macros describe which constants fit which constraint
8702: letters.
8703:
8704: @table @code
8705: @item CONST_OK_FOR_LETTER_P (@var{value}, @var{c})
8706: A C expression that defines the machine-dependent operand constraint letters
8707: that specify particular ranges of integer values. If @var{c} is one
8708: of those letters, the expression should check that @var{value}, an integer,
8709: is in the appropriate range and return 1 if so, 0 otherwise. If @var{c} is
8710: not one of those letters, the value should be 0 regardless of @var{value}.
8711:
8712: @item CONST_DOUBLE_OK_FOR_LETTER_P (@var{value}, @var{c})
8713: A C expression that defines the machine-dependent operand constraint
8714: letters that specify particular ranges of floating values. If @var{c} is
8715: one of those letters, the expression should check that @var{value}, an RTX
1.1.1.8 root 8716: of code @code{const_double}, is in the appropriate range and return 1 if
1.1 root 8717: so, 0 otherwise. If @var{c} is not one of those letters, the value should
8718: be 0 regardless of @var{value}.
8719: @end table
8720:
1.1.1.12 root 8721: @node Stack Layout, Library Calls, Register Classes, Machine Macros
1.1 root 8722: @section Describing Stack Layout
8723:
8724: @table @code
8725: @item STACK_GROWS_DOWNWARD
8726: Define this macro if pushing a word onto the stack moves the stack
8727: pointer to a smaller address.
8728:
8729: When we say, ``define this macro if @dots{},'' it means that the
8730: compiler checks this macro only with @code{#ifdef} so the precise
8731: definition used does not matter.
8732:
8733: @item FRAME_GROWS_DOWNWARD
8734: Define this macro if the addresses of local variable slots are at negative
8735: offsets from the frame pointer.
8736:
8737: @item STARTING_FRAME_OFFSET
8738: Offset from the frame pointer to the first local variable slot to be allocated.
8739:
8740: If @code{FRAME_GROWS_DOWNWARD}, the next slot's offset is found by
8741: subtracting the length of the first slot from @code{STARTING_FRAME_OFFSET}.
8742: Otherwise, it is found by adding the length of the first slot to
8743: the value @code{STARTING_FRAME_OFFSET}.
8744:
8745: @item PUSH_ROUNDING (@var{npushed})
8746: A C expression that is the number of bytes actually pushed onto the
8747: stack when an instruction attempts to push @var{npushed} bytes.
8748:
8749: If the target machine does not have a push instruction, do not define
8750: this macro. That directs GNU CC to use an alternate strategy: to
8751: allocate the entire argument block and then store the arguments into
8752: it.
8753:
8754: On some machines, the definition
8755:
8756: @example
8757: #define PUSH_ROUNDING(BYTES) (BYTES)
8758: @end example
8759:
8760: @noindent
8761: will suffice. But on other machines, instructions that appear
8762: to push one byte actually push two bytes in an attempt to maintain
8763: alignment. Then the definition should be
8764:
8765: @example
8766: #define PUSH_ROUNDING(BYTES) (((BYTES) + 1) & ~1)
8767: @end example
8768:
8769: @item FIRST_PARM_OFFSET (@var{fundecl})
8770: Offset from the argument pointer register to the first argument's
8771: address. On some machines it may depend on the data type of the
8772: function. (In the next version of GNU CC, the argument will be
8773: changed to the function data type rather than its declaration.)
8774:
8775: @item FIRST_PARM_CALLER_OFFSET (@var{fundecl})
8776: Define this macro on machines where register parameters have shadow
8777: locations on the stack, at addresses below the nominal parameter.
8778: This matters because certain arguments cannot be passed on the stack.
8779: On these machines, such arguments must be stored into the shadow
8780: locations.
8781:
8782: This macro should expand into a C expression whose value is the offset
8783: of the first parameter's shadow location from the nominal stack
8784: pointer value. (That value is itself computed by adding the value of
8785: @code{STACK_POINTER_OFFSET} to the stack pointer register.)
8786:
1.1.1.9 root 8787: @item REG_PARM_STACK_SPACE
8788: Define this macro if functions should assume that stack space has been
8789: allocated for arguments even when their values are passed in
8790: registers.
8791:
8792: The actual allocation of such space would be done either by
8793: the call instruction or by the function prologue, or by
1.1.1.10 root 8794: defining @code{FIRST_PARM_CALLER_OFFSET}.
1.1.1.9 root 8795:
1.1.1.6 root 8796: @item STACK_ARGS_ADJUST (@var{size})
8797: Define this macro if the machine requires padding on the stack for
8798: certain function calls. This is padding on a per-function-call basis,
8799: not padding for individual arguments.
8800:
1.1.1.7 root 8801: The argument @var{size} will be a C variable of type @code{struct
8802: arg_data} which contains two fields, an integer named @code{constant}
8803: and an RTX named @code{var}. These together represent a size measured
8804: in bytes which is the sum of the integer and the RTX. Most of the
8805: time @code{var} is 0, which means that the size is simply the integer.
8806:
8807: The definition should be a C statement or compound statement
8808: which alters the variable supplied in whatever way you wish.
8809:
8810: Note that the value you leave in the variable @code{size} will
8811: ultimately be rounded up to a multiple of @code{STACK_BOUNDARY} bits.
8812:
8813: This macro is not fully implemented for machines which have push
8814: instructions (i.e., on which @code{PUSH_ROUNDING} is defined).
1.1.1.6 root 8815:
1.1 root 8816: @item RETURN_POPS_ARGS (@var{funtype})
8817: A C expression that should be 1 if a function pops its own arguments
8818: on returning, or 0 if the function pops no arguments and the caller
8819: must therefore pop them all after the function returns.
8820:
8821: @var{funtype} is a C variable whose value is a tree node that
8822: describes the function in question. Normally it is a node of type
8823: @code{FUNCTION_TYPE} that describes the data type of the function.
8824: From this it is possible to obtain the data types of the value and
8825: arguments (if known).
8826:
8827: When a call to a library function is being considered, @var{funtype}
8828: will contain an identifier node for the library function. Thus, if
8829: you need to distinguish among various library functions, you can do so
8830: by their names. Note that ``library function'' in this context means
8831: a function used to perform arithmetic, whose name is known specially
8832: in the compiler and was not mentioned in the C code being compiled.
8833:
8834: On the Vax, all functions always pop their arguments, so the
8835: definition of this macro is 1. On the 68000, using the standard
8836: calling convention, no functions pop their arguments, so the value of
8837: the macro is always 0 in this case. But an alternative calling
8838: convention is available in which functions that take a fixed number of
8839: arguments pop them but other functions (such as @code{printf}) pop
8840: nothing (the caller pops all). When this convention is in use,
8841: @var{funtype} is examined to determine whether a function takes a
8842: fixed number of arguments.
8843:
1.1.1.10 root 8844: When this macro returns nonzero, the macro @code{FRAME_POINTER_REQUIRED}
8845: must also return nonzero for proper operation.
8846:
1.1 root 8847: @item FUNCTION_VALUE (@var{valtype}, @var{func})
8848: A C expression to create an RTX representing the place where a
8849: function returns a value of data type @var{valtype}. @var{valtype} is
8850: a tree node representing a data type. Write @code{TYPE_MODE
8851: (@var{valtype})} to get the machine mode used to represent that type.
8852: On many machines, only the mode is relevant. (Actually, on most
8853: machines, scalar values are returned in the same place regardless of
8854: mode).@refill
8855:
8856: If the precise function being called is known, @var{func} is a tree
8857: node (@code{FUNCTION_DECL}) for it; otherwise, @var{func} is a null
8858: pointer. This makes it possible to use a different value-returning
8859: convention for specific functions when all their calls are
8860: known.@refill
8861:
8862: @item FUNCTION_OUTGOING_VALUE (@var{valtype}, @var{func})
8863: Define this macro if the target machine has ``register windows''
8864: so that the register in which a function returns its value is not
8865: the same as the one in which the caller sees the value.
8866:
8867: For such machines, @code{FUNCTION_VALUE} computes the register in
8868: which the caller will see the value, and
8869: @code{FUNCTION_OUTGOING_VALUE} should be defined in a similar fashion
8870: to tell the function where to put the value.@refill
8871:
8872: If @code{FUNCTION_OUTGOING_VALUE} is not defined,
8873: @code{FUNCTION_VALUE} serves both purposes.@refill
8874:
1.1.1.7 root 8875: @item RETURN_IN_MEMORY (@var{type})
8876: A C expression which can inhibit the returning of certain function
8877: values in registers, based on the type of value. A nonzero value says
8878: to return the function value in memory, just as large structures are
8879: always returned. Here @var{type} will be a C expression of type
8880: @code{tree}, representing the data type of the value.
8881:
8882: Note that values of mode @code{BLKmode} are returned in memory
8883: regardless of this macro. Also, the option @samp{-fpcc-struct-return}
8884: takes effect regardless of this macro. On most systems, it is
8885: possible to leave the macro undefined; this causes a default
8886: definition to be used, whose value is the constant 0.
8887:
1.1 root 8888: @item LIBCALL_VALUE (@var{mode})
8889: A C expression to create an RTX representing the place where a library
8890: function returns a value of mode @var{mode}. If the precise function
8891: being called is known, @var{func} is a tree node
8892: (@code{FUNCTION_DECL}) for it; otherwise, @var{func} is a null
8893: pointer. This makes it possible to use a different value-returning
8894: convention for specific functions when all their calls are
8895: known.@refill
8896:
8897: Note that ``library function'' in this context means a compiler
8898: support routine, used to perform arithmetic, whose name is known
8899: specially by the compiler and was not mentioned in the C code being
8900: compiled.
8901:
8902: @item FUNCTION_VALUE_REGNO_P (@var{regno})
8903: A C expression that is nonzero if @var{regno} is the number of a hard
8904: register in which the values of called function may come back.
8905:
8906: A register whose use for returning values is limited to serving as the
8907: second of a pair (for a value of type @code{double}, say) need not be
8908: recognized by this macro. So for most machines, this definition
8909: suffices:
8910:
8911: @example
8912: #define FUNCTION_VALUE_REGNO_P(N) ((N) == 0)
8913: @end example
8914:
8915: If the machine has register windows, so that the caller and the called
8916: function use different registers for the return value, this macro
8917: should recognize only the caller's register numbers.
8918:
8919: @item FUNCTION_ARG (@var{cum}, @var{mode}, @var{type}, @var{named})
8920: A C expression that controls whether a function argument is passed
8921: in a register, and which register.
8922:
8923: The arguments are @var{cum}, which summarizes all the previous
8924: arguments; @var{mode}, the machine mode of the argument; @var{type},
8925: the data type of the argument as a tree node or 0 if that is not known
8926: (which happens for C support library functions); and @var{named},
8927: which is 1 for an ordinary argument and 0 for nameless arguments that
1.1.1.8 root 8928: correspond to @samp{@dots{}} in the called function's prototype.
1.1 root 8929:
1.1.1.8 root 8930: The value of the expression should either be a @code{reg} RTX for the
1.1 root 8931: hard register in which to pass the argument, or zero to pass the
8932: argument on the stack.
8933:
8934: For the Vax and 68000, where normally all arguments are pushed, zero
8935: suffices as a definition.
8936:
1.1.1.8 root 8937: The usual way to make the ANSI library @file{stdarg.h} work on a machine
8938: where some arguments are usually passed in registers, is to cause
8939: nameless arguments to be passed on the stack instead. This is done
8940: by making @code{FUNCTION_ARG} return 0 whenever @var{named} is 0.
8941:
1.1 root 8942: @item FUNCTION_INCOMING_ARG (@var{cum}, @var{mode}, @var{type}, @var{named})
8943: Define this macro if the target machine has ``register windows'', so
8944: that the register in which a function sees an arguments is not
8945: necessarily the same as the one in which the caller passed the
8946: argument.
8947:
8948: For such machines, @code{FUNCTION_ARG} computes the register in which
8949: the caller passes the value, and @code{FUNCTION_INCOMING_ARG} should
8950: be defined in a similar fashion to tell the function being called
8951: where the arguments will arrive.
8952:
8953: If @code{FUNCTION_INCOMING_ARG} is not defined, @code{FUNCTION_ARG}
8954: serves both purposes.@refill
8955:
8956: @item FUNCTION_ARG_PARTIAL_NREGS (@var{cum}, @var{mode}, @var{type}, @var{named})
8957: A C expression for the number of words, at the beginning of an
8958: argument, must be put in registers. The value must be zero for
8959: arguments that are passed entirely in registers or that are entirely
8960: pushed on the stack.
8961:
8962: On some machines, certain arguments must be passed partially in
8963: registers and partially in memory. On these machines, typically the
8964: first @var{n} words of arguments are passed in registers, and the rest
8965: on the stack. If a multi-word argument (a @code{double} or a
8966: structure) crosses that boundary, its first few words must be passed
8967: in registers and the rest must be pushed. This macro tells the
8968: compiler when this occurs, and how many of the words should go in
8969: registers.
8970:
8971: @code{FUNCTION_ARG} for these arguments should return the first
8972: register to be used by the caller for this argument; likewise
8973: @code{FUNCTION_INCOMING_ARG}, for the called function.
8974:
8975: @item CUMULATIVE_ARGS
8976: A C type for declaring a variable that is used as the first argument
8977: of @code{FUNCTION_ARG} and other related values. For some target
8978: machines, the type @code{int} suffices and can hold the number of
8979: bytes of argument so far.
8980:
8981: @item INIT_CUMULATIVE_ARGS (@var{cum}, @var{fntype})
8982: A C statement (sans semicolon) for initializing the variable @var{cum}
8983: for the state at the beginning of the argument list. The variable has
8984: type @code{CUMULATIVE_ARGS}. The value of @var{fntype} is the tree node
8985: for the data type of the function which will receive the args, or 0
8986: if the args are to a compiler support library function.
8987:
8988: @item FUNCTION_ARG_ADVANCE (@var{cum}, @var{mode}, @var{type}, @var{named})
1.1.1.7 root 8989: A C statement (sans semicolon) to update the summarizer variable
8990: @var{cum} to advance past an argument in the argument list. The
8991: values @var{mode}, @var{type} and @var{named} describe that argument.
8992: Once this is done, the variable @var{cum} is suitable for analyzing
8993: the @emph{following} argument with @code{FUNCTION_ARG}, etc.@refill
1.1 root 8994:
8995: @item FUNCTION_ARG_REGNO_P (@var{regno})
8996: A C expression that is nonzero if @var{regno} is the number of a hard
8997: register in which function arguments are sometimes passed. This does
8998: @emph{not} include implicit arguments such as the static chain and
8999: the structure-value address. On many machines, no registers can be
9000: used for this purpose since all function arguments are pushed on the
9001: stack.
9002:
9003: @item FUNCTION_ARG_PADDING (@var{mode}, @var{size})
9004: If defined, a C expression which determines whether, and in which direction,
9005: to pad out an argument with extra space. The value should be of type
9006: @code{enum direction}: either @code{upward} to pad above the argument,
9007: @code{downward} to pad below, or @code{none} to inhibit padding.
9008:
9009: The argument @var{size} is an RTX which describes the size of the
9010: argument, in bytes. It should be used only if @var{mode} is
9011: @code{BLKmode}. Otherwise, @var{size} is 0.
9012:
9013: This macro does not control the @emph{amount} of padding; that is
9014: always just enough to reach the next multiple of @code{PARM_BOUNDARY}.
9015:
9016: This macro has a default definition which is right for most systems.
9017: For little-endian machines, the default is to pad upward. For
9018: big-endian machines, the default is to pad downward for an argument of
9019: constant size shorter than an @code{int}, and upward otherwise.
9020:
9021: @item FUNCTION_PROLOGUE (@var{file}, @var{size})
9022: A C compound statement that outputs the assembler code for entry to a
9023: function. The prologue is responsible for setting up the stack frame,
9024: initializing the frame pointer register, saving registers that must be
9025: saved, and allocating @var{size} additional bytes of storage for the
9026: local variables. @var{size} is an integer. @var{file} is a stdio
9027: stream to which the assembler code should be output.
9028:
9029: The label for the beginning of the function need not be output by this
9030: macro. That has already been done when the macro is run.
9031:
9032: To determine which registers to save, the macro can refer to the array
9033: @code{regs_ever_live}: element @var{r} is nonzero if hard register
9034: @var{r} is used anywhere within the function. This implies the
9035: function prologue should save register @var{r}, but not if it is one
9036: of the call-used registers.
9037:
9038: On machines where functions may or may not have frame-pointers, the
9039: function entry code must vary accordingly; it must set up the frame
9040: pointer if one is wanted, and not otherwise. To determine whether a
9041: frame pointer is in wanted, the macro can refer to the variable
9042: @code{frame_pointer_needed}. The variable's value will be 1 at run
9043: time in a function that needs a frame pointer.
9044:
1.1.1.10 root 9045: On machines where an argument may be passed partly in registers and
9046: partly in memory, this macro must examine the variable
1.1.1.8 root 9047: @code{current_function_pretend_args_size}, and allocate that many bytes
9048: of uninitialized space on the stack just underneath the first argument
9049: arriving on the stack. (This may not be at the very end of the stack,
9050: if the calling sequence has pushed anything else since pushing the stack
9051: arguments. But usually, on such machines, nothing else has been pushed
9052: yet, because the function prologue itself does all the pushing.)
9053:
1.1 root 9054: @item FUNCTION_PROFILER (@var{file}, @var{labelno})
9055: A C statement or compound statement to output to @var{file} some
9056: assembler code to call the profiling subroutine @code{mcount}.
9057: Before calling, the assembler code must load the address of a
9058: counter variable into a register where @code{mcount} expects to
9059: find the address. The name of this variable is @samp{LP} followed
9060: by the number @var{labelno}, so you would generate the name using
9061: @samp{LP%d} in a @code{fprintf}.
9062:
9063: The details of how the address should be passed to @code{mcount} are
9064: determined by your operating system environment, not by GNU CC. To
9065: figure them out, compile a small program for profiling using the
9066: system's installed C compiler and look at the assembler code that
9067: results.
9068:
1.1.1.6 root 9069: @item FUNCTION_BLOCK_PROFILER (@var{file}, @var{labelno})
9070: A C statement or compound statement to output to @var{file} some
9071: assembler code to initialize basic-block profiling for the current
9072: object module. This code should call the subroutine
9073: @code{__bb_init_func} once per object module, passing it as its sole
9074: argument the address of a block allocated in the object module.
9075:
9076: The name of the block is a local symbol made with this statement:
9077:
9078: @example
9079: ASM_GENERATE_INTERNAL_LABEL (@var{buffer}, "LPBX", 0);
9080: @end example
9081:
9082: Of course, since you are writing the definition of
9083: @code{ASM_GENERATE_INTERNAL_LABEL} as well as that of this macro, you
9084: can take a short cut in the definition of this macro and use the name
9085: that you know will result.
9086:
9087: The first word of this block is a flag which will be nonzero if the
9088: object module has already been initialized. So test this word first,
9089: and do not call @code{__bb_init_func} if the flag is nonzero.
9090:
9091: @item BLOCK_PROFILER (@var{file}, @var{blockno})
9092: A C statement or compound statement to increment the count associated
9093: with the basic block number @var{blockno}. Basic blocks are numbered
9094: separately from zero within each compilation. The count associated
9095: with block number @var{blockno} is at index @var{blockno} in a vector
9096: of words; the name of this array is a local symbol made with this
9097: statement:
9098:
9099: @example
9100: ASM_GENERATE_INTERNAL_LABEL (@var{buffer}, "LPBX", 2);
9101: @end example
9102:
9103: Of course, since you are writing the definition of
9104: @code{ASM_GENERATE_INTERNAL_LABEL} as well as that of this macro, you
9105: can take a short cut in the definition of this macro and use the name
9106: that you know will result.
9107:
1.1.1.10 root 9108: @item EXIT_IGNORE_STACK
1.1 root 9109: Define this macro as a C expression that is nonzero if the return
9110: instruction or the function epilogue ignores the value of the stack
9111: pointer; in other words, if it is safe to delete an instruction to
9112: adjust the stack pointer before a return from the function.
9113:
1.1.1.8 root 9114: Note that this macro's value is relevant only for functions for which
9115: frame pointers are maintained. It is never safe to delete a final
9116: stack adjustment in a function that has no frame pointer, and the
1.1.1.10 root 9117: compiler knows this regardless of @code{EXIT_IGNORE_STACK}.
1.1 root 9118:
9119: @item FUNCTION_EPILOGUE (@var{file}, @var{size})
9120: A C compound statement that outputs the assembler code for exit from a
9121: function. The epilogue is responsible for restoring the saved
9122: registers and stack pointer to their values when the function was
9123: called, and returning control to the caller. This macro takes the
9124: same arguments as the macro @code{FUNCTION_PROLOGUE}, and the
9125: registers to restore are determined from @code{regs_ever_live} and
9126: @code{CALL_USED_REGISTERS} in the same way.
9127:
9128: On some machines, there is a single instruction that does all the work
9129: of returning from the function. On these machines, give that
9130: instruction the name @samp{return} and do not define the macro
9131: @code{FUNCTION_EPILOGUE} at all.
9132:
9133: Do not define a pattern named @samp{return} if you want the
9134: @code{FUNCTION_EPILOGUE} to be used. If you want the target switches
9135: to control whether return instructions or epilogues are used, define a
9136: @samp{return} pattern with a validity condition that tests the target
9137: switches appropriately. If the @samp{return} pattern's validity
9138: condition is false, epilogues will be used.
9139:
9140: On machines where functions may or may not have frame-pointers, the
9141: function exit code must vary accordingly. Sometimes the code for
9142: these two cases is completely different. To determine whether a frame
9143: pointer is in wanted, the macro can refer to the variable
9144: @code{frame_pointer_needed}. The variable's value will be 1 at run
9145: time in a function that needs a frame pointer.
9146:
9147: On some machines, some functions pop their arguments on exit while
9148: others leave that for the caller to do. For example, the 68020 when
9149: given @samp{-mrtd} pops arguments in functions that take a fixed
9150: number of arguments.
9151:
9152: Your definition of the macro @code{RETURN_POPS_ARGS} decides which
9153: functions pop their own arguments. @code{FUNCTION_EPILOGUE} needs to
9154: know what was decided. The variable @code{current_function_pops_args}
9155: is nonzero if the function should pop its own arguments. If so, use
9156: the variable @code{current_function_args_size} as the number of bytes
9157: to pop.
9158:
9159: @item FIX_FRAME_POINTER_ADDRESS (@var{addr}, @var{depth})
9160: A C compound statement to alter a memory address that uses the frame
9161: pointer register so that it uses the stack pointer register instead.
9162: This must be done in the instructions that load parameter values into
9163: registers, when the reload pass determines that a frame pointer is not
9164: necessary for the function. @var{addr} will be a C variable name, and
9165: the updated address should be stored in that variable. @var{depth}
9166: will be the current depth of stack temporaries (number of bytes of
9167: arguments currently pushed). The change in offset between a
9168: frame-pointer-relative address and a stack-pointer-relative address
9169: must include @var{depth}.
9170:
9171: Even if your machine description specifies there will always be a
9172: frame pointer in the frame pointer register, you must still define
9173: @code{FIX_FRAME_POINTER_ADDRESS}, but the definition will never be
9174: executed at run time, so it may be empty.
1.1.1.8 root 9175:
9176: @item LONGJMP_RESTORE_FROM_STACK
9177: Define this macro if the @code{longjmp} function restores registers
9178: from the stack frames, rather than from those saved specifically by
9179: @code{setjmp}. Certain quantities must not be kept in registers
9180: across a call to @code{setjmp} on such machines.
1.1 root 9181: @end table
9182:
1.1.1.12 root 9183: @node Library Calls, Addressing Modes, Stack Layout, Machine Macros
9184: @section Implicit Use of Library Routines
1.1 root 9185:
9186: @table @code
1.1.1.5 root 9187: @item MULSI3_LIBCALL
9188: A C string constant giving the name of the function to call for
9189: multiplication of one signed full-word by another. If you do not
9190: define this macro, the default name is used, which is @code{__mulsi3},
9191: a function defined in @file{gnulib}.
9192:
9193: @item UMULSI3_LIBCALL
9194: A C string constant giving the name of the function to call for
9195: multiplication of one unsigned full-word by another. If you do not
9196: define this macro, the default name is used, which is
9197: @code{__umulsi3}, a function defined in @file{gnulib}.
9198:
9199: @item DIVSI3_LIBCALL
9200: A C string constant giving the name of the function to call for
9201: division of one signed full-word by another. If you do not define
9202: this macro, the default name is used, which is @code{__divsi3}, a
9203: function defined in @file{gnulib}.
9204:
1.1 root 9205: @item UDIVSI3_LIBCALL
9206: A C string constant giving the name of the function to call for
1.1.1.5 root 9207: division of one unsigned full-word by another. If you do not define
9208: this macro, the default name is used, which is @code{__udivsi3}, a
9209: function defined in @file{gnulib}.
9210:
9211: @item MODSI3_LIBCALL
9212: A C string constant giving the name of the function to call for the
9213: remainder in division of one signed full-word by another. If you do
9214: not define this macro, the default name is used, which is
9215: @code{__modsi3}, a function defined in @file{gnulib}.
1.1 root 9216:
9217: @item UMODSI3_LIBCALL
9218: A C string constant giving the name of the function to call for the
1.1.1.5 root 9219: remainder in division of one unsigned full-word by another. If you do
9220: not define this macro, the default name is used, which is
9221: @code{__umodsi3}, a function defined in @file{gnulib}.
1.1 root 9222:
9223: @item TARGET_MEM_FUNCTIONS
9224: Define this macro if GNU CC should generate calls to the System V
9225: (and ANSI C) library functions @code{memcpy} and @code{memset}
9226: rather than the BSD functions @code{bcopy} and @code{bzero}.
1.1.1.12 root 9227:
9228: @item GNULIB_NEEDS_DOUBLE
9229: Define this macro if only @code{float} arguments cannot be passed to
9230: library routines (so they must be converted to @code{double}). This
9231: macro affects both how library calls are generated and how the library
9232: routines in @file{gnulib.c} accept their arguments. It is useful on
9233: machines where floating and fixed point arguments are passed
9234: differently, such as the i860.
1.1 root 9235: @end table
9236:
1.1.1.12 root 9237: @node Addressing Modes, Delayed Branch, Library Calls, Machine Macros
1.1 root 9238: @section Addressing Modes
9239:
9240: @table @code
9241: @item HAVE_POST_INCREMENT
9242: Define this macro if the machine supports post-increment addressing.
9243:
9244: @item HAVE_PRE_INCREMENT
9245: @itemx HAVE_POST_DECREMENT
9246: @itemx HAVE_PRE_DECREMENT
9247: Similar for other kinds of addressing.
9248:
9249: @item CONSTANT_ADDRESS_P (@var{x})
9250: A C expression that is 1 if the RTX @var{x} is a constant whose value
9251: is an integer. This includes integers whose values are not explicitly
1.1.1.8 root 9252: known, such as @code{symbol_ref} and @code{label_ref} expressions and
9253: @code{const} arithmetic expressions.
1.1 root 9254:
9255: On most machines, this can be defined as @code{CONSTANT_P (@var{x})},
9256: but a few machines are more restrictive in which constant addresses
9257: are supported.
9258:
9259: @item MAX_REGS_PER_ADDRESS
9260: A number, the maximum number of registers that can appear in a valid
1.1.1.10 root 9261: memory address. Note that it is up to you to specify a value equal to
9262: the maximum number that @code{go_if_legitimate_address} would ever
9263: accept.
1.1 root 9264:
9265: @item GO_IF_LEGITIMATE_ADDRESS (@var{mode}, @var{x}, @var{label})
9266: A C compound statement with a conditional @code{goto @var{label};}
9267: executed if @var{x} (an RTX) is a legitimate memory address on the
9268: target machine for a memory operand of mode @var{mode}.
9269:
9270: It usually pays to define several simpler macros to serve as
9271: subroutines for this one. Otherwise it may be too complicated to
9272: understand.
9273:
9274: This macro must exist in two variants: a strict variant and a
9275: non-strict one. The strict variant is used in the reload pass. It
9276: must be defined so that any pseudo-register that has not been
9277: allocated a hard register is considered a memory reference. In
9278: contexts where some kind of register is required, a pseudo-register
9279: with no hard register must be rejected.
9280:
9281: The non-strict variant is used in other passes. It must be defined to
9282: accept all pseudo-registers in every context where some kind of
9283: register is required.
9284:
9285: Compiler source files that want to use the strict variant of this
9286: macro define the macro @code{REG_OK_STRICT}. You should use an
9287: @code{#ifdef REG_OK_STRICT} conditional to define the strict variant
9288: in that case and the non-strict variant otherwise.
9289:
9290: Typically among the subroutines used to define
9291: @code{GO_IF_LEGITIMATE_ADDRESS} are subroutines to check for
9292: acceptable registers for various purposes (one for base registers, one
9293: for index registers, and so on). Then only these subroutine macros
9294: need have two variants; the higher levels of macros may be the same
9295: whether strict or not.@refill
9296:
1.1.1.8 root 9297: Normally, constant addresses which are the sum of a @code{symbol_ref}
9298: and an integer are stored inside a @code{const} RTX to mark them as
9299: constant. Therefore, there is no need to recognize such sums as
9300: legitimate addresses.
9301:
9302: Usually @code{PRINT_OPERAND_ADDRESS} is not prepared to handle constant
9303: sums that are not marked with @code{const}. It assumes that a naked
9304: @code{plus} indicates indexing. If so, then you @emph{must} reject such
9305: naked constant sums as illegitimate addresses, so that none of them will
9306: be given to @code{PRINT_OPERAND_ADDRESS}.@refill
9307:
1.1 root 9308: @item REG_OK_FOR_BASE_P (@var{x})
1.1.1.5 root 9309: A C expression that is nonzero if @var{x} (assumed to be a @code{reg}
1.1 root 9310: RTX) is valid for use as a base register. For hard registers, it
9311: should always accept those which the hardware permits and reject the
9312: others. Whether the macro accepts or rejects pseudo registers must be
9313: controlled by @code{REG_OK_STRICT} as described above. This usually
9314: requires two variant definitions, of which @code{REG_OK_STRICT}
9315: controls the one actually used.
9316:
9317: @item REG_OK_FOR_INDEX_P (@var{x})
1.1.1.5 root 9318: A C expression that is nonzero if @var{x} (assumed to be a @code{reg}
1.1 root 9319: RTX) is valid for use as an index register.
9320:
9321: The difference between an index register and a base register is that
9322: the index register may be scaled. If an address involves the sum of
9323: two registers, neither one of them scaled, then either one may be
9324: labeled the ``base'' and the other the ``index''; but whichever
9325: labeling is used must fit the machine's constraints of which registers
9326: may serve in each capacity. The compiler will try both labelings,
9327: looking for one that is valid, and will reload one or both registers
9328: only if neither labeling works.
9329:
9330: @item LEGITIMIZE_ADDRESS (@var{x}, @var{oldx}, @var{mode}, @var{win})
9331: A C compound statement that attempts to replace @var{x} with a valid
9332: memory address for an operand of mode @var{mode}. @var{win} will be a
9333: C statement label elsewhere in the code; the macro definition may use
9334:
9335: @example
9336: GO_IF_LEGITIMATE_ADDRESS (@var{mode}, @var{x}, @var{win});
9337: @end example
9338:
9339: @noindent
9340: to avoid further processing if the address has become legitimate.
9341:
9342: @var{x} will always be the result of a call to @code{break_out_memory_refs},
9343: and @var{oldx} will be the operand that was given to that function to produce
9344: @var{x}.
9345:
9346: The code generated by this macro should not alter the substructure of
9347: @var{x}. If it transforms @var{x} into a more legitimate form, it
9348: should assign @var{x} (which will always be a C variable) a new value.
9349:
9350: It is not necessary for this macro to come up with a legitimate
9351: address. The compiler has standard ways of doing so in all cases. In
9352: fact, it is safe for this macro to do nothing. But often a
9353: machine-dependent strategy can generate better code.
9354:
9355: @item GO_IF_MODE_DEPENDENT_ADDRESS (@var{addr}, @var{label})
9356: A C statement or compound statement with a conditional @code{goto
9357: @var{label};} executed if memory address @var{x} (an RTX) can have
9358: different meanings depending on the machine mode of the memory
9359: reference it is used for.
9360:
9361: Autoincrement and autodecrement addresses typically have mode-dependent
9362: effects because the amount of the increment or decrement is the size
9363: of the operand being addressed. Some machines have other mode-dependent
9364: addresses. Many RISC machines have no mode-dependent addresses.
9365:
9366: You may assume that @var{addr} is a valid address for the machine.
9367:
9368: @item LEGITIMATE_CONSTANT_P (@var{x})
9369: A C expression that is nonzero if @var{x} is a legitimate constant for
9370: an immediate operand on the target machine. You can assume that
1.1.1.8 root 9371: either @var{x} is a @code{const_double} or it satisfies
1.1 root 9372: @code{CONSTANT_P}, so you need not check these things. In fact,
9373: @samp{1} is a suitable definition for this macro on machines where any
1.1.1.8 root 9374: @code{const_double} is valid and anything @code{CONSTANT_P} is valid.@refill
9375: @end table
9376:
9377: @node Delayed Branch, Condition Code, Addressing Modes, Machine Macros
9378: @section Parameters for Delayed Branch Optimization
9379:
9380: @table @code
9381: @item HAVE_DELAYED_BRANCH
9382: Define this macro if the target machine has delayed branches, that is,
9383: a branch does not take effect immediately, and the actual branch
9384: instruction may be followed by one or more instructions that will be
9385: issued before the PC is actually changed.
9386:
9387: If defined, this allows a special scheduling pass to be run after the
9388: second jump optimization to attempt to reorder instructions to exploit
9389: this. Defining this macro also requires the definition of certain
9390: other macros described below.
9391:
9392: @item DBR_SLOTS_AFTER (@var{insn})
9393: This macro must be defined if @code{HAVE_DELAYED_BRANCH} is defined.
9394: Its definition should be a C expression returning the number of
9395: available delay slots following the instruction(s) output by the
9396: pattern for @var{insn}. The definition of ``slot'' is
9397: machine-dependent, and may denote instructions, bytes, or whatever.
9398:
9399: @item DBR_INSN_SLOTS (@var{insn})
9400: This macro must be defined if @code{HAVE_DELAYED_BRANCH} is defined.
9401: It should be a C expression returning the number of slots (typically
9402: the number of machine instructions) consumed by @var{insn}.
9403:
9404: You may assume that @var{insn} is truly an insn, not a note, label,
9405: barrier, dispatch table, @code{use}, or @code{clobber}.
9406:
9407: @item DBR_INSN_ELIGIBLE_P (@var{insn}, @var{dinsn})
9408: A C expression whose value is non-zero if it is legitimate to put
9409: @var{insn} in the delay slot following @var{dinsn}.
9410:
9411: You do not need to take account of data flow considerations in the
9412: definition of this macro, because the delayed branch optimizer always
9413: does that. This macro is needed only when certain insns may not be
9414: placed in certain delay slots for reasons not evident from the RTL
9415: expressions themselves. If there are no such problems, you don't need
9416: to define this macro.
9417:
9418: You may assume that @var{insn} is truly an insn, not a note, label,
9419: barrier, dispatch table, @code{use}, or @code{clobber}. You may
9420: assume that @var{dinsn} is a jump insn with a delay slot.
9421:
9422: @item DBR_OUTPUT_SEQEND(@var{file})
9423: A C statement, to be executed after all slot-filler instructions have
9424: been output. If necessary, call @code{dbr_sequence_length} to
9425: determine the number of slots filled in a sequence (zero if not
9426: currently outputting a sequence), to decide how many no-ops to output,
9427: or whatever.
9428:
9429: Don't define this macro if it has nothing to do, but it is helpful in
9430: reading assembly output if the extent of the delay sequence is made
9431: explicit (e.g. with white space).
9432:
9433: Note that output routines for instructions with delay slots must be
9434: prepared to deal with not being output as part of a sequence (i.e.
9435: when the scheduling pass is not run, or when no slot fillers could be
9436: found.) The variable @code{final_sequence} is null when not
9437: processing a sequence, otherwise it contains the @code{sequence} rtx
9438: being output.
1.1 root 9439: @end table
9440:
1.1.1.9 root 9441: @node Condition Code, Cross-compilation, Delayed Branch, Machine Macros
1.1.1.8 root 9442: @section Condition Code Information
9443:
9444: The file @file{conditions.h} defines a variable @code{cc_status} to
9445: describe how the condition code was computed (in case the interpretation of
9446: the condition code depends on the instruction that it was set by). This
9447: variable contains the RTL expressions on which the condition code is
9448: currently based, and several standard flags.
9449:
9450: Sometimes additional machine-specific flags must be defined in the machine
9451: description header file. It can also add additional machine-specific
9452: information by defining @code{CC_STATUS_MDEP}.
9453:
9454: @table @code
9455: @item CC_STATUS_MDEP
9456: C code for a data type which is used for declaring the @code{mdep}
9457: component of @code{cc_status}. It defaults to @code{int}.
9458:
9459: @item CC_STATUS_MDEP_INIT
1.1.1.9 root 9460: A C expression to initialize the @code{mdep} field to ``empty''.
9461: The default definition does nothing, since most machines don't use
9462: the field anyway. If you want to use the field, you should probably
9463: define this macro to initialize it.
1.1.1.8 root 9464:
9465: @item NOTICE_UPDATE_CC (@var{exp}, @var{insn})
9466: A C compound statement to set the components of @code{cc_status}
9467: appropriately for an insn @var{insn} whose body is @var{exp}. It is
9468: this macro's responsibility to recognize insns that set the condition
9469: code as a byproduct of other activity as well as those that explicitly
9470: set @code{(cc0)}.
9471:
9472: If there are insn that do not set the condition code but do alter
9473: other machine registers, this macro must check to see whether they
9474: invalidate the expressions that the condition code is recorded as
9475: reflecting. For example, on the 68000, insns that store in address
9476: registers do not set the condition code, which means that usually
9477: @code{NOTICE_UPDATE_CC} can leave @code{cc_status} unaltered for such
9478: insns. But suppose that the previous insn set the condition code
9479: based on location @samp{a4@@(102)} and the current insn stores a new
9480: value in @samp{a4}. Although the condition code is not changed by
9481: this, it will no longer be true that it reflects the contents of
9482: @samp{a4@@(102)}. Therefore, @code{NOTICE_UPDATE_CC} must alter
9483: @code{cc_status} in this case to say that nothing is known about the
9484: condition code value.
9485:
9486: The definition of @code{NOTICE_UPDATE_CC} must be prepared to deal
9487: with the results of peephole optimization: insns whose patterns are
9488: @code{parallel} RTXs containing various @code{reg}, @code{mem} or
9489: constants which are just the operands. The RTL structure of these
9490: insns is not sufficient to indicate what the insns actually do. What
9491: @code{NOTICE_UPDATE_CC} should do when it sees one is just to run
9492: @code{CC_STATUS_INIT}.
9493: @end table
9494:
9495: @node Cross-compilation, Misc, Condition Code, Machine Macros
1.1.1.5 root 9496: @section Cross Compilation and Floating-Point Format
9497:
1.1.1.9 root 9498: While all modern machines use 2's complement representation for integers,
1.1.1.5 root 9499: there are a variety of representations for floating point numbers. This
9500: means that in a cross-compiler the representation of floating point numbers
9501: in the compiled program may be different from that used in the machine
9502: doing the compilation.
9503:
9504: Because different representation systems may offer different amounts of
9505: range and precision, the cross compiler cannot safely use the host
9506: machine's floating point arithmetic. Therefore, floating point constants
9507: must be represented in the target machine's format. This means that the
9508: cross compiler cannot use @code{atof} to parse a floating point constant;
9509: it must have its own special routine to use instead. Also, constant
9510: folding must emulate the target machine's arithmetic (or must not be done
9511: at all).
9512:
9513: The macros in the following table should be defined only if you are cross
9514: compiling between different floating point formats.
9515:
9516: Otherwise, don't define them. Then default definitions will be set up which
9517: use @code{double} as the data type, @code{==} to test for equality, etc.
9518:
9519: You don't need to worry about how many times you use an operand of any
9520: of these macros. The compiler never uses operands which have side effects.
9521:
9522: @table @code
9523: @item REAL_VALUE_TYPE
9524: A macro for the C data type to be used to hold a floating point value
9525: in the target machine's format. Typically this would be a
9526: @code{struct} containing an array of @code{int}.
9527:
9528: @item REAL_VALUES_EQUAL (@var{x}, @var{y})
9529: A macro for a C expression which compares for equality the two values,
9530: @var{x} and @var{y}, both of type @code{REAL_VALUE_TYPE}.
9531:
9532: @item REAL_VALUES_LESS (@var{x}, @var{y})
9533: A macro for a C expression which tests whether @var{x} is less than
9534: @var{y}, both values being of type @code{REAL_VALUE_TYPE} and
9535: interpreted as floating point numbers in the target machine's
9536: representation.
9537:
9538: @item REAL_VALUE_LDEXP (@var{x}, @var{scale})
9539: A macro for a C expression which performs the standard library
9540: function @code{ldexp}, but using the target machine's floating point
9541: representation. Both @var{x} and the value of the expression have
9542: type @code{REAL_VALUE_TYPE}. The second argument, @var{scale}, is an
9543: integer.
9544:
9545: @item REAL_VALUE_ATOF (@var{string})
9546: A macro for a C expression which converts @var{string}, an expression
9547: of type @code{char *}, into a floating point number in the target
9548: machine's representation. The value has type @code{REAL_VALUE_TYPE}.
9549: @end table
9550:
9551: Define the following additional macros if you want to make floating
9552: point constant folding work while cross compiling. If you don't
9553: define them, cross compilation is still possible, but constant folding
9554: will not happen for floating point values.
9555:
9556: @table @code
9557: @item REAL_ARITHMETIC (@var{output}, @var{code}, @var{x}, @var{y})
9558: A macro for a C statement which calculates an arithmetic operation of
9559: the two floating point values @var{x} and @var{y}, both of type
9560: @code{REAL_VALUE_TYPE} in the target machine's representation, to
9561: produce a result of the same type and representation which is stored
9562: in @var{output} (which will be a variable).
9563:
9564: The operation to be performed is specified by @var{code}, a tree code
9565: which will always be one of the following: @code{PLUS_EXPR},
9566: @code{MINUS_EXPR}, @code{MULT_EXPR}, @code{RDIV_EXPR},
9567: @code{MAX_EXPR}, @code{MIN_EXPR}.@refill
9568:
9569: The expansion of this macro is responsible for checking for overflow.
9570: If overflow happens, the macro expansion should execute the statement
9571: @code{return 0;}, which indicates the inability to perform the
9572: arithmetic operation requested.
9573:
9574: @item REAL_VALUE_NEGATE (@var{x})
9575: A macro for a C expression which returns the negative of the floating
9576: point value @var{x}. Both @var{x} and the value of the expression
9577: have type @code{REAL_VALUE_TYPE} and are in the target machine's
9578: floating point representation.
9579:
9580: There is no way for this macro to report overflow, since overflow
9581: can't happen in the negation operation.
9582:
9583: @item REAL_VALUE_TO_INT (@var{low}, @var{high}, @var{x})
9584: A macro for a C expression which converts a floating point value
9585: @var{x} into a double-precision integer which is then stored into
9586: @var{low} and @var{high}, two variables of type @var{int}.
9587:
9588: @item REAL_VALUE_FROM_INT (@var{x}, @var{low}, @var{high})
9589: A macro for a C expression which converts a double-precision integer
9590: found in @var{low} and @var{high}, two variables of type @var{int},
9591: into a floating point value which is then stored into @var{x}.
9592: @end table
9593:
1.1.1.8 root 9594: @node Misc, Assembler Format, Cross-compilation, Machine Macros
1.1 root 9595: @section Miscellaneous Parameters
9596:
9597: @table @code
9598: @item CASE_VECTOR_MODE
9599: An alias for a machine mode name. This is the machine mode that
9600: elements of a jump-table should have.
9601:
9602: @item CASE_VECTOR_PC_RELATIVE
9603: Define this macro if jump-tables should contain relative addresses.
9604:
9605: @item CASE_DROPS_THROUGH
9606: Define this if control falls through a @code{case} insn when the index
9607: value is out of range. This means the specified default-label is
9608: actually ignored by the @code{case} insn proper.
9609:
9610: @item IMPLICIT_FIX_EXPR
9611: An alias for a tree code that should be used by default for conversion
9612: of floating point values to fixed point. Normally,
9613: @code{FIX_ROUND_EXPR} is used.@refill
9614:
9615: @item FIXUNS_TRUNC_LIKE_FIX_TRUNC
9616: Define this macro if the same instructions that convert a floating
9617: point number to a signed fixed point number also convert validly to an
9618: unsigned one.
9619:
9620: @item EASY_DIV_EXPR
9621: An alias for a tree code that is the easiest kind of division to
9622: compile code for in the general case. It may be
9623: @code{TRUNC_DIV_EXPR}, @code{FLOOR_DIV_EXPR}, @code{CEIL_DIV_EXPR} or
9624: @code{ROUND_DIV_EXPR}. These four division operators differ in how
9625: they round the result to an integer. @code{EASY_DIV_EXPR} is used
9626: when it is permissible to use any of those kinds of division and the
9627: choice should be made on the basis of efficiency.@refill
9628:
9629: @item DEFAULT_SIGNED_CHAR
9630: An expression whose value is 1 or 0, according to whether the type
9631: @code{char} should be signed or unsigned by default. The user can
9632: always override this default with the options @samp{-fsigned-char}
9633: and @samp{-funsigned-char}.
9634:
9635: @item SCCS_DIRECTIVE
9636: Define this if the preprocessor should ignore @code{#sccs} directives
9637: and print no error message.
9638:
1.1.1.7 root 9639: @item HAVE_VPRINTF
9640: Define this if the library function @code{vprintf} is available on your
9641: system.
1.1 root 9642:
9643: @item MOVE_MAX
9644: The maximum number of bytes that a single instruction can move quickly
9645: from memory to memory.
9646:
9647: @item INT_TYPE_SIZE
9648: A C expression for the size in bits of the type @code{int} on the
1.1.1.8 root 9649: target machine. If you don't define this, the default is one word.
9650:
9651: @item SHORT_TYPE_SIZE
9652: A C expression for the size in bits of the type @code{short} on the
9653: target machine. If you don't define this, the default is half a word.
9654: (If this would be less than one storage unit, it is rounded up to one
9655: unit.)
9656:
9657: @item LONG_TYPE_SIZE
9658: A C expression for the size in bits of the type @code{long} on the
9659: target machine. If you don't define this, the default is one word.
9660:
9661: @item LONG_LONG_TYPE_SIZE
9662: A C expression for the size in bits of the type @code{long long} on the
9663: target machine. If you don't define this, the default is two
9664: words.
9665:
9666: @item CHAR_TYPE_SIZE
9667: A C expression for the size in bits of the type @code{char} on the
9668: target machine. If you don't define this, the default is one quarter
9669: of a word. (If this would be less than one storage unit, it is rounded up
9670: to one unit.)
9671:
9672: @item FLOAT_TYPE_SIZE
9673: A C expression for the size in bits of the type @code{float} on the
9674: target machine. If you don't define this, the default is one word.
9675:
9676: @item DOUBLE_TYPE_SIZE
9677: A C expression for the size in bits of the type @code{double} on the
9678: target machine. If you don't define this, the default is two
9679: words.
9680:
9681: @item LONG_DOUBLE_TYPE_SIZE
9682: A C expression for the size in bits of the type @code{long double} on
9683: the target machine. If you don't define this, the default is two
9684: words.
1.1 root 9685:
9686: @item SLOW_BYTE_ACCESS
9687: Define this macro as a C expression which is nonzero if accessing less
9688: than a word of memory (i.e. a @code{char} or a @code{short}) is slow
9689: (requires more than one instruction).
9690:
9691: @item SLOW_ZERO_EXTEND
9692: Define this macro if zero-extension (of a @code{char} or @code{short}
9693: to an @code{int}) can be done faster if the destination is a register
9694: that is known to be zero.
9695:
9696: If you define this macro, you must have instruction patterns that
9697: recognize RTL structures like this:
9698:
9699: @example
9700: (set (strict-low-part (subreg:QI (reg:SI @dots{}) 0)) @dots{})
9701: @end example
9702:
9703: @noindent
9704: and likewise for @code{HImode}.
9705:
9706: @item SHIFT_COUNT_TRUNCATED
9707: Define this macro if shift instructions ignore all but the lowest few
9708: bits of the shift count. It implies that a sign-extend or zero-extend
9709: instruction for the shift count can be omitted.
9710:
9711: @item TRULY_NOOP_TRUNCATION (@var{outprec}, @var{inprec})
9712: A C expression which is nonzero if on this machine it is safe to
9713: ``convert'' an integer of @var{inprec} bits to one of @var{outprec}
9714: bits (where @var{outprec} is smaller than @var{inprec}) by merely
9715: operating on it as if it had only @var{outprec} bits.
9716:
9717: On many machines, this expression can be 1.
9718:
9719: @item NO_FUNCTION_CSE
9720: Define this macro if it is as good or better to call a constant
9721: function address than to call an address kept in a register.
9722:
9723: @item PROMOTE_PROTOTYPES
9724: Define this macro if an argument declared as @code{char} or
9725: @code{short} in a prototype should actually be passed as an
9726: @code{int}. In addition to avoiding errors in certain cases of
9727: mismatch, it also makes for better code on certain machines.
9728:
9729: @item STORE_FLAG_VALUE
9730: A C expression for the value stored by a store-flag instruction
9731: (@code{s@var{cond}}) when the condition is true. This is usually 1 or
1.1.1.9 root 9732: -1; it is required to be an odd number or a negative number.
1.1 root 9733:
9734: Do not define @code{STORE_FLAG_VALUE} if the machine has no store-flag
9735: instructions.
9736:
9737: @item Pmode
9738: An alias for the machine mode for pointers. Normally the definition
9739: can be
9740:
9741: @example
9742: #define Pmode SImode
9743: @end example
9744:
9745: @item FUNCTION_MODE
9746: An alias for the machine mode used for memory references to functions
1.1.1.8 root 9747: being called, in @code{call} RTL expressions. On most machines this
1.1 root 9748: should be @code{QImode}.
9749:
9750: @item INSN_MACHINE_INFO
9751: This macro should expand into a C structure type to use for the
9752: machine-dependent info field specified with the optional last argument
1.1.1.8 root 9753: in @code{define_insn} and @code{define_peephole} patterns. For example,
9754: it might expand into @code{struct machine_info}; then it would be up
1.1 root 9755: to you to define this structure in the @file{tm.h} file.
9756:
9757: You do not need to define this macro if you do not write the optional
9758: last argument in any of the patterns in the machine description.
9759:
1.1.1.8 root 9760: @item DEFAULT_MACHINE_INFO
9761: This macro should expand into a C initializer to use to initialize
9762: the machine-dependent info for one insn pattern. It is used for patterns
9763: that do not specify the machine-dependent info.
9764:
9765: If you do not define this macro, zero is used.
9766:
1.1 root 9767: @item CONST_COSTS (@var{x}, @var{code})
9768: A part of a C @code{switch} statement that describes the relative
9769: costs of constant RTL expressions. It must contain @code{case} labels
1.1.1.8 root 9770: for expression codes @code{const_int}, @code{const}, @code{symbol_ref}, @code{label_ref}
9771: and @code{const_double}. Each case must ultimately reach a
1.1 root 9772: @code{return} statement to return the relative cost of the use of that
9773: kind of constant value in an expression. The cost may depend on the
9774: precise value of the constant, which is available for examination in
9775: @var{x}.
9776:
9777: @var{code} is the expression code---redundant, since it can be
9778: obtained with @code{GET_CODE (@var{x})}.
9779:
9780: @item DOLLARS_IN_IDENTIFIERS
9781: Define this to be nonzero if the character @samp{$} should be allowed
9782: by default in identifier names.
9783: @end table
9784:
1.1.1.8 root 9785: @node Assembler Format,, Misc, Machine Macros
1.1 root 9786: @section Output of Assembler Code
9787:
9788: @table @code
9789: @item ASM_SPEC
9790: A C string constant that tells the GNU CC driver program options to
9791: pass to the assembler. It can also specify how to translate options
9792: you give to GNU CC into options for GNU CC to pass to the assembler.
9793: See the file @file{tm-sun3.h} for an example of this.
9794:
9795: Do not define this macro if it does not need to do anything.
9796:
9797: @item LINK_SPEC
9798: A C string constant that tells the GNU CC driver program options to
9799: pass to the linker. It can also specify how to translate options you
9800: give to GNU CC into options for GNU CC to pass to the linker.
9801:
9802: Do not define this macro if it does not need to do anything.
9803:
9804: @item LIB_SPEC
9805: Another C string constant used much like @code{LINK_SPEC}. The difference
9806: between the two is that @code{LIBS_SPEC} is used at the end of the
9807: command given to the linker.
9808:
9809: If this macro is not defined, a default is provided that
9810: loads the standard C library from the usual place. See @file{gcc.c}.
9811:
1.1.1.12 root 9812: @item LIBG_SPEC
9813: Another C string constant used much like @code{LINK_SPEC}.
9814: This controls whether to link @file{libg.a} when debugging.
9815: Some systems expect this; others do not have any @file{libg.a}.
9816:
9817: If this macro is not defined, a default is provided that loads the
9818: @file{libg.a} provided @samp{-g} is specified. See @file{gcc.c}.
9819:
1.1 root 9820: @item STARTFILE_SPEC
9821: Another C string constant used much like @code{LINK_SPEC}. The
9822: difference between the two is that @code{STARTFILE_SPEC} is used at
9823: the very beginning of the command given to the linker.
9824:
9825: If this macro is not defined, a default is provided that loads the
9826: standard C startup file from the usual place. See @file{gcc.c}.
9827:
1.1.1.7 root 9828: @item STANDARD_EXEC_PREFIX
9829: Define this macro as a C string constant if you wish to override the
9830: standard choice of @file{/usr/local/lib/gcc-} as the default prefix to
9831: try when searching for the executable files of the compiler.
9832:
9833: The prefix specified by the @samp{-B} option, if any, is tried before
9834: the default prefix. After the default prefix, if the executable is
9835: not found that way, @file{/usr/lib/gcc-} is tried next; then the
9836: directories in your search path for shell commands are searched.
9837:
1.1.1.4 root 9838: @item STANDARD_STARTFILE_PREFIX
9839: Define this macro as a C string constant if you wish to override the
1.1.1.7 root 9840: standard choice of @file{/usr/local/lib/} as the default prefix to try
9841: when searching for startup files such as @file{crt0.o}.
9842:
9843: In this search, all the prefixes tried for executable files are tried
9844: first. Then comes the default startfile prefix specified by this
9845: macro, followed by the prefixes @file{/lib/} and @file{/usr/lib/} as
9846: last resorts.
1.1.1.4 root 9847:
1.1 root 9848: @item ASM_FILE_START (@var{stream})
9849: A C expression which outputs to the stdio stream @var{stream}
9850: some appropriate text to go at the start of an assembler file.
9851:
9852: Normally this macro is defined to output a line containing
9853: @samp{#NO_APP}, which is a comment that has no effect on most
9854: assemblers but tells the GNU assembler that it can save time by not
9855: checking for certain assembler constructs.
9856:
9857: On systems that use SDB, it is necessary to output certain commands;
9858: see @file{tm-attasm.h}.
9859:
1.1.1.8 root 9860: @item ASM_FILE_END (@var{stream})
9861: A C expression which outputs to the stdio stream @var{stream}
9862: some appropriate text to go at the end of an assembler file.
9863:
9864: If this macro is not defined, the default is to output nothing
9865: special at the end of the file. Most systems don't require any
9866: definition.
9867:
9868: On systems that use SDB, it is necessary to output certain commands;
9869: see @file{tm-attasm.h}.
9870:
9871: @item ASM_IDENTIFY_GCC (@var{file})
9872: A C statement to output assembler commands which will identify
9873: the object file as having been compiled with GNU CC (or another
9874: GNU compiler).
9875:
9876: If you don't define this macro, the string @samp{gcc_compiled.:}
9877: is output. This string is calculated to define a symbol which,
9878: on BSD systems, will never be defined for any other reason.
9879: GDB checks for the presence of this symbol when reading the
9880: symbol table of an executable.
9881:
9882: On non-BSD systems, you must arrange communication with GDB in
9883: some other fashion. If GDB is not used on your system, you can
9884: define this macro with an empty body.
9885:
1.1 root 9886: @item ASM_APP_ON
9887: A C string constant for text to be output before each @code{asm}
9888: statement or group of consecutive ones. Normally this is
9889: @code{"#APP"}, which is a comment that has no effect on most
9890: assemblers but tells the GNU assembler that it must check the lines
9891: that follow for all valid assembler constructs.
9892:
9893: @item ASM_APP_OFF
9894: A C string constant for text to be output after each @code{asm}
9895: statement or group of consecutive ones. Normally this is
9896: @code{"#NO_APP"}, which tells the GNU assembler to resume making the
9897: time-saving assumptions that are valid for ordinary compiler output.
9898:
9899: @item TEXT_SECTION_ASM_OP
9900: A C string constant for the assembler operation that should precede
9901: instructions and read-only data. Normally @code{".text"} is right.
9902:
9903: @item DATA_SECTION_ASM_OP
9904: A C string constant for the assembler operation to identify the
9905: following data as writable initialized data. Normally @code{".data"}
9906: is right.
9907:
1.1.1.8 root 9908: @item EXTRA_SECTIONS
9909: A list of names for sections other than the standard two, which are
9910: @code{in_text} and @code{in_data}. You need not define this macro
9911: on a system with no other sections (that GCC needs to use).
9912:
9913: @item EXTRA_SECTION_FUNCTIONS
9914: One or more functions to be defined in @file{varasm.c}. These
9915: functions should do jobs analogous to those of @code{text_section} and
9916: @code{data_section}, for your additional sections. Do not define this
9917: macro if you do not define @code{EXTRA_SECTIONS}.
9918:
9919: @item SELECT_SECTION (@var{exp})
9920: A C statement or statements to switch to the appropriate section for
9921: output of @var{exp}. You can assume that @var{exp} is either a
9922: @code{VAR_DECL} node or a constant of some sort. Select the section
9923: by calling @code{text_section} or one of the alternatives for other
9924: sections.
9925:
9926: Do not define this macro if you use only the standard two sections
9927: and put all read-only variables and constants in the text section.
9928:
9929: @item SELECT_RTX_SECTION (@var{mode}, @var{rtx})
9930: A C statement or statements to switch to the appropriate section for
9931: output of @var{rtx} in mode @var{mode}. You can assume that @var{rtx}
9932: is some kind of constant in RTL. The argument @var{mode} is redundant
9933: except in the case of a @code{const_int} rtx. Select the section by
9934: calling @code{text_section} or one of the alternatives for other
9935: sections.
9936:
9937: Do not define this macro if you use only the standard two sections and
9938: put all constants in the text section.
9939:
1.1 root 9940: @item REGISTER_NAMES
9941: A C initializer containing the assembler's names for the machine
9942: registers, each one as a C string constant. This is what translates
9943: register numbers in the compiler into assembler language.
9944:
9945: @item DBX_REGISTER_NUMBER (@var{regno})
9946: A C expression that returns the DBX register number for the compiler
9947: register number @var{regno}. In simple cases, the value of this
9948: expression may be @var{regno} itself. But sometimes there are some
9949: registers that the compiler knows about and DBX does not, or vice
9950: versa. In such cases, some register may need to have one number in
9951: the compiler and another for DBX.
9952:
9953: @item DBX_DEBUGGING_INFO
9954: Define this macro if GNU CC should produce debugging output for DBX
9955: in response to the @samp{-g} option.
9956:
9957: @item SDB_DEBUGGING_INFO
9958: Define this macro if GNU CC should produce debugging output for SDB
9959: in response to the @samp{-g} option.
9960:
9961: @item PUT_SDB_@var{op}
9962: Define these macros to override the assembler syntax for the special
9963: SDB assembler directives. See @file{sdbout.c} for a list of these
9964: macros and their arguments. If the standard syntax is used, you need
9965: not define them yourself.
9966:
9967: @item SDB_GENERATE_FAKE
9968: Define this macro to override the usual method of constructing a dummy
9969: name for anonymous structure and union types. See @file{sdbout.c} for
1.1.1.9 root 9970: more information.
1.1 root 9971:
9972: @item DBX_NO_XREFS
9973: Define this macro if DBX on your system does not support the construct
9974: @samp{xs@var{tagname}}. On some systems, this construct is used to
9975: describe a forward reference to a structure named @var{tagname}.
9976: On other systems, this construct is not supported at all.
9977:
9978: @item DBX_CONTIN_LENGTH
9979: A symbol name in DBX-format debugging information is normally
9980: continued (split into two separate @code{.stabs} directives) when it
9981: exceeds a certain length (by default, 80 characters). On some
9982: operating systems, DBX requires this splitting; on others, splitting
9983: must not be done. You can inhibit splitting by defining this macro
9984: with the value zero. You can override the default splitting-length by
9985: defining this macro as an expression for the length you desire.
9986:
9987: @item DBX_CONTIN_CHAR
9988: Normally continuation is indicated by adding a @samp{\} character to
9989: the end of a @code{.stabs} string when a continuation follows. To use
9990: a different character instead, define this macro as a character
9991: constant for the character you want to use. Do not define this macro
9992: if backslash is correct for your system.
9993:
1.1.1.8 root 9994: @item DBX_STATIC_STAB_DATA_SECTION
9995: Define this macro if it is necessary to go to the data section before
9996: outputting the @samp{.stabs} pseudo-op for a non-global static
9997: variable.
9998:
1.1 root 9999: @item ASM_OUTPUT_LABEL (@var{stream}, @var{name})
10000: A C statement (sans semicolon) to output to the stdio stream
1.1.1.8 root 10001: @var{stream} the assembler definition of a label named @var{name}.
10002: Use the expression @code{assemble_name (@var{stream}, @var{name})} to
10003: output the name itself; before and after that, output the additional
1.1 root 10004: assembler syntax for defining the name, and a newline.
10005:
10006: @item ASM_DECLARE_FUNCTION_NAME (@var{stream}, @var{name}, @var{decl})
10007: A C statement (sans semicolon) to output to the stdio stream
10008: @var{stream} any text necessary for declaring the name @var{name} of a
10009: function which is being defined. This macro is responsible for
10010: outputting the label definition (perhaps using
10011: @code{ASM_OUTPUT_LABEL}). The argument @var{decl} is the
10012: @code{FUNCTION_DECL} tree node representing the function.
10013:
10014: If this macro is not defined, then the function name is defined in the
10015: usual manner as a label (by means of @code{ASM_OUTPUT_LABEL}).
10016:
10017: @item ASM_GLOBALIZE_LABEL (@var{stream}, @var{name})
10018: A C statement (sans semicolon) to output to the stdio stream
10019: @var{stream} some commands that will make the label @var{name} global;
10020: that is, available for reference from other files. Use the expression
10021: @code{assemble_name (@var{stream}, @var{name})} to output the name
10022: itself; before and after that, output the additional assembler syntax
10023: for making that name global, and a newline.
10024:
1.1.1.8 root 10025: @item ASM_OUTPUT_EXTERNAL (@var{stream}, @var{decl}, @var{name})
1.1 root 10026: A C statement (sans semicolon) to output to the stdio stream
10027: @var{stream} any text necessary for declaring the name of an external
10028: symbol named @var{name} which is referenced in this compilation but
10029: not defined. The value of @var{decl} is the tree node for the
10030: declaration.
10031:
10032: This macro need not be defined if it does not need to output anything.
10033: The GNU assembler and most Unix assemblers don't require anything.
10034:
10035: @item ASM_OUTPUT_LABELREF (@var{stream}, @var{name})
1.1.1.8 root 10036: A C statement to output to the stdio stream @var{stream} a reference
10037: in assembler syntax to a label named @var{name}. The character
10038: @samp{_} should be added to the front of the name, if that is
10039: customary on your operating system, as it is in most Berkeley Unix
10040: systems. This macro is used in @code{assemble_name}.
1.1 root 10041:
10042: @item ASM_GENERATE_INTERNAL_LABEL (@var{string}, @var{prefix}, @var{num})
1.1.1.8 root 10043: A C statement to store into the string @var{string} a label whose name
10044: is made from the string @var{prefix} and the number @var{num}.
1.1 root 10045:
10046: This string, when output subsequently by @code{ASM_OUTPUT_LABELREF},
10047: should produce the same output that @code{ASM_OUTPUT_INTERNAL_LABEL}
10048: would produce with the same @var{prefix} and @var{num}.
10049:
10050: @item ASM_OUTPUT_INTERNAL_LABEL (@var{stream}, @var{prefix}, @var{num})
10051: A C statement to output to the stdio stream @var{stream} a label whose
10052: name is made from the string @var{prefix} and the number @var{num}.
10053: These labels are used for internal purposes, and there is no reason
10054: for them to appear in the symbol table of the object file. On many
10055: systems, the letter @samp{L} at the beginning of a label has this
10056: effect. The usual definition of this macro is as follows:
10057:
10058: @example
10059: fprintf (@var{stream}, "L%s%d:\n", @var{prefix}, @var{num})
10060: @end example
10061:
10062: @item ASM_OUTPUT_CASE_LABEL (@var{stream}, @var{prefix}, @var{num}, @var{table})
10063: Define this if the label before a jump-table needs to be output
10064: specially. The first three arguments are the same as for
10065: @code{ASM_OUTPUT_INTERNAL_LABEL}; the fourth argument is the
1.1.1.8 root 10066: jump-table which follows (a @code{jump_insn} containing an
10067: @code{addr_vec} or @code{addr_diff_vec}).
1.1 root 10068:
10069: This feature is used on system V to output a @code{swbeg} statement
10070: for the table.
10071:
10072: If this macro is not defined, these labels are output with
10073: @code{ASM_OUTPUT_INTERNAL_LABEL}.
10074:
10075: @item ASM_OUTPUT_CASE_END (@var{stream}, @var{num}, @var{table})
1.1.1.8 root 10076: Define this if something special must be output at the end of a
10077: jump-table. The definition should be a C statement to be executed
10078: after the assembler code for the table is written. It should write
10079: the appropriate code to stdio stream @var{stream}. The argument
10080: @var{table} is the jump-table insn, and @var{num} is the label-number
10081: of the preceding label.
1.1 root 10082:
10083: If this macro is not defined, nothing special is output at the end of
10084: the jump-table.
10085:
1.1.1.4 root 10086: @item ASM_OUTPUT_ALIGN_CODE (@var{file})
10087: A C expression to output text to align the location counter in the way
10088: that is desirable at a point in the code that is reached only by
10089: jumping.
10090:
10091: This macro need not be defined if you don't want any special alignment
10092: to be done at such a time. Most machine descriptions do not currently
10093: define the macro.
10094:
1.1 root 10095: @item ASM_FORMAT_PRIVATE_NAME (@var{outvar}, @var{name}, @var{number})
10096: A C expression to assign to @var{outvar} (which is a variable of type
10097: @code{char *}) a newly allocated string made from the string
10098: @var{name} and the number @var{number}, with some suitable punctuation
10099: added. Use @code{alloca} to get space for the string.
10100:
10101: This string will be used as the argument to @code{ASM_OUTPUT_LABELREF}
10102: to produce an assembler label for an internal static variable whose
10103: name is @var{name}. Therefore, the string must be such as to result
10104: in valid assembler code. The argument @var{number} is different each
10105: time this macro is executed; it prevents conflicts between
10106: similarly-named internal static variables in different scopes.
10107:
10108: Ideally this string should not be a valid C identifier, to prevent any
10109: conflict with the user's own symbols. Most assemblers allow periods
10110: or percent signs in assembler symbols; putting at least one of these
10111: between the name and the number will suffice.
10112:
10113: @item ASM_OUTPUT_REG_PUSH (@var{stream}, @var{regno})
10114: A C expression to output to @var{stream} some assembler code
10115: which will push hard register number @var{regno} onto the stack.
10116: The code need not be optimal, since this macro is used only when
10117: profiling.
10118:
10119: @item ASM_OUTPUT_REG_POP (@var{stream}, @var{regno})
10120: A C expression to output to @var{stream} some assembler code
10121: which will pop hard register number @var{regno} off of the stack.
10122: The code need not be optimal, since this macro is used only when
10123: profiling.
10124:
10125: @item ASM_OUTPUT_ADDR_DIFF_ELT (@var{stream}, @var{value}, @var{rel})
10126: This macro should be provided on machines where the addresses
10127: in a dispatch table are relative to the table's own address.
10128:
10129: The definition should be a C statement to output to the stdio stream
10130: @var{stream} an assembler pseudo-instruction to generate a difference
10131: between two labels. @var{value} and @var{rel} are the numbers of two
10132: internal labels. The definitions of these labels are output using
10133: @code{ASM_OUTPUT_INTERNAL_LABEL}, and they must be printed in the same
10134: way here. For example,
10135:
10136: @example
10137: fprintf (@var{stream}, "\t.word L%d-L%d\n",
10138: @var{value}, @var{rel})
10139: @end example
10140:
10141: @item ASM_OUTPUT_ADDR_VEC_ELT (@var{stream}, @var{value})
10142: This macro should be provided on machines where the addresses
10143: in a dispatch table are absolute.
10144:
10145: The definition should be a C statement to output to the stdio stream
10146: @var{stream} an assembler pseudo-instruction to generate a reference to
10147: a label. @var{value} is the number of an internal label whose
10148: definition is output using @code{ASM_OUTPUT_INTERNAL_LABEL}.
10149: For example,
10150:
10151: @example
10152: fprintf (@var{stream}, "\t.word L%d\n", @var{value})
10153: @end example
10154:
10155: @item ASM_OUTPUT_DOUBLE (@var{stream}, @var{value})
10156: A C statement to output to the stdio stream @var{stream} an assembler
10157: instruction to assemble a @code{double} constant whose value is
10158: @var{value}. @var{value} will be a C expression of type
10159: @code{double}.
10160:
10161: @item ASM_OUTPUT_FLOAT (@var{stream}, @var{value})
10162: A C statement to output to the stdio stream @var{stream} an assembler
10163: instruction to assemble a @code{float} constant whose value is
10164: @var{value}. @var{value} will be a C expression of type @code{float}.
10165:
10166: @item ASM_OUTPUT_INT (@var{stream}, @var{exp})
10167: @itemx ASM_OUTPUT_SHORT (@var{stream}, @var{exp})
10168: @itemx ASM_OUTPUT_CHAR (@var{stream}, @var{exp})
10169: A C statement to output to the stdio stream @var{stream} an assembler
10170: instruction to assemble a @code{int}, @code{short} or @code{char}
1.1.1.10 root 10171: constant whose value is @var{value}. The argument @var{exp} will be an
10172: RTL expression which represents a constant value. Use
10173: @samp{output_addr_const (@var{stream}, @var{exp})} to output this value
10174: as an assembler expression.@refill
1.1 root 10175:
1.1.1.8 root 10176: @item ASM_OUTPUT_DOUBLE_INT (@var{stream}, @var{exp})
10177: A C statement to output to the stdio stream @var{stream} an assembler
10178: instruction to assemble a @code{long long} constant whose value is
10179: @var{exp}. The argument @var{exp} will be an RTL expression which
10180: represents a constant value. It may be a @code{const_double} RTX,
10181: or it may be an ordinary single-precision constant. In the latter
10182: case, you should zero-extend it.
10183:
1.1 root 10184: @item ASM_OUTPUT_BYTE (@var{stream}, @var{value})
10185: A C statement to output to the stdio stream @var{stream} an assembler
10186: instruction to assemble a single byte containing the number @var{value}.
10187:
10188: @item ASM_OUTPUT_ASCII (@var{stream}, @var{ptr}, @var{len})
10189: A C statement to output to the stdio stream @var{stream} an assembler
10190: instruction to assemble a string constant containing the @var{len}
10191: bytes at @var{ptr}. @var{ptr} will be a C expression of type
10192: @code{char *} and @var{len} a C expression of type @code{int}.
10193:
10194: If the assembler has a @code{.ascii} pseudo-op as found in the
10195: Berkeley Unix assembler, do not define the macro
10196: @code{ASM_OUTPUT_ASCII}.
10197:
10198: @item ASM_OUTPUT_SKIP (@var{stream}, @var{nbytes})
10199: A C statement to output to the stdio stream @var{stream} an assembler
10200: instruction to advance the location counter by @var{nbytes} bytes.
10201: @var{nbytes} will be a C expression of type @code{int}.
10202:
10203: @item ASM_OUTPUT_ALIGN (@var{stream}, @var{power})
10204: A C statement to output to the stdio stream @var{stream} an assembler
10205: instruction to advance the location counter to a multiple of 2 to the
10206: @var{power} bytes. @var{power} will be a C expression of type @code{int}.
10207:
1.1.1.7 root 10208: @item ASM_OUTPUT_COMMON (@var{stream}, @var{name}, @var{size}, @var{rounded})
1.1 root 10209: A C statement (sans semicolon) to output to the stdio stream
1.1.1.7 root 10210: @var{stream} the assembler definition of a common-label named
10211: @var{name} whose size is @var{size} bytes. The variable @var{rounded}
10212: is the size rounded up to whatever alignment the caller wants.
10213:
10214: Use the expression @code{assemble_name (@var{stream}, @var{name})} to
10215: output the name itself; before and after that, output the additional
10216: assembler syntax for defining the name, and a newline.
1.1 root 10217:
10218: This macro controls how the assembler definitions of uninitialized
10219: global variables are output.
10220:
1.1.1.7 root 10221: @item ASM_OUTPUT_LOCAL (@var{stream}, @var{name}, @var{size}, @var{rounded})
1.1 root 10222: A C statement (sans semicolon) to output to the stdio stream
10223: @var{stream} the assembler definition of a local-common-label named
1.1.1.7 root 10224: @var{name} whose size is @var{size} bytes. The variable @var{rounded}
10225: is the size rounded up to whatever alignment the caller wants.
10226:
10227: Use the expression @code{assemble_name (@var{stream}, @var{name})} to
10228: output the name itself; before and after that, output the additional
10229: assembler syntax for defining the name, and a newline.
1.1 root 10230:
10231: This macro controls how the assembler definitions of uninitialized
10232: static variables are output.
10233:
1.1.1.8 root 10234: @item ASM_OUTPUT_SOURCE_FILENAME (@var{stream}, @var{name})
10235: A C statment to output DBX or SDB debugging information which indicates
10236: that filename @var{name} is the current source file to the stdio stream
10237: @var{stream}.
10238:
10239: This macro need not be defined if the standard form of debugging
10240: information for the debugger in use is appropriate.
10241:
1.1 root 10242: @item ASM_OUTPUT_SOURCE_LINE (@var{stream}, @var{line})
10243: A C statment to output DBX or SDB debugging information before code
10244: for line number @var{line} of the current source file to the
10245: stdio stream @var{stream}.
10246:
10247: This macro need not be defined if the standard form of debugging
10248: information for the debugger in use is appropriate.
10249:
10250: @item ASM_OUTPUT_IDENT (@var{stream}, @var{string})
10251: A C statement to output something to the assembler file to handle a
10252: @samp{#ident} directive containing the text @var{string}. If this
1.1.1.7 root 10253: macro is not defined, nothing is output for a @samp{#ident} directive.
1.1 root 10254:
10255: @item TARGET_BELL
10256: A C constant expression for the integer value for escape sequence
10257: @samp{\a}.
10258:
10259: @item TARGET_BS
10260: @itemx TARGET_TAB
10261: @itemx TARGET_NEWLINE
10262: C constant expressions for the integer values for escape sequences
10263: @samp{\b}, @samp{\t} and @samp{\n}.
10264:
10265: @item TARGET_VT
10266: @itemx TARGET_FF
10267: @itemx TARGET_CR
10268: C constant expressions for the integer values for escape sequences
10269: @samp{\v}, @samp{\f} and @samp{\r}.
10270:
10271: @item ASM_OUTPUT_OPCODE (@var{stream}, @var{ptr})
10272: Define this macro if you are using an unusual assembler that
10273: requires different names for the machine instructions.
10274:
10275: The definition is a C statement or statements which output an
10276: assembler instruction opcode to the stdio stream @var{stream}. The
10277: macro-operand @var{ptr} is a variable of type @code{char *} which
10278: points to the opcode name in its ``internal'' form---the form that is
10279: written in the machine description. The definition should output the
10280: opcode name to @var{stream}, performing any translation you desire, and
10281: increment the variable @var{ptr} to point at the end of the opcode
10282: so that it will not be output twice.
10283:
10284: In fact, your macro definition may process less than the entire opcode
10285: name, or more than the opcode name; but if you want to process text
10286: that includes @samp{%}-sequences to substitute operands, you must take
10287: care of the substitution yourself. Just be sure to increment
10288: @var{ptr} over whatever text should not be output normally.
10289:
1.1.1.8 root 10290: If you need to look at the operand values, they can be found as the
10291: elements of @code{recog_operand}.
10292:
1.1 root 10293: If the macro definition does nothing, the instruction is output
10294: in the usual way.
10295:
10296: @item FINAL_PRESCAN_INSN (@var{insn}, @var{opvec}, @var{noperands})
10297: If defined, a C statement to be executed just prior to the output of
10298: assembler code for @var{insn}, to modify the extracted operands so
10299: they will be output differently.
10300:
10301: Here the argument @var{opvec} is the vector containing the operands
10302: extracted from @var{insn}, and @var{noperands} is the number of
10303: elements of the vector which contain meaningful data for this insn.
10304: The contents of this vector are what will be used to convert the insn
10305: template into assembler code, so you can change the assembler output
10306: by changing the contents of the vector.
10307:
10308: This macro is useful when various assembler syntaxes share a single
10309: file of instruction patterns; by defining this macro differently, you
10310: can cause a large class of instructions to be output differently (such
10311: as with rearranged operands). Naturally, variations in assembler
10312: syntax affecting individual insn patterns ought to be handled by
10313: writing conditional output routines in those patterns.
10314:
10315: If this macro is not defined, it is equivalent to a null statement.
10316:
10317: @item PRINT_OPERAND (@var{stream}, @var{x}, @var{code})
10318: A C compound statement to output to stdio stream @var{stream} the
10319: assembler syntax for an instruction operand @var{x}. @var{x} is an
10320: RTL expression.
10321:
10322: @var{code} is a value that can be used to specify one of several ways
10323: of printing the operand. It is used when identical operands must be
10324: printed differently depending on the context. @var{code} comes from
10325: the @samp{%} specification that was used to request printing of the
10326: operand. If the specification was just @samp{%@var{digit}} then
10327: @var{code} is 0; if the specification was @samp{%@var{ltr}
10328: @var{digit}} then @var{code} is the ASCII code for @var{ltr}.
10329:
10330: If @var{x} is a register, this macro should print the register's name.
10331: The names can be found in an array @code{reg_names} whose type is
10332: @code{char *[]}. @code{reg_names} is initialized from
10333: @code{REGISTER_NAMES}.
10334:
10335: When the machine description has a specification @samp{%@var{punct}}
10336: (a @samp{%} followed by a punctuation character), this macro is called
10337: with a null pointer for @var{x} and the punctuation character for
10338: @var{code}.
10339:
1.1.1.8 root 10340: @item PRINT_OPERAND_PUNCT_VALID_P (@var{code})
10341: A C expression which evaluates to true if @var{code} is a valid
10342: punctuation character for use in the @code{PRINT_OPERAND} macro. If
10343: @code{PRINT_OPERAND_PUNCT_VALID_P} is not defined, it means that no
10344: punctuation characters (except for the standard one, @samp{%}) are used
10345: in this way.
10346:
1.1 root 10347: @item PRINT_OPERAND_ADDRESS (@var{stream}, @var{x})
10348: A C compound statement to output to stdio stream @var{stream} the
10349: assembler syntax for an instruction operand that is a memory reference
10350: whose address is @var{x}. @var{x} is an RTL expression.
10351:
10352: @item ASM_OPEN_PAREN
10353: @itemx ASM_CLOSE_PAREN
10354: These macros are defined as C string constant, describing the syntax
10355: in the assembler for grouping arithmetic expressions. The following
10356: definitions are correct for most assemblers:
10357:
10358: @example
10359: #define ASM_OPEN_PAREN "("
10360: #define ASM_CLOSE_PAREN ")"
10361: @end example
10362: @end table
10363:
10364: @node Config,, Machine Macros, Top
10365: @chapter The Configuration File
10366:
1.1.1.3 root 10367: The configuration file @file{xm-@var{machine}.h} contains macro definitions
10368: that describe the machine and system on which the compiler is running.
10369: Most of the values in it are actually the same on all machines that GNU CC
10370: runs on, so large parts of all configuration files are identical. But
1.1 root 10371: there are some macros that vary:
10372:
10373: @table @code
10374: @item FAILURE_EXIT_CODE
10375: A C expression for the status code to be returned when the compiler
10376: exits after serious errors.
10377:
10378: @item SUCCESS_EXIT_CODE
10379: A C expression for the status code to be returned when the compiler
10380: exits without serious errors.
1.1.1.10 root 10381:
10382: @item USE_C_ALLOCA
10383: Define this macro to indicate that the compiler is running with the
10384: @code{alloca} implemented in C. This version of @code{alloca} can be
10385: found in the file @file{alloca.c}; to use it, you must also alter the
10386: @file{Makefile} variable @code{ALLOCA}.
10387:
10388: This macro, unlike most, describes the machine that the compiler is
10389: running on, rather than the one the compiler is compiling for.
10390: Therefore, it should be set in the @file{xm-@var{machine}.h} file
10391: rather than in the @file{tm-@var{machine}.h} file.
10392:
10393: If you do define this macro, you should probably do it as follows:
10394:
10395: @example
10396: #ifndef __GNUC__
10397: #define USE_C_ALLOCA
10398: #else
10399: #define alloca __builtin_alloca
10400: #endif
10401: @end example
10402:
10403: @noindent
10404: so that when the compiler is compiled with GNU CC it uses the more
10405: efficient built-in @code{alloca} function.
1.1 root 10406: @end table
10407:
1.1.1.3 root 10408: In addition, configuration files for system V define @code{bcopy},
10409: @code{bzero} and @code{bcmp} as aliases. Some files define @code{alloca}
10410: as a macro when compiled with GNU CC, in order to take advantage of the
10411: benefit of GNU CC's built-in @code{alloca}.
10412:
1.1 root 10413: @contents
10414: @bye
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.