|
|
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.12! root 45: @center last updated 3 June 1991
1.1 root 46: @sp 1
1.1.1.12! root 47: @center for version 1.40
1.1 root 48: @page
49: @vskip 0pt plus 1filll
1.1.1.12! root 50: Copyright @copyright{} 1988, 1989, 1990, 1991 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 root 1276: @item -fkeep-inline-functions
1277: Even if all calls to a given function are integrated, and the
1278: function is declared @code{static}, nevertheless output a
1279: separate run-time callable version of the function.
1280:
1281: @item -fwritable-strings
1.1.1.8 root 1282: Store string constants in the writable data segment and don't uniquize
1283: them. This is for compatibility with old programs which assume they can
1284: write into string constants. @samp{-traditional} also has this effect.
1285:
1286: Writing into string constants is a very bad idea; ``constants'' should
1287: be constant.
1.1 root 1288:
1.1.1.4 root 1289: @item -fcond-mismatch
1290: Allow conditional expressions with mismatched types in the second and
1291: third arguments. The value of such an expression is void.
1292:
1.1 root 1293: @item -fno-function-cse
1294: Do not put function addresses in registers; make each instruction
1295: that calls a constant function contain the function's address
1296: explicitly.
1297:
1298: This option results in less efficient code, but some strange
1299: hacks that alter the assembler output may be confused by the
1300: optimizations performed when this option is not used.
1301:
1302: @item -fvolatile
1303: Consider all memory references through pointers to be volatile.
1304:
1.1.1.4 root 1305: @item -fshared-data
1306: Requests that the data and non-@code{const} variables of this
1307: compilation be shared data rather than private data. The distinction
1308: makes sense only on certain operating systems, where shared data is
1309: shared between processes running the same program, while private data
1310: exists in one copy per process.
1311:
1.1 root 1312: @item -funsigned-char
1.1.1.4 root 1313: Let the type @code{char} be the unsigned, like @code{unsigned char}.
1.1 root 1314:
1315: Each kind of machine has a default for what @code{char} should
1316: be. It is either like @code{unsigned char} by default or like
1317: @code{signed char} by default. (Actually, at present, the
1318: default is always signed.)
1319:
1320: The type @code{char} is always a distinct type from either
1321: @code{signed char} or @code{unsigned char}, even though its
1322: behavior is always just like one of those two.
1323:
1.1.1.4 root 1324: Note that this is equivalent to @samp{-fno-signed-char}, which is the
1325: negative form of @samp{-fsigned-char}.
1326:
1.1 root 1327: @item -fsigned-char
1328: Let the type @code{char} be signed, like @code{signed char}.
1329:
1.1.1.4 root 1330: Note that this is equivalent to @samp{-fno-unsigned-char}, which is
1331: the negative form of @samp{-funsigned-char}.
1332:
1.1.1.8 root 1333: @item -fdelayed-branch
1334: If supported for the target machine, attempt to reorder instructions
1335: to exploit instruction slots available after delayed branch
1336: instructions.
1337:
1.1 root 1338: @item -ffixed-@var{reg}
1339: Treat the register named @var{reg} as a fixed register; generated
1340: code should never refer to it (except perhaps as a stack pointer,
1341: frame pointer or in some other fixed role).
1342:
1343: @var{reg} must be the name of a register. The register names
1344: accepted are machine-specific and are defined in the
1345: @code{REGISTER_NAMES} macro in the machine description macro
1346: file.
1347:
1.1.1.4 root 1348: This flag does not have a negative form, because it specifies a
1349: three-way choice.
1350:
1.1 root 1351: @item -fcall-used-@var{reg}
1352: Treat the register named @var{reg} as an allocatable register
1353: that is clobbered by function calls. It may be allocated for
1354: temporaries or variables that do not live across a call.
1355: Functions compiled this way will not save and restore the
1356: register @var{reg}.
1357:
1358: Use of this flag for a register that has a fixed pervasive role
1359: in the machine's execution model, such as the stack pointer or
1360: frame pointer, will produce disastrous results.
1361:
1.1.1.4 root 1362: This flag does not have a negative form, because it specifies a
1363: three-way choice.
1364:
1.1 root 1365: @item -fcall-saved-@var{reg}
1366: Treat the register named @var{reg} as an allocatable register
1367: saved by functions. It may be allocated even for temporaries or
1368: variables that live across a call. Functions compiled this way
1369: will save and restore the register @var{reg} if they use it.
1370:
1371: Use of this flag for a register that has a fixed pervasive role
1372: in the machine's execution model, such as the stack pointer or
1373: frame pointer, will produce disastrous results.
1374:
1375: A different sort of disaster will result from the use of this
1376: flag for a register in which function values may be returned.
1.1.1.4 root 1377:
1378: This flag does not have a negative form, because it specifies a
1379: three-way choice.
1.1 root 1380: @end table
1381:
1382: @item -d@var{letters}
1383: Says to make debugging dumps at times specified by @var{letters}.
1384: Here are the possible letters:
1385:
1386: @table @samp
1387: @item r
1388: Dump after RTL generation.
1389: @item j
1390: Dump after first jump optimization.
1391: @item s
1392: Dump after CSE (including the jump optimization that sometimes
1393: follows CSE).
1394: @item L
1395: Dump after loop optimization.
1396: @item f
1397: Dump after flow analysis.
1398: @item c
1399: Dump after instruction combination.
1400: @item l
1401: Dump after local register allocation.
1402: @item g
1403: Dump after global register allocation.
1.1.1.8 root 1404: @item d
1405: Dump after delayed branch scheduling.
1406: @item J
1407: Dump after last jump optimization.
1.1 root 1408: @item m
1409: Print statistics on memory usage, at the end of the run.
1410: @end table
1411:
1412: @item -pedantic
1413: Issue all the warnings demanded by strict ANSI standard C; reject
1414: all programs that use forbidden extensions.
1415:
1416: Valid ANSI standard C programs should compile properly with or without
1417: this option (though a rare few will require @samp{-ansi}). However,
1418: without this option, certain GNU extensions and traditional C features
1419: are supported as well. With this option, they are rejected. There is
1420: no reason to @i{use} this option; it exists only to satisfy pedants.
1.1.1.5 root 1421:
1.1.1.8 root 1422: @samp{-pedantic} does not cause warning messages for use of the
1423: alternate keywords whose names begin and end with @samp{__}.
1424: @xref{Alternate Keywords}.
1425:
1.1.1.5 root 1426: @item -static
1427: On Suns running version 4, this prevents linking with the shared
1428: libraries. (@samp{-g} has the same effect.)
1.1 root 1429: @end table
1430:
1431: These options control the C preprocessor, which is run on each C source
1432: file before actual compilation. If you use the @samp{-E} option, nothing
1433: is done except C preprocessing. Some of these options make sense only
1434: together with @samp{-E} because they request preprocessor output that is
1435: not suitable for actual compilation.
1436:
1437: @table @samp
1438: @item -C
1439: Tell the preprocessor not to discard comments. Used with the
1440: @samp{-E} option.
1441:
1442: @item -I@var{dir}
1443: Search directory @var{dir} for include files.
1444:
1445: @item -I-
1446: Any directories specified with @samp{-I} options before the @samp{-I-}
1447: option are searched only for the case of @samp{#include "@var{file}"};
1448: they are not searched for @samp{#include <@var{file}>}.
1449:
1450: If additional directories are specified with @samp{-I} options after
1451: the @samp{-I-}, these directories are searched for all @samp{#include}
1452: directives. (Ordinarily @emph{all} @samp{-I} directories are used
1453: this way.)
1454:
1455: In addition, the @samp{-I-} option inhibits the use of the current
1.1.1.8 root 1456: directory (where the current input file came from) as the first search
1457: directory for @samp{#include "@var{file}"}. There is no way to override
1458: this effect of @samp{-I-}. With @samp{-I.} you can specify searching
1459: the directory which was current when the compiler was invoked. That is
1460: not exactly the same as what the preprocessor does by default, but it is
1461: often satisfactory.
1462:
1463: @samp{-I-} does not inhibit the use of the standard system directories
1464: for header files. Thus, @samp{-I-} and @samp{-nostdinc} are
1465: independent.
1466:
1467: @item -i @var{file}
1468: Process @var{file} as input, discarding the resulting output, before
1469: processing the regular input file. Because the output generated from
1470: @var{file} is discarded, the only effect of @samp{-i @var{file}} is to
1471: make the macros defined in @var{file} available for use in the main
1472: input.
1.1 root 1473:
1474: @item -nostdinc
1475: Do not search the standard system directories for header files. Only
1476: the directories you have specified with @samp{-I} options (and the
1477: current directory, if appropriate) are searched.
1478:
1479: Between @samp{-nostdinc} and @samp{-I-}, you can eliminate all
1480: directories from the search path except those you specify.
1481:
1482: @item -M
1483: Tell the preprocessor to output a rule suitable for @code{make}
1.1.1.10 root 1484: describing the dependencies of each object file. For each source
1.1 root 1485: file, the preprocessor outputs one @code{make}-rule whose target is
1486: the object file name for that source file and whose dependencies are
1487: all the files @samp{#include}d in it. This rule may be a single line
1488: or may be continued with @samp{\}-newline if it is long.
1489:
1490: @samp{-M} implies @samp{-E}.
1491:
1492: @item -MM
1493: Like @samp{-M} but the output mentions only the user-header files
1494: included with @samp{#include "@var{file}"}. System header files
1495: included with @samp{#include <@var{file}>} are omitted.
1496:
1497: @samp{-MM} implies @samp{-E}.
1498:
1499: @item -D@var{macro}
1.1.1.8 root 1500: Define macro @var{macro} with the string @samp{1} as its definition.
1.1 root 1501:
1502: @item -D@var{macro}=@var{defn}
1503: Define macro @var{macro} as @var{defn}.
1504:
1505: @item -U@var{macro}
1506: Undefine macro @var{macro}.
1507:
1.1.1.7 root 1508: @item -trigraphs
1.1 root 1509: Support ANSI C trigraphs. You don't want to know about this
1510: brain-damage. The @samp{-ansi} option also has this effect.
1511: @end table
1512:
1513: @node Installation, Trouble, Options, Top
1514: @chapter Installing GNU CC
1515:
1516: Here is the procedure for installing GNU CC on a Unix system.
1.1.1.8 root 1517:
1.1 root 1518: @menu
1.1.1.8 root 1519: * Other Dir:: Compiling in a separate directory (not where the source is).
1520: * Sun Install:: See below for installation on the Sun.
1521: * 3B1 Install:: See below for installation on the 3B1.
1.1.1.11 root 1522: * SCO Install:: See below for installation on SCO System V 3.2. (Or ESIX.)
1.1 root 1523: * VMS Install:: See below for installation on VMS.
1.1.1.9 root 1524: * HPUX Install:: See below for installation on HPUX.
1.1.1.11 root 1525: * Tower Install:: See below for installation on an NCR Tower.
1.1 root 1526: @end menu
1527: @iftex
1.1.1.9 root 1528: See below for VMS systems, and modified procedures needed on Sun
1529: systems, 3b1 machines and HPUX. The following section says how to
1530: compile in a separate directory on Unix; here we assume you compile in
1531: the same directory that contains the source files.
1.1 root 1532: @end iftex
1533:
1534: @enumerate
1535: @item
1536: Edit @file{Makefile}. If you are using HPUX, or any form of system V,
1537: you must make a few changes described in comments at the beginning of
1.1.1.9 root 1538: the file. Genix requires changes also, and so does the Pyramid.
1.1 root 1539:
1540: @item
1541: On a Sequent system, go to the Berkeley universe.
1542:
1543: @item
1.1.1.2 root 1544: Choose configuration files. The easy way to do this is to run the
1.1.1.8 root 1545: command file @file{config.gcc} with a single argument, which specifies
1546: the type of machine (and in some cases which operating system).
1.1.1.4 root 1547:
1548: Here is a list of the possible arguments:
1549:
1550: @table @samp
1551: @item vax
1552: Vaxes running BSD.
1553: @item vms
1554: Vaxes running VMS.
1555: @item vax-sysv
1556: Vaxes running system V.
1557: @item i386-sysv
1558: Intel 386 PCs running system V.
1.1.1.5 root 1559: @item i386-sysv-gas
1560: Intel 386 PCs running system V, using the GNU assembler and GNU
1561: linker.
1.1.1.6 root 1562: @item sequent-i386
1.1.1.4 root 1563: Sequent with Intel 386 processors.
1.1.1.8 root 1564: @item i386-aix
1565: Intel 386 PCs or PS/2s running AIX.
1.1.1.4 root 1566: @item sun2
1567: Sun 2 running system version 2 or 3.
1568: @item sun3
1.1.1.12! root 1569: Sun 3 running system version 4, with 68881.
1.1.1.7 root 1570: Note there we do not provide a configuration file to use an FPA
1.1.1.8 root 1571: by default, because programs that establish signal handlers for
1.1.1.7 root 1572: floating point traps inherently cannot work with the FPA.
1.1.1.5 root 1573: @item sun3-nfp
1.1.1.12! root 1574: Sun 3 running system version 4, without 68881.
1.1.1.4 root 1575: @item sun4
1.1.1.12! root 1576: Sun 4 running system version 4. @xref{Incompatibilities},
1.1.1.8 root 1577: for calling convention incompatibilities on the Sun 4 (sparc).
1.1.1.4 root 1578: @item sun2-os4
1579: Sun 2 running system version 4.
1.1.1.12! root 1580: @item sun3-os3
! 1581: Sun 3 running system version 2 or 3, with 68881.
! 1582: @item sun3-nfp-os3
! 1583: Sun 3 running system version 2 or 3, without 68881.
! 1584: @item sun4-os3
! 1585: Sun 4 running system version 2 or 3. @xref{Incompatibilities},
1.1.1.8 root 1586: for calling convention incompatibilities on the Sun 4 (sparc).
1.1.1.4 root 1587: @item sun386
1588: Sun 386 (``roadrunner'').
1.1.1.5 root 1589: @item alliant
1.1.1.8 root 1590: Alliant FX/8 computer. Note that the standard installed C compiler in
1591: Concentrix 5.0 has a bug which prevent it from compiling GNU CC
1592: correctly. You can patch the compiler bug as follows:
1593:
1594: @example
1595: cp /bin/pcc ./pcc
1.1.1.9 root 1596: adb -w ./pcc - << EOF
1.1.1.8 root 1597: 15f6?w 6610
1598: EOF
1599: @end example
1600:
1601: Then you must use the @samp{-ip12} option when compiling GNU CC
1602: with the patched compiler, as shown here:
1603:
1604: @example
1605: make CC="./pcc -ip12" CFLAGS=-w
1606: @end example
1607:
1608: Note also that Alliant's version of DBX does not manage to work with the
1609: output from GNU CC.
1610: @item tahoe
1611: The tahoe computer (running BSD, and using DBX).
1612: @item decstation
1613: The DEC 3100 Mips machine (``pmax''). Note that GNU CC cannot generate
1614: debugging information in the unusual format used on the Mips.
1615: @item mips-sysv
1616: The Mips computer, RS series, with the System V environment as default.
1617: Note that GNU CC cannot generate debugging information in the unusual
1618: format used on the Mips.
1619: @item mips-bsd43
1620: The Mips computer, RS series, with the BSD 4.3 environment as default.
1621: Note that GNU CC cannot generate debugging information in the unusual
1622: format used on the Mips.
1.1.1.7 root 1623: @item mips
1.1.1.8 root 1624: The Mips computer, M series. Note that GNU CC cannot generate debugging
1625: information in the unusual format used on the Mips.
1626: @item iris
1.1.1.10 root 1627: Another variant of the Mips computer, the Silicon Graphics Iris 4D.
1628: Note that GNU CC cannot generate debugging information in the unusual
1629: format used on the Mips.
1.1.1.5 root 1630: @item convex-c1
1.1.1.12! root 1631: Convex C1 computer. With operating system version 9, use @samp{cc -pcc}
! 1632: as the compilation command when building stage 1 of GNU CC.
1.1.1.5 root 1633: @item convex-c2
1.1.1.12! root 1634: Convex C2 computer. With operating system version 9, use @samp{cc -pcc}
! 1635: as the compilation command when building stage 1 of GNU CC.
1.1.1.8 root 1636: @item pyramid
1637: Pyramid computer.
1.1.1.4 root 1638: @item hp9k320
1.1.1.7 root 1639: HP 9000 series 300 using HPUX assembler. Note there is no
1640: support in GNU CC for HP's debugger; thus, @samp{-g} is not
1641: available in this configuration.
1.1.1.8 root 1642: @item hp9k320-gas
1.1.1.4 root 1643: HP 9000 series 300 using GNU assembler, linker and debugger.
1.1.1.7 root 1644: This requires the HP-adapt package, which is available along with
1645: the GNU linker as part of the ``binutils'' distribution.
1646: This is on the GNU CC distribution tape.
1.1.1.8 root 1647: @item hp9k320-old
1648: HP 9000 series 300 using HPUX assembler, in operating system versions
1649: older than 6.5. Note there is no support in GNU CC for HP's debugger;
1650: thus, @samp{-g} is not available in this configuration.
1651: @item hp9k320-bsd
1652: HP 9000 series 300 running BSD.
1.1.1.12! root 1653: @item hp9k200-bsd
! 1654: HP 9000 series 200 running BSD. Note that the C compiler that comes
! 1655: with this system cannot compile GNU CC; contact @code{law@@super.org} to
! 1656: get binaries of GNU CC for bootstrapping. Additionally, a minor patch
! 1657: is necessary if you wish to build kernels with GNU CC; contact
! 1658: @code{law@@super.org} to get a copy of the patch.
1.1.1.4 root 1659: @item isi68
1.1.1.8 root 1660: ISI 68000 or 68020 system with a 68881.
1661: @item isi68-nfp
1662: ISI 68000 or 68020 system without a 68881.
1.1.1.4 root 1663: @item news800
1664: Sony NEWS 68020 system.
1.1.1.6 root 1665: @item next
1666: NeXT system.
1.1.1.10 root 1667: @item tower
1668: NCR Tower 32 system.
1.1.1.7 root 1669: @item altos
1670: Altos 3068. Note that you must use the GNU assembler, linker and
1671: debugger, with COFF-encapsulation. Also, you must fix a kernel
1672: bug. Details in the file @file{ALTOS-README}.
1.1.1.4 root 1673: @item 3b1
1.1.1.8 root 1674: AT&T 3b1, a.k.a. 7300 PC. Note that special procedures are needed
1675: to compile GNU CC with this machine's standard C compiler, due to
1676: bugs in that compiler. @xref{3b1 Install}. You can bootstrap it
1677: more easily with previous versions of GNU CC if you have them.
1.1.1.9 root 1678: @item 3b1-gas
1679: AT&T 3b1 using the GNU assembler.
1.1.1.4 root 1680: @item sequent-ns32k
1681: Sequent containing ns32000 processors.
1682: @item encore
1683: Encore ns32000 system.
1684: @item genix
1685: National Semiconductor ns32000 system.
1686: @item 88000
1687: Motorola 88000 processor. This port is not finished.
1688: @end table
1.1.1.2 root 1689:
1.1.1.4 root 1690: Here we spell out what files need to be set up:
1.1 root 1691:
1692: @itemize @bullet
1693: @item
1694: Make a symbolic link named @file{config.h} to the top-level
1695: config file for the machine you are using (@pxref{Config}). This
1696: file is responsible for defining information about the host
1697: machine. It includes @file{tm.h}.
1698:
1.1.1.7 root 1699: The file is located in the subdirectory @file{config}. Its name
1700: should be @file{xm-@var{machine}.h}, with these exceptions:
1.1 root 1701:
1702: @table @file
1.1.1.3 root 1703: @item xm-vms.h
1.1 root 1704: for vaxen running VMS.
1.1.1.3 root 1705: @item xm-vaxv.h
1.1 root 1706: for vaxen running system V.
1.1.1.3 root 1707: @item xm-i386v.h
1.1 root 1708: for Intel 80386's running system V.
1.1.1.3 root 1709: @item xm-sun386i.h
1710: for Sun roadrunner running any version of the operating system.
1711: @item xm-hp9k320.h
1.1 root 1712: for the HP 9000 series 300.
1.1.1.4 root 1713: @item xm-genix.h
1.1 root 1714: for the ns32000 running Genix
1715: @end table
1716:
1717: If your system does not support symbolic links, you might want to
1718: set up @file{config.h} to contain a @samp{#include} command which
1719: refers to the appropriate file.
1720:
1721: @item
1722: Make a symbolic link named @file{tm.h} to the machine-description
1.1.1.7 root 1723: macro file for your machine. It should be in the subdirectory
1724: @file{config} and its name should be @file{tm-@var{machine}.h}.
1.1 root 1725:
1726: If your system is a 68000, don't use the file @file{tm-m68k.h}
1727: directly. Instead, use one of these files:
1728:
1729: @table @file
1730: @item tm-sun3.h
1.1.1.5 root 1731: for Sun 3 machines with 68881.
1732: @item tm-sun3-nfp.h
1733: for Sun 3 machines with no hardware floating point.
1.1.1.8 root 1734: @item tm-sun3os3.h
1735: for Sun 3 machines with 68881, running Sunos version 3.
1736: @item tm-sun3os3nf.h
1737: for Sun 3 machines with no hardware floating point, running Sunos
1738: version 3.
1.1 root 1739: @item tm-sun2.h
1740: for Sun 2 machines.
1741: @item tm-3b1.h
1742: for AT&T 3b1 (aka 7300 Unix PC).
1743: @item tm-isi68.h
1.1.1.3 root 1744: for Integrated Solutions systems. This file assumes you
1745: use the GNU assembler.
1.1.1.8 root 1746: @item tm-isi68-nfp.h
1747: for Integrated Solutions systems without a 68881. This file assumes you
1748: use the GNU assembler.
1.1 root 1749: @item tm-news800.h
1.1.1.8 root 1750: for Sony NEWS systems.
1.1 root 1751: @item tm-hp9k320.h
1752: for HPUX systems, if you are using GNU CC with the system's
1753: assembler and linker.
1754: @item tm-hp9k320g.h
1755: for HPUX systems, if you are using the GNU assembler, linker and
1756: other utilities. Not all of the pieces of GNU software needed
1757: for this mode of operation are as yet in distribution; full
1758: instructions will appear here in the future.@refill
1.1.1.10 root 1759: @item tm-tower-as.h
1760: for NCR Tower 32 systems, using the standard system assembler.
1.1 root 1761: @end table
1762:
1763: For the vax, use @file{tm-vax.h} on BSD Unix, @file{tm-vaxv.h} on
1764: system V, or @file{tm-vms.h} on VMS.@refill
1765:
1766: For the Motorola 88000, use @file{tm-m88k.h}. The support for the
1.1.1.9 root 1767: 88000 does not currently work; it requires extensive changes which
1768: we hope to reconcile in version 2.
1.1 root 1769:
1770: For the 80386, don't use @file{tm-i386.h} directly. Use
1771: @file{tm-i386v.h} if the target machine is running system V,
1.1.1.5 root 1772: @file{tm-i386gas.h} if it is running system V but you are using the
1773: GNU assembler and linker, @file{tm-seq386.h} for a Sequent 386 system,
1774: or @file{tm-compaq.h} for a Compaq, or @file{tm-sun386i.h} for a Sun
1775: 386 system.
1.1 root 1776:
1.1.1.8 root 1777: For the Mips computer, there are five choices: @file{tm-mips.h} for the
1778: M series, @file{tm-mips-bsd.h} for the RS series with BSD,
1779: @file{tm-mips-sysv.h} for the RS series with System V, @file{tm-iris.h}
1780: for the Iris version of the machine, and @file{tm-decstatn.h} for the
1781: Decstation.
1782:
1.1 root 1783: For the 32000, use @file{tm-sequent.h} if you are using a Sequent
1784: machine, or @file{tm-encore.h} for an Encore machine, or
1.1.1.4 root 1785: @file{tm-genix.h} if you are using Genix version 3; otherwise, perhaps
1.1 root 1786: @file{tm-ns32k.h} will work for you.
1787:
1788: Note that Genix has bugs in @code{alloca} and @code{malloc}; you must
1789: get the compiled versions of these from GNU Emacs and edit GNU CC's
1790: @file{Makefile} to use them.
1791:
1792: Note that Encore systems are supported only under BSD.
1793:
1.1.1.6 root 1794: For Sparc (Sun 4) machines, use @file{tm-sparc.h} with operating system
1795: version 4, and @file{tm-sun4os3.h} with system version 3.
1796:
1.1.1.10 root 1797: For Convex systems before version 8.1, use @file{tm-conv1os7.h} or
1798: @file{tm-conv2os7.h}. For versions 8.1 and greater, use @file{tm-convex1.h}
1799: or @file{tm-convex2.h}. You should also bootstrap GCC with @code{pcc}
1800: rather than @code{cc}; one way to do this is with the following commands.
1801:
1802: @example
1803: ln -s /bin/pcc ./cc
1804: set path = (. $path)
1805: @end example
1806:
1.1 root 1807: @item
1808: Make a symbolic link named @file{md} to the machine description
1.1.1.7 root 1809: pattern file. It should be in the @file{config} subdirectory and its
1810: name should be @file{@var{machine}.md}; but @var{machine} is often not
1811: the same as the name used in the @file{tm.h} file because the
1812: @file{md} files are more general.
1.1 root 1813:
1814: @item
1815: Make a symbolic link named @file{aux-output.c} to the output
1.1.1.7 root 1816: subroutine file for your machine. It should be in the @file{config}
1817: subdirectory and its name should be @file{out-@var{machine}.c}.
1.1 root 1818: @end itemize
1819:
1820: @item
1821: Make sure the Bison parser generator is installed. (This is
1822: unnecessary if the Bison output files @file{c-parse.tab.c} and
1823: @file{cexp.c} are more recent than @file{c-parse.y} and @file{cexp.y}
1824: and you do not plan to change the @samp{.y} files.)
1825:
1.1.1.9 root 1826: Bison versions older than Sept 8, 1988 will produce incorrect output
1.1 root 1827: for @file{c-parse.tab.c}.
1828:
1829: @item
1.1.1.10 root 1830: If you have a previous version of GCC installed, then chances are
1831: you can compile the new version with that. Do the following:
1832:
1833: @example
1834: make CC="gcc -O"
1835: @end example
1836:
1837: @noindent
1838: Since this produces an optimized executable right away, there is no need
1839: to bootstrap the result with itself except to test it. Therefore, you can
1840: skip directly to the @samp{make install} step below.
1841:
1842: @item
1.1 root 1843: Build the compiler. Just type @samp{make} in the compiler directory.
1844:
1.1.1.2 root 1845: Ignore any warnings you may see about ``statement not reached'' in the
1846: @file{insn-emit.c}; they are normal. Any other compilation errors may
1847: represent bugs in the port to your machine or operating system, and
1848: should be investigated and reported (@pxref{Bugs}).
1849:
1.1.1.9 root 1850: Some commercial compilers fail to compile GNU CC because they have bugs
1851: or limitations. For example, the Microsoft compiler is said to run out
1852: of macro space. Some Ultrix compilers run out of expression space; then
1853: you need to break up the statement where the problem happens.
1.1.1.7 root 1854:
1855: @item
1.1.1.5 root 1856: If you are using COFF-encapsulation, you must convert @file{gnulib} to
1857: a GNU-format library at this point. See the file @file{README-ENCAP}
1858: in the directory containing the GNU binary file utilities, for
1859: directions.
1860:
1861: @item
1.1 root 1862: Move the first-stage object files and executables into a subdirectory
1863: with this command:
1864:
1865: @example
1866: make stage1
1867: @end example
1868:
1869: The files are moved into a subdirectory named @file{stage1}.
1870: Once installation is complete, you may wish to delete these files
1871: with @code{rm -r stage1}.
1872:
1873: @item
1874: Recompile the compiler with itself, with this command:
1875:
1876: @example
1877: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/"
1878: @end example
1879:
1.1.1.10 root 1880: This is called making the stage 2 compiler.
1881:
1.1 root 1882: On a 68000 or 68020 system lacking floating point hardware,
1883: unless you have selected a @file{tm.h} file that expects by default
1884: that there is no such hardware, do this instead:
1885:
1886: @example
1887: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/ -msoft-float"
1888: @end example
1889:
1890: @item
1891: If you wish to test the compiler by compiling it with itself one more
1.1.1.7 root 1892: time, do this (in C shell):
1.1 root 1893:
1894: @example
1895: make stage2
1896: make CC=stage2/gcc CFLAGS="-g -O -Bstage2/"
1897: foreach file (*.o)
1898: cmp $file stage2/$file
1899: end
1900: @end example
1901:
1.1.1.7 root 1902: @noindent
1.1.1.10 root 1903: This is called making the stage 3 compiler. Aside from the @samp{-B}
1904: option, the options should be the same as when you made the stage 2
1905: compiler.
1.1 root 1906:
1.1.1.7 root 1907: The @code{foreach} command (written in C shell) will notify you if any of
1908: these stage 3 object files differs from those of stage 2. On BSD systems,
1909: any difference, no matter how innocuous, indicates that the stage 2
1910: compiler has compiled GNU CC incorrectly, and is therefore a potentially
1911: serious bug which you should investigate and report (@pxref{Bugs}).
1912:
1913: On systems that use COFF object files, bytes 5 to 8 will always be
1914: different, since it is a timestamp. On these systems, you can do the
1915: comparison as follows (in Bourne shell):
1916:
1917: @example
1918: for file in *.o; do
1919: echo $file
1.1.1.10 root 1920: tail +10c $file > foo1
1921: tail +10c stage2/$file > foo2
1.1.1.7 root 1922: cmp foo1 foo2
1923: done
1924: @end example
1925:
1.1.1.10 root 1926: On MIPS machines, you should use the shell script @file{ecoff-cmp}
1927: to compare two object files.
1928:
1.1 root 1929: @item
1930: Install the compiler driver, the compiler's passes and run-time support.
1931: You can use the following command:
1932:
1933: @example
1934: make install
1935: @end example
1936:
1937: @noindent
1938: This copies the files @file{cc1}, @file{cpp} and @file{gnulib} to
1939: files @file{gcc-cc1}, @file{gcc-cpp} and @file{gcc-gnulib} in
1940: directory @file{/usr/local/lib}, which is where the compiler driver
1941: program looks for them. It also copies the driver program @file{gcc}
1.1.1.6 root 1942: into the directory @file{/usr/local/bin}, so that it appears in typical
1.1 root 1943: execution search paths.@refill
1944:
1945: @strong{Warning: there is a bug in @code{alloca} in the Sun library.
1946: To avoid this bug, install the binaries of GNU CC that were compiled
1947: by GNU CC. They use @code{alloca} as a built-in function and never
1948: the one in the library.}
1949:
1950: @strong{Warning: the GNU CPP may not work for @file{ioctl.h},
1951: @file{ttychars.h} and other system header files unless the
1952: @samp{-traditional} option is used.} The bug is in the header files:
1953: at least on some machines, they rely on behavior that is incompatible
1954: with ANSI C. This behavior consists of substituting for macro
1955: argument names when they appear inside of character constants. The
1956: @samp{-traditional} option tells GNU CC to behave the way these
1957: headers expect.
1958:
1959: Because of this problem, you might prefer to configure GNU CC to use
1960: the system's own C preprocessor. To do so, make the file
1961: @file{/usr/local/lib/gcc-cpp} a link to @file{/lib/cpp}.
1962:
1963: Alternatively, on Sun systems and 4.3BSD at least, you can correct the
1964: include files by running the shell script @file{fixincludes}. This
1965: installs modified, corrected copies of the files @file{ioctl.h},
1966: @file{ttychars.h} and many others, in a special directory where only
1.1.1.2 root 1967: GNU CC will normally look for them. This script will work on various
1.1.1.6 root 1968: systems because it chooses the files by searching all the system
1.1.1.2 root 1969: headers for the problem cases that we know about.
1.1.1.10 root 1970:
1971: Use the following command to do this:
1972:
1973: @example
1974: make includes
1975: @end example
1976:
1977: @noindent
1978: If you selected a different directory for GNU CC installation when you
1979: installed it, by specifying the Make variable @code{prefix} or
1980: @code{libdir}, specify it the same way in this command.
1981:
1982: Note that some systems are starting to come with ANSI C system header
1983: files. On these systems, don't run @file{fixincludes}; it may not work,
1984: and is certainly not necessary.
1.1.1.12! root 1985:
! 1986: @strong{Warning:} @file{fixincludes} does not work on many MIPS systems,
! 1987: because those systems come with circular symbolic links which cause
! 1988: @samp{ls -lR} to go into an infinite loop.
1.1 root 1989: @end enumerate
1990:
1991: If you cannot install the compiler's passes and run-time support in
1992: @file{/usr/local/lib}, you can alternatively use the @samp{-B} option to
1993: specify a prefix by which they may be found. The compiler concatenates
1994: the prefix with the names @file{cpp}, @file{cc1} and @file{gnulib}.
1995: Thus, you can put the files in a directory @file{/usr/foo/gcc} and
1996: specify @samp{-B/usr/foo/gcc/} when you run GNU CC.
1997:
1998: Also, you can specify an alternative default directory for these files
1999: by setting the Make variable @code{libdir} when you make GNU CC.
2000:
1.1.1.8 root 2001: @node Other Dir, Sun Install, Installation, Installation
2002: @section Compilation in a Separate Directory
1.1 root 2003:
1.1.1.8 root 2004: If you wish to build the object files and executables in a directory
2005: other than the one containing the source files, here is what you must
2006: do differently:
2007:
2008: @enumerate
2009: @item
2010: Go to that directory before running @file{config.gcc}:
2011:
2012: @example
2013: mkdir gcc-sun3
2014: cd gcc-sun3
2015: @end example
1.1.1.4 root 2016:
1.1.1.8 root 2017: On systems that do not support symbolic links, this directory must be
2018: on the same file system as the source code directory.
2019:
2020: @item
2021: Specify where to find @file{config.gcc} when you run it:
2022:
2023: @example
2024: ../gcc-1.36/config.gcc @dots{}
2025: @end example
2026:
2027: @item
2028: Specify where to find the sources, as an argument to @file{config.gcc}:
2029:
2030: @example
2031: ../gcc-1.36/config.gcc -srcdir=../gcc-1.36 sun3
2032: @end example
2033:
2034: The @samp{-srcdir=@var{dir}} option is not needed when the source
2035: directory is the parent of the current directory, because
2036: @file{config.gcc} detects that case automatically.
2037: @end enumerate
2038:
2039: Now, you can run @code{make} in that directory. You need not repeat the
2040: configuration steps shown above, when ordinary source files change. You
2041: must, however, run @code{config.gcc} again when the configuration files
2042: change, if your system does not support symbolic links.
2043:
2044: @node Sun Install, 3b1 Install, Other Dir, Installation
2045: @section Installing GNU CC on the Sun
2046:
2047: Make sure the environment variable @code{FLOAT_OPTION} is not set when
2048: you compile @file{gnulib}. If this option were set to @code{f68881}
2049: when @file{gnulib} is compiled, the resulting code would demand to be
2050: linked with a special startup file and would not link properly without
2051: special pains.
2052:
2053: There is a bug in @code{alloca} in certain versions of the Sun library.
2054: To avoid this bug, install the binaries of GNU CC that were compiled by
2055: GNU CC. They use @code{alloca} as a built-in function and never the one
2056: in the library.
2057:
1.1.1.11 root 2058: Some versions of the Sun compiler crash when compiling GNU CC, with a
2059: segmentation fault in cpp. This can sometimes be due to the bulk of
2060: data in the environment variables. You may be able to avoid it by using
2061: the following command to compile GNU CC with Sun CC:
1.1.1.8 root 2062:
2063: @example
2064: make CC="TERMCAP=x OBJS=x LIBFUNCS=x STAGESTUFF=x cc"
2065: @end example
2066:
1.1.1.11 root 2067: Another problem that often happens on Suns is that you get a crash when
2068: building stage 2, when @code{genflags} is run.
2069:
2070: One reason for such as crash is if you configured GNU CC for the wrong
2071: version of SunOS. Starting with version 1.38, configurations @code{sun3}
2072: and @code{sun4} are for SunOS 4, so this problem should no longer happen.
2073:
2074: Another cause of the same symptom is having installed the GNU linker
2075: with an earlier version of SunOS. The version that worked before
2076: stopped working due to a change in the format of executables in SunOS
2077: 4.1. Many sites have installed the GNU linker as
2078: @file{/usr/local/lib/gcc-ld}, often as part of installing GNU C++. So
2079: if you get such crashes and you have used the proper configuration, try
2080: deleting @file{/usr/local/lib/gcc-ld}.
2081:
2082: The current version of the GNU linker, found in the current binutils
2083: release, does work with SunOS 4.1.
2084:
1.1.1.10 root 2085: @node 3b1 Install, SCO Install, Sun Install, Installation
1.1.1.8 root 2086: @section Installing GNU CC on the 3b1
2087:
2088: Installing GNU CC on the 3b1 is difficult if you do not already have
2089: GNU CC running, due to bugs in the installed C compiler. However,
2090: the following procedure might work. We are unable to test it.
1.1 root 2091:
2092: @enumerate
2093: @item
1.1.1.8 root 2094: Comment out the @samp{#include "config.h"} line on line 37 of
2095: @file{cccp.c} and do @samp{make cpp}. This makes a preliminary version
2096: of GNU cpp.
1.1 root 2097:
2098: @item
1.1.1.8 root 2099: Save the old @file{/lib/cpp} and copy the preliminary GNU cpp to that
2100: file name.
1.1.1.5 root 2101:
1.1.1.8 root 2102: @item
2103: Undo your change in @file{cccp.c}, or reinstall the original version,
2104: and do @samp{make cpp} again.
2105:
2106: @item
2107: Copy this final version of GNU cpp into @file{/lib/cpp}.
2108:
2109: @item
1.1.1.9 root 2110: Replace every occurrence of @code{obstack_free} in @file{tree.c}
1.1.1.8 root 2111: with @code{_obstack_free}.
2112:
2113: @item
2114: Run @code{make} to get the first-stage GNU CC.
2115:
2116: @item
2117: Reinstall the original version of @file{/lib/cpp}.
2118:
2119: @item
2120: Now you can compile GNU CC with itself and install it in the normal
2121: fashion.
1.1 root 2122: @end enumerate
2123:
1.1.1.9 root 2124: If you have installed an earlier version of GCC, you can compile the
2125: newer version with that. However, you will run into trouble compiling
2126: @file{gnulib}, since that is normally compiled with CC. To solve the
2127: problem, uncomment this line in @file{Makefile}:
2128:
2129: @example
2130: CCLIBFLAGS = -B/usr/local/lib/gcc- -tp -Wp,-traditional
2131: @end example
2132:
1.1.1.10 root 2133: @node SCO Install, VMS Install, 3B1 Install, Installation
2134: @section Installing GNU CC on SCO System V 3.2
2135: @cindex Installation on SCO systems
2136:
2137: The compiler that comes with this system does not work properly with
2138: @samp{-O}. Therefore, you should redefine the Make variable
2139: @code{CCLIBFLAGS} not to use @samp{-O}.
2140:
1.1.1.11 root 2141: You should also edit @file{Makefile} to enable the lines that set
2142: @code{CLIB} to @code{-lPW}, and the ones specifically labeled as being
2143: for SCO, that set @code{RANLIB}, and that set @code{CC} and @code{OLDCC}
2144: to @code{rcc}.
1.1.1.10 root 2145:
1.1.1.11 root 2146: Also, edit the definition of @code{USER_H} to remove the file @file{limits.h}.
1.1.1.10 root 2147:
1.1.1.11 root 2148: Then you can run @samp{config.gcc i386-sco} and finish building GNU CC
2149: normally.
1.1.1.10 root 2150:
1.1.1.11 root 2151: The same recipe should work on ESIX, but use @samp{config.gcc i386-esix}
2152: instead.
1.1.1.10 root 2153:
2154: @node VMS Install, HPUX Install, SCO Install, Installation
1.1.1.8 root 2155: @section Installing GNU CC on VMS
2156:
2157: The VMS version of GNU CC is distributed in a backup saveset containing
2158: both source code and precompiled binaries.
2159:
2160: To install the @file{gcc} command so you can use the compiler easily, in
1.1 root 2161: the same manner as you use the VMS C compiler, you must install the VMS CLD
2162: file for GNU CC as follows:
2163:
2164: @enumerate
2165: @item
2166: Define the VMS logical names @samp{GNU_CC} and @samp{GNU_CC_INCLUDE}
2167: to point to the directories where the GNU CC executables
1.1.1.8 root 2168: (@file{gcc-cpp}, @file{gcc-cc1}, etc.) and the C include files are
1.1 root 2169: kept. This should be done with the commands:@refill
2170:
2171: @example
1.1.1.8 root 2172: $ assign /super /system disk:[gcc.] gnu_cc
2173: $ assign /super /system disk:[gcc.include.] gnu_cc_include
1.1 root 2174: @end example
2175:
2176: @noindent
2177: with the appropriate disk and directory names. These commands can be
2178: placed in your system startup file so they will be executed whenever
1.1.1.8 root 2179: the machine is rebooted. You may, if you choose, do this via the
2180: @file{GCC_INSTALL.COM} script in the @file{[GCC]} directory.
1.1 root 2181:
2182: @item
1.1.1.8 root 2183: Install the @file{GCC} command with the command line:
1.1 root 2184:
2185: @example
1.1.1.8 root 2186: $ set command /table=sys$library:dcltables gnu_cc:[000000]gcc
1.1 root 2187: @end example
2188:
1.1.1.7 root 2189: @item
2190: To install the help file, do the following:
2191:
2192: @example
2193: $ lib/help sys$library:helplib.hlb gcc.hlp
2194: @end example
2195:
1.1 root 2196: @noindent
2197: Now you can invoke the compiler with a command like @samp{gcc /verbose
2198: file.c}, which is equivalent to the command @samp{gcc -v -c file.c} in
2199: Unix.
2200: @end enumerate
2201:
1.1.1.8 root 2202: We try to put corresponding binaries and sources on the VMS distribution
2203: tape. But sometimes the binaries will be from an older version that the
2204: sources, because we don't always have time to update them. (Use the
2205: @samp{/verbose} option to determine the version number of the binaries and
2206: compare it with the source file @file{version.c} to tell whether this is
2207: so.) In this case, you should use the binaries you get to recompile the
2208: sources. If you must recompile, here is how:
2209:
2210: @enumerate
2211: @item
2212: Copy the file @file{tm-vms.h} to @file{tm.h}, @file{xm-vms.h} to
2213: @file{config.h}, @file{vax.md} to @file{md.} and @file{out-vax.c}
2214: to @file{aux-output.c}. The files to be copied are found in the
2215: subdirectory named @file{config}; they should be copied to the
2216: main directory of GNU CC.@refill
2217:
2218: @item
2219: Setup the logical names and command tables as defined above. In
2220: addition, define the vms logical name @samp{GNU_BISON} to point at the
2221: to the directories where the Bison executable is kept. This should be
2222: done with the command:@refill
2223:
2224: @example
2225: $ assign /super /system disk:[bison.] gnu_bison
2226: @end example
2227:
2228: You may, if you choose, use the @file{INSTALL_BISON.COM} script in the
2229: @file{[BISON]} directory.
2230:
2231: @item
2232: Install the @samp{BISON} command with the command line:@refill
2233:
2234: @example
2235: $ set command /table=sys$library:dcltables gnu_bison:[000000]bison
2236: @end example
2237:
2238: @item
2239: Type @samp{@@make} to do recompile everything.
2240:
2241: If you are compiling with a version of GNU CC older than 1.33, specify
2242: @samp{/DEFINE=("inline=")} as an option in all the compilations. This
2243: requires editing all the @code{gcc} commands in @file{make-cc1.com}.
2244: (The older versions had problems supporting @code{inline}.) Once you
2245: have a working 1.33 or newer GNU CC, you can change this file back.
2246: @end enumerate
2247:
1.1.1.12! root 2248: Due to the differences between the filesystems of Unix and VMS, the
! 2249: preprocessor attempts to translate the names of include files into
! 2250: something that VMS will understand. The basic strategy is to prepend a
! 2251: prefix to the specification of the include file, convert the whole
! 2252: filename to a VMS filename, and then try to open the file. The
! 2253: preprocessor tries various prefixes until one of them succeeds.
! 2254:
! 2255: The first prefix is the @samp{GNU_CC_INCLUDE:} logical name: this is
! 2256: where GNU_C header files are traditionally stored. If a header file is
! 2257: not found there, @samp{SYS$SYSROOT:[SYSLIB.]} is tried next. If the
! 2258: preprocessor is still unable to locate the file, it then assumes that
! 2259: the include file specification is a valid VMS filename all by itself,
! 2260: and it uses this filename to attempt to open the include file. If none
! 2261: of these strategies succeeds, the preprocessor reports an error.
! 2262:
! 2263: If you wish to store header files in non-standard locations, then you
! 2264: can assign the logical @samp{GNU_CC_INCLUDE} to be a search list, where
! 2265: each element of the list is suitable for use with a rooted logical.
! 2266:
1.1.1.10 root 2267: With this version of GNU CC, @code{const} global variables now work
2268: properly. Unless, however, the @code{const} modifier is also specified
2269: in every external declaration of the variable in all of the source files
2270: that use that variable, the linker will issue warnings about conflicting
2271: attributes for the variable, since the linker does not know if the
2272: variable should be read-only. The program will still work, but the
2273: variable will be placed in writable storage.
2274:
1.1.1.12! root 2275: Due to an assembler bug, offsets to static constants are sometimes
! 2276: incorrectly evaluated. This bug is present in GAS 1.38.1, and should be
! 2277: fixed in the next version.
! 2278:
1.1.1.10 root 2279: Under previous versions of GNU CC, the generated code would occasionally
2280: give strange results when linked to the sharable @file{VAXCRTL} library.
2281: Now this should work.
2282:
1.1.1.12! root 2283: Even with this version, however, GNU CC itself should not be linked to the
! 2284: sharable @file{VAXCRTL}. The @file{qsort} routine supplied with @file{VAXCRTL}
! 2285: has a bug which can cause a compiler crash.
! 2286:
! 2287: Similarly, the preprocessor should not be linked to the sharable
! 2288: @file{VAXCRTL}. The @code{strncat} routine supplied with @file{VAXCRTL} has a
! 2289: bug which can cause the preprocessor to go into an infinite loop.
! 2290:
! 2291: It should be pointed out that if you attempt to link to the sharable
! 2292: @file{VAXCRTL}, the VMS linker will strongly resist any effort to force
! 2293: it to use the @code{qsort} and @code{strncat} routines from
! 2294: @file{gcclib}. Until the bugs in @file{VAXCRTL} have been fixed,
! 2295: linking any of the compiler components to the sharable VAXCRTL is not
! 2296: recommended. (These routines can be bypassed by placing duplicate copies
! 2297: of @code{qsort} and @code{strncat} in @file{gcclib} under different
! 2298: names, and patching the compiler sources to use these routines). Both
! 2299: of the bugs in @file{VAXCRTL} are still present in VMS version 5.4-1,
! 2300: which is the most recent version as of this writing.
! 2301:
! 2302: The executables that are generated by @file{make-cc1.com} and
! 2303: @file{make-cccp.com} use the non-shared version of @file{VAXCRTL} (and
! 2304: thus use the @code{qsort} and @code{strncat} routines from
! 2305: @file{gcclib.olb}).
1.1.1.10 root 2306:
2307: Note that GNU CC on VMS now generates debugging information to describe
2308: the programs symbols to the VMS debugger. However, you need version 1.37
2309: or later of GAS in order to output them properly in the object file.
1.1.1.7 root 2310:
1.1.1.12! root 2311: The VMS linker does not distinguish between upper and lower case letters
! 2312: in function and variable names. However, usual practice in C is to
! 2313: distinguish case. Normally GNU C (by means of the assembler GAS)
! 2314: implements usual C behavior by augmenting each name that is not all
! 2315: lower-case. A name is augmented by truncating it to at most 23
! 2316: characters and then adding more characters at the end which encode the
! 2317: case pattern the rest.
! 2318:
! 2319: Name augmentation yields bad results for programs that use precompiled
! 2320: libraries (such as Xlib) which were generated by another compiler. Use
! 2321: the compiler option @samp{/NOCASE_HACK} to inhibits augmentation; it
! 2322: makes external C functions and variables case-independent as is usual on
! 2323: VMS. Alternatively, you could write all references to the functions and
! 2324: variables in such libraries using lower case; this will work on VMS, but
! 2325: is not portable to other systems. In cases where you need to
! 2326: selectively inhibit augmentation, you can define a macro for each mixed
! 2327: case symbol for which you wish to inhibit augmentation, where the macro
! 2328: expands into the lower case equivalent of the name.
! 2329:
! 2330: @node HPUX Install, Tower Install, VMS Install, Installation
1.1.1.9 root 2331: @section Installing GNU CC on HPUX
2332:
2333: To install GNU CC on HPUX, you must start by editing the file
2334: @file{Makefile}. Search for the string @samp{HPUX} to find comments
2335: saying what to change. You need to change some variable definitions and
2336: (if you are using GAS) some lines in the rule for the target
2337: @samp{gnulib}.
2338:
1.1.1.10 root 2339: To avoid errors when linking programs with @samp{-g}, create an empty
2340: library named @file{libg.a}. An easy way to do this is:
2341:
2342: @example
2343: ar rc /usr/local/lib/libg.a
2344: @end example
2345:
1.1.1.9 root 2346: To compile with the HPUX C compiler, you must specify get the file
2347: @file{alloca.c} from GNU Emacs. Then, when you run @code{make}, use
2348: this argument:
2349:
2350: @example
2351: make ALLOCA=alloca.o
2352: @end example
2353:
2354: When recompiling GNU CC with itself, do not define @code{ALLOCA}.
2355: Instead, an @samp{-I} option needs to be added to @code{CFLAGS} as
2356: follows:
2357:
2358: @example
2359: make CC=stage1/gcc CFLAGS="-g -O -Bstage1/ -I../binutils/hp-include"
2360: @end example
2361:
1.1.1.12! root 2362: @node Tower Install,, HPUX Install, Installation
1.1.1.11 root 2363: @section Installing GNU CC on an NCR Tower
2364:
2365: On an NCR Tower model 4x0 or 6x0, you may have trouble because the
2366: default maximum virtual address size of a process is just 1 Mb. Most
2367: often you will find this problem while compiling GNU CC with itself.
2368:
2369: The only way to solve the problem is to reconfigure the kernel.
2370: Add a line such as this to the configuration file:
2371:
2372: @example
2373: MAXUMEM = 4096
2374: @end example
2375:
2376: @noindent
2377: and then relink the kernel and reboot the machine.
2378:
2379:
1.1.1.10 root 2380: @node Trouble, Service, Installation, Top
2381: @chapter Known Causes of Trouble with GNU CC
1.1 root 2382:
2383: Here are some of the things that have caused trouble for people installing
2384: or using GNU CC.
2385:
2386: @itemize @bullet
2387: @item
2388: On certain systems, defining certain environment variables such as
1.1.1.8 root 2389: @code{CC} can interfere with the functioning of @code{make}.
1.1 root 2390:
2391: @item
2392: Cross compilation can run into trouble for certain machines because
2393: some target machines' assemblers require floating point numbers to be
2394: written as @emph{integer} constants in certain contexts.
2395:
2396: The compiler writes these integer constants by examining the floating
2397: point value as an integer and printing that integer, because this is
2398: simple to write and independent of the details of the floating point
2399: representation. But this does not work if the compiler is running on
2400: a different machine with an incompatible floating point format, or
2401: even a different byte-ordering.
2402:
1.1.1.5 root 2403: In addition, correct constant folding of floating point values
2404: requires representing them in the target machine's format.
2405: (The C standard does not quite require this, but in practice
2406: it is the only way to win.)
2407:
2408: It is now possible to overcome these problems by defining macros such
2409: as @code{REAL_VALUE_TYPE}. But doing so is a substantial amount of
2410: work for each target machine. @xref{Cross-compilation}.
1.1 root 2411:
2412: @item
1.1.1.2 root 2413: Users often think it is a bug when GNU CC reports an error for code
2414: like this:
2415:
2416: @example
2417: int foo (short);
2418:
2419: int foo (x)
2420: short x;
2421: @{@dots{}@}
2422: @end example
2423:
1.1.1.4 root 2424: The error message is correct: this code really is erroneous, because the
2425: old-style non-prototype definition passes subword integers in their
2426: promoted types. In other words, the argument is really an @code{int},
2427: not a @code{short}. The correct prototype is this:
1.1.1.2 root 2428:
2429: @example
2430: int foo (int);
2431: @end example
2432:
2433: @item
2434: Users often think it is a bug when GNU CC reports an error for code
2435: like this:
2436:
2437: @example
2438: int foo (struct mumble *);
2439:
2440: struct mumble @{ @dots{} @};
2441:
2442: int foo (struct mumble *x)
2443: @{ @dots{} @}
2444: @end example
2445:
2446: This code really is erroneous, because the scope of @code{struct
2447: mumble} the prototype is limited to the argument list containing it.
2448: It does not refer to the @code{struct mumble} defined with file scope
2449: immediately below---they are two unrelated types with similar names in
2450: different scopes.
2451:
2452: But in the definition of @code{foo}, the file-scope type is used
2453: because that is available to be inherited. Thus, the definition and
2454: the prototype do not match, and you get an error.
2455:
2456: This behavior may seem silly, but it's what the ANSI standard
2457: specifies. It is easy enough for you to make your code work by moving
2458: the definition of @code{struct mumble} above the prototype. I don't
2459: think it's worth being incompatible for.
1.1 root 2460: @end itemize
2461:
1.1.1.12! root 2462: Additional problems are described in @ref{Incompatibilities}.
! 2463:
1.1.1.10 root 2464: @node Service, Incompatibilities, Trouble, Top
2465: @chapter How To Get Help with GNU CC
2466:
2467: If you need help installing, using or changing GNU CC, there are two
2468: ways to find it:
2469:
2470: @itemize @bullet
2471: @item
2472: Send a message to a suitable network mailing list. First try
2473: @code{bug-gcc@@prep.ai.mit.edu}, and if that brings no response, try
1.1.1.12! root 2474: @code{help-gcc@@prep.ai.mit.edu}.
1.1.1.10 root 2475:
2476: @item
2477: Look in the service directory for someone who might help you for a fee.
2478: The service directory is found in the file named @file{SERVICE} in the
2479: GNU CC distribution.
2480: @end itemize
2481:
2482: @node Incompatibilities, Extensions, Service, Top
1.1 root 2483: @chapter Incompatibilities of GNU CC
2484:
2485: There are several noteworthy incompatibilities between GNU C and most
1.1.1.9 root 2486: existing (non-ANSI) versions of C. The @samp{-traditional} option
2487: eliminates most of these incompatibilities, @emph{but not all}, by
2488: telling GNU C to behave like older C compilers.
1.1 root 2489:
2490: @itemize @bullet
2491: @item
2492: GNU CC normally makes string constants read-only. If several
2493: identical-looking string constants are used, GNU CC stores only one
2494: copy of the string.
2495:
2496: One consequence is that you cannot call @code{mktemp} with a string
2497: constant argument. The function @code{mktemp} always alters the
2498: string its argument points to.
2499:
2500: Another consequence is that @code{sscanf} does not work on some
2501: systems when passed a string constant as its format control string.
2502: This is because @code{sscanf} incorrectly tries to write into the
1.1.1.4 root 2503: string constant. Likewise @code{fscanf} and @code{scanf}.
1.1 root 2504:
2505: The best solution to these problems is to change the program to use
2506: @code{char}-array variables with initialization strings for these
2507: purposes instead of string constants. But if this is not possible,
2508: you can use the @samp{-fwritable-strings} flag, which directs GNU CC
2509: to handle string constants the same way most C compilers do.
1.1.1.8 root 2510: @samp{-traditional} also has this effect, among others.
1.1 root 2511:
2512: @item
2513: GNU CC does not substitute macro arguments when they appear inside of
2514: string constants. For example, the following macro in GNU CC
2515:
2516: @example
2517: #define foo(a) "a"
2518: @end example
2519:
2520: @noindent
1.1.1.8 root 2521: will produce output @code{"a"} regardless of what the argument @var{a} is.
1.1 root 2522:
2523: The @samp{-traditional} option directs GNU CC to handle such cases
2524: (among others) in the old-fashioned (non-ANSI) fashion.
2525:
2526: @item
2527: When you use @code{setjmp} and @code{longjmp}, the only automatic
2528: variables guaranteed to remain valid are those declared
2529: @code{volatile}. This is a consequence of automatic register
2530: allocation. Consider this function:
2531:
2532: @example
2533: jmp_buf j;
2534:
2535: foo ()
2536: @{
2537: int a, b;
2538:
2539: a = fun1 ();
2540: if (setjmp (j))
2541: return a;
2542:
2543: a = fun2 ();
2544: /* @r{@code{longjmp (j)} may be occur in @code{fun3}.} */
2545: return a + fun3 ();
2546: @}
2547: @end example
2548:
2549: Here @code{a} may or may not be restored to its first value when the
2550: @code{longjmp} occurs. If @code{a} is allocated in a register, then
2551: its first value is restored; otherwise, it keeps the last value stored
2552: in it.
2553:
2554: If you use the @samp{-W} option with the @samp{-O} option, you will
2555: get a warning when GNU CC thinks such a problem might be possible.
2556:
1.1.1.2 root 2557: The @samp{-traditional} option directs GNU C to put variables in
2558: the stack by default, rather than in registers, in functions that
2559: call @code{setjmp}. This results in the behavior found in
2560: traditional C compilers.
2561:
1.1 root 2562: @item
2563: Declarations of external variables and functions within a block apply
2564: only to the block containing the declaration. In other words, they
2565: have the same scope as any other declaration in the same place.
2566:
2567: In some other C compilers, a @code{extern} declaration affects all the
2568: rest of the file even if it happens within a block.
2569:
2570: The @samp{-traditional} option directs GNU C to treat all @code{extern}
2571: declarations as global, like traditional compilers.
2572:
2573: @item
2574: In traditional C, you can combine @code{long}, etc., with a typedef name,
2575: as shown here:
2576:
2577: @example
2578: typedef int foo;
2579: typedef long foo bar;
2580: @end example
2581:
2582: In ANSI C, this is not allowed: @code{long} and other type modifiers
2583: require an explicit @code{int}. Because this criterion is expressed
2584: by Bison grammar rules rather than C code, the @samp{-traditional}
2585: flag cannot alter it.
2586:
2587: @item
2588: PCC allows typedef names to be used as function parameters. The
2589: difficulty described immediately above applies here too.
2590:
2591: @item
2592: PCC allows whitespace in the middle of compound assignment operators
2593: such as @samp{+=}. GNU CC, following the ANSI standard, does not
2594: allow this. The difficulty described immediately above applies here
2595: too.
2596:
2597: @item
2598: GNU CC will flag unterminated character constants inside of preprocessor
2599: conditionals that fail. Some programs have English comments enclosed in
2600: conditionals that are guaranteed to fail; if these comments contain
2601: apostrophes, GNU CC will probably report an error. For example,
2602: this code would produce an error:
2603:
2604: @example
2605: #if 0
2606: You can't expect this to work.
2607: #endif
2608: @end example
2609:
2610: The best solution to such a problem is to put the text into an actual
2611: C comment delimited by @samp{/*@dots{}*/}. However,
2612: @samp{-traditional} suppresses these error messages.
2613:
2614: @item
2615: When compiling functions that return @code{float}, PCC converts it to
2616: a double. GNU CC actually returns a @code{float}. If you are concerned
2617: with PCC compatibility, you should declare your functions to return
2618: @code{double}; you might as well say what you mean.
2619:
2620: @item
2621: When compiling functions that return structures or unions, GNU CC
1.1.1.6 root 2622: output code normally uses a method different from that used on most
2623: versions of Unix. As a result, code compiled with GNU CC cannot call
2624: a structure-returning function compiled with PCC, and vice versa.
1.1 root 2625:
1.1.1.6 root 2626: The method used by GNU CC is as follows: a structure or union which is 1,
1.1 root 2627: 2, 4 or 8 bytes long is returned like a scalar. A structure or union
2628: with any other size is stored into an address supplied by the caller
2629: in a special, fixed register.
2630:
2631: PCC usually handles all sizes of structures and unions by returning
2632: the address of a block of static storage containing the value. This
1.1.1.6 root 2633: method is not used in GNU CC because it is slower and nonreentrant.
1.1.1.5 root 2634:
1.1.1.6 root 2635: You can tell GNU CC to use the PCC convention with the option
2636: @samp{-fpcc-struct-return}.
1.1.1.12! root 2637: @end itemize
1.1.1.8 root 2638:
1.1.1.12! root 2639: There are also system-specific incompatibilities.
! 2640:
! 2641: @itemize @bullet
1.1.1.8 root 2642: @item
2643: On the Sparc, GNU CC uses an incompatible calling convention for
2644: structures. It passes them by including their contents in the argument
2645: list, whereas the standard compiler passes them effectively by
2646: reference.
2647:
2648: This really ought to be fixed, but such calling conventions are not
2649: yet supported in GNU CC, so it isn't straightforward to fix it.
1.1.1.12! root 2650: GNU CC version 2 will use a compatible calling convention.
1.1.1.8 root 2651:
2652: The convention for structure returning is also incompatible, and
2653: @samp{-fpcc-struct-return} does not help.
1.1.1.10 root 2654:
1.1.1.12! root 2655: @item
! 2656: The Sparc version of @code{setjmp} interacts badly with unexpected stack
! 2657: adjustments. With rare exceptions, you cannot use @code{setjmp} in a
! 2658: function which moves the stack pointer.
! 2659:
! 2660: In the current version of GNU CC, there are three ways that the stack
! 2661: pointer can change value: (1) calls to @code{alloca}, (2) use of
! 2662: variable-sized objects, and (3) calls to functions with parameters that
! 2663: do not all fit in the argument-passing registers (e.g., more than 6
! 2664: parameters). You should avoid all three in functions that call
! 2665: @code{setjmp}.
! 2666:
! 2667: The cause of the problem is the way that Sun implemented register
! 2668: windows. The 64 bytes at addresses @code{%sp} through @code{%sp+63}
! 2669: correspond to the register window save area. When a register window
! 2670: must be spilled, its stack pointer is located, and the registers are
! 2671: dumped starting at that address. Similarly, when a register window must
! 2672: be restored, its stack pointer is located, and the registers are
! 2673: restored from that address.
! 2674:
! 2675: When @code{setjmp} is called, the current register window's registers
! 2676: are saved into the register save area, and when @code{longjmp} is
! 2677: called, they are restored (actually, @emph{all} register windows are
! 2678: restored from all valid register windows at the time @code{longjmp} is
! 2679: called). If there is a change in the value of the stack pointer bewteen
! 2680: the @code{setjmp} and @code{longjmp} calls, when the registers are
! 2681: restored, they are restored with random values.
! 2682:
1.1.1.10 root 2683: @item
2684: On Ultrix, the Fortran compiler expects registers 2 through 5 to be saved
2685: by function calls. We have not been able to tell whether the C compiler
2686: agrees with the Fortran compiler. Currently, GNU CC treats these registers
2687: as temporaries on the Vax, which is compatible with BSD Unix.
2688:
2689: If we learn for certain that Ultrix has departed from the traditional
2690: BSD calling convention, we will change GNU CC for Ultrix to fit. In the
2691: mean time, you can use these options to produce code compatible with the
2692: Fortran compiler:
2693:
2694: @example
2695: -fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
2696: @end example
1.1.1.12! root 2697:
! 2698: @item
! 2699: DBX rejects some files produced by GNU CC, though it accepts similar
! 2700: constructs in output from PCC. Until someone can supply a coherent
! 2701: description of what is valid DBX input and what is not, there is
! 2702: nothing I can do about these problems. You are on your own.
1.1 root 2703: @end itemize
2704:
2705: @node Extensions, Bugs, Incompatibilities, Top
2706: @chapter GNU Extensions to the C Language
2707:
2708: GNU C provides several language features not found in ANSI standard C.
2709: (The @samp{-pedantic} option directs GNU CC to print a warning message if
2710: any of these features is used.) To test for the availability of these
2711: features in conditional compilation, check for a predefined macro
2712: @code{__GNUC__}, which is always defined under GNU CC.
2713:
2714: @menu
2715: * Statement Exprs:: Putting statements and declarations inside expressions.
2716: * Naming Types:: Giving a name to the type of some expression.
1.1.1.9 root 2717: * Typeof:: @code{typeof}: referring to the type of an expression.
2718: * Lvalues:: Using @samp{?:}, @samp{,} and casts in lvalues.
2719: * Conditionals:: Omitting the middle operand of a @samp{?:} expression.
2720: * Zero-Length:: Zero-length arrays.
2721: * Variable-Length:: Arrays whose length is computed at run time.
2722: * Subscripting:: Any array can be subscripted, even if not an lvalue.
2723: * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers.
2724: * Initializers:: Non-constant initializers.
2725: * Constructors:: Constructor expressions give structures, unions
2726: or arrays as values.
1.1.1.5 root 2727: * Function Attributes:: Declaring that functions have no side effects,
1.1.1.9 root 2728: or that they can never return.
1.1 root 2729: * Dollar Signs:: Dollar sign is allowed in identifiers.
2730: * Alignment:: Inquiring about the alignment of a type or variable.
2731: * Inline:: Defining inline functions (as fast as macros).
1.1.1.9 root 2732: * Extended Asm:: Assembler instructions with C expressions as operands.
2733: (With them you can define ``built-in'' functions.)
2734: * Asm Labels:: Specifying the assembler name to use for a C symbol.
1.1.1.8 root 2735: * Explicit Reg Vars:: Defining variables residing in specified registers.
2736: * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files.
1.1 root 2737: @end menu
2738:
2739: @node Statement Exprs, Naming Types, Extensions, Extensions
2740: @section Statements and Declarations inside of Expressions
2741:
2742: A compound statement in parentheses may appear inside an expression in GNU
2743: C. This allows you to declare variables within an expression. For
2744: example:
2745:
2746: @example
2747: (@{ int y = foo (); int z;
2748: if (y > 0) z = y;
2749: else z = - y;
2750: z; @})
2751: @end example
2752:
2753: @noindent
2754: is a valid (though slightly more complex than necessary) expression
2755: for the absolute value of @code{foo ()}.
2756:
2757: This feature is especially useful in making macro definitions ``safe'' (so
2758: that they evaluate each operand exactly once). For example, the
2759: ``maximum'' function is commonly defined as a macro in standard C as
2760: follows:
2761:
2762: @example
2763: #define max(a,b) ((a) > (b) ? (a) : (b))
2764: @end example
2765:
2766: @noindent
2767: But this definition computes either @var{a} or @var{b} twice, with bad
2768: results if the operand has side effects. In GNU C, if you know the
2769: type of the operands (here let's assume @code{int}), you can define
2770: the macro safely as follows:
2771:
2772: @example
2773: #define maxint(a,b) \
2774: (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
2775: @end example
2776:
2777: Embedded statements are not allowed in constant expressions, such as
2778: the value of an enumeration constant, the width of a bit field, or
2779: the initial value of a static variable.
2780:
2781: If you don't know the type of the operand, you can still do this, but you
2782: must use @code{typeof} (@pxref{Typeof}) or type naming (@pxref{Naming
2783: Types}).
2784:
2785: @node Naming Types, Typeof, Statement Exprs, Extensions
2786: @section Naming an Expression's Type
2787:
2788: You can give a name to the type of an expression using a @code{typedef}
2789: declaration with an initializer. Here is how to define @var{name} as a
2790: type name for the type of @var{exp}:
2791:
2792: @example
2793: typedef @var{name} = @var{exp};
2794: @end example
2795:
2796: This is useful in conjunction with the statements-within-expressions
2797: feature. Here is how the two together can be used to define a safe
2798: ``maximum'' macro that operates on any arithmetic type:
2799:
2800: @example
2801: #define max(a,b) \
2802: (@{typedef _ta = (a), _tb = (b); \
2803: _ta _a = (a); _tb _b = (b); \
2804: _a > _b ? _a : _b; @})
2805: @end example
2806:
2807: The reason for using names that start with underscores for the local
2808: variables is to avoid conflicts with variable names that occur within the
2809: expressions that are substituted for @code{a} and @code{b}. Eventually we
2810: hope to design a new form of declaration syntax that allows you to declare
2811: variables whose scopes start only after their initializers; this will be a
2812: more reliable way to prevent such conflicts.
2813:
2814: @node Typeof, Lvalues, Naming Types, Extensions
2815: @section Referring to a Type with @code{typeof}
2816:
2817: Another way to refer to the type of an expression is with @code{typeof}.
2818: The syntax of using of this keyword looks like @code{sizeof}, but the
2819: construct acts semantically like a type name defined with @code{typedef}.
2820:
2821: There are two ways of writing the argument to @code{typeof}: with an
2822: expression or with a type. Here is an example with an expression:
2823:
2824: @example
2825: typeof (x[0](1))
2826: @end example
2827:
2828: @noindent
2829: This assumes that @code{x} is an array of functions; the type described
2830: is that of the values of the functions.
2831:
2832: Here is an example with a typename as the argument:
2833:
2834: @example
2835: typeof (int *)
2836: @end example
2837:
2838: @noindent
2839: Here the type described is that of pointers to @code{int}.
2840:
1.1.1.7 root 2841: If you are writing a header file that must work when included in ANSI C
1.1.1.8 root 2842: programs, write @code{__typeof__} instead of @code{typeof}.
1.1.1.7 root 2843: @xref{Alternate Keywords}.
2844:
1.1 root 2845: A @code{typeof}-construct can be used anywhere a typedef name could be
2846: used. For example, you can use it in a declaration, in a cast, or inside
2847: of @code{sizeof} or @code{typeof}.
2848:
2849: @itemize @bullet
2850: @item
2851: This declares @code{y} with the type of what @code{x} points to.
2852:
2853: @example
2854: typeof (*x) y;
2855: @end example
2856:
2857: @item
2858: This declares @code{y} as an array of such values.
2859:
2860: @example
2861: typeof (*x) y[4];
2862: @end example
2863:
2864: @item
2865: This declares @code{y} as an array of pointers to characters:
2866:
2867: @example
2868: typeof (typeof (char *)[4]) y;
2869: @end example
2870:
2871: @noindent
2872: It is equivalent to the following traditional C declaration:
2873:
2874: @example
2875: char *y[4];
2876: @end example
2877:
2878: To see the meaning of the declaration using @code{typeof}, and why it
2879: might be a useful way to write, let's rewrite it with these macros:
2880:
2881: @example
2882: #define pointer(T) typeof(T *)
2883: #define array(T, N) typeof(T [N])
2884: @end example
2885:
2886: @noindent
2887: Now the declaration can be rewritten this way:
2888:
2889: @example
2890: array (pointer (char), 4) y;
2891: @end example
2892:
2893: @noindent
1.1.1.8 root 2894: Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
1.1 root 2895: pointers to @code{char}.
2896: @end itemize
2897:
2898: @node Lvalues, Conditionals, Typeof, Extensions
2899: @section Generalized Lvalues
2900:
2901: Compound expressions, conditional expressions and casts are allowed as
2902: lvalues provided their operands are lvalues. This means that you can take
2903: their addresses or store values into them.
2904:
2905: For example, a compound expression can be assigned, provided the last
2906: expression in the sequence is an lvalue. These two expressions are
2907: equivalent:
2908:
2909: @example
2910: (a, b) += 5
2911: a, (b += 5)
2912: @end example
2913:
2914: Similarly, the address of the compound expression can be taken. These two
2915: expressions are equivalent:
2916:
2917: @example
2918: &(a, b)
2919: a, &b
2920: @end example
2921:
2922: A conditional expression is a valid lvalue if its type is not void and the
2923: true and false branches are both valid lvalues. For example, these two
2924: expressions are equivalent:
2925:
2926: @example
2927: (a ? b : c) = 5
2928: (a ? b = 5 : (c = 5))
2929: @end example
2930:
2931: A cast is a valid lvalue if its operand is valid. Taking the address of
2932: the cast is the same as taking the address without a cast, except for the
2933: type of the result. For example, these two expressions are equivalent (but
1.1.1.8 root 2934: the second may be valid when the type of @code{a} does not permit a cast to
2935: @code{int *}).
1.1 root 2936:
2937: @example
2938: &(int *)a
2939: (int **)&a
2940: @end example
2941:
2942: A simple assignment whose left-hand side is a cast works by converting the
2943: right-hand side first to the specified type, then to the type of the inner
2944: left-hand side expression. After this is stored, the value is converter
2945: back to the specified type to become the value of the assignment. Thus, if
1.1.1.8 root 2946: @code{a} has type @code{char *}, the following two expressions are
1.1 root 2947: equivalent:
2948:
2949: @example
2950: (int)a = 5
2951: (int)(a = (char *)5)
2952: @end example
2953:
2954: An assignment-with-arithmetic operation such as @samp{+=} applied to a cast
2955: performs the arithmetic using the type resulting from the cast, and then
2956: continues as in the previous case. Therefore, these two expressions are
2957: equivalent:
2958:
2959: @example
2960: (int)a += 5
2961: (int)(a = (char *) ((int)a + 5))
2962: @end example
2963:
2964: @node Conditionals, Zero-Length, Lvalues, Extensions
2965: @section Conditional Expressions with Omitted Middle-Operands
2966:
2967: The middle operand in a conditional expression may be omitted. Then
2968: if the first operand is nonzero, its value is the value of the conditional
2969: expression.
2970:
2971: Therefore, the expression
2972:
2973: @example
2974: x ? : y
2975: @end example
2976:
2977: @noindent
2978: has the value of @code{x} if that is nonzero; otherwise, the value of
2979: @code{y}.
2980:
2981: This example is perfectly equivalent to
2982:
2983: @example
2984: x ? x : y
2985: @end example
2986:
2987: @noindent
2988: In this simple case, the ability to omit the middle operand is not
2989: especially useful. When it becomes useful is when the first operand does,
2990: or may (if it is a macro argument), contain a side effect. Then repeating
2991: the operand in the middle would perform the side effect twice. Omitting
2992: the middle operand uses the value already computed without the undesirable
2993: effects of recomputing it.
2994:
2995: @node Zero-Length, Variable-Length, Conditionals, Extensions
2996: @section Arrays of Length Zero
2997:
2998: Zero-length arrays are allowed in GNU C. They are very useful as the last
2999: element of a structure which is really a header for a variable-length
3000: object:
3001:
3002: @example
3003: struct line @{
3004: int length;
3005: char contents[0];
3006: @};
3007:
3008: @{
3009: struct line *thisline
3010: = (struct line *) malloc (sizeof (struct line) + this_length);
3011: thisline->length = this_length;
3012: @}
3013: @end example
3014:
3015: In standard C, you would have to give @code{contents} a length of 1, which
3016: means either you waste space or complicate the argument to @code{malloc}.
3017:
3018: @node Variable-Length, Subscripting, Zero-Length, Extensions
3019: @section Arrays of Variable Length
3020:
3021: Variable-length automatic arrays are allowed in GNU C. These arrays are
3022: declared like any other automatic arrays, but with a length that is not a
3023: constant expression. The storage is allocated at that time and
3024: deallocated when the brace-level is exited. For example:
3025:
3026: @example
3027: FILE *concat_fopen (char *s1, char *s2, char *mode)
3028: @{
3029: char str[strlen (s1) + strlen (s2) + 1];
3030: strcpy (str, s1);
3031: strcat (str, s2);
3032: return fopen (str, mode);
3033: @}
3034: @end example
3035:
1.1.1.7 root 3036: You can also use variable-length arrays as arguments to functions:
1.1 root 3037:
3038: @example
3039: struct entry
1.1.1.7 root 3040: tester (int len, char data[len])
1.1 root 3041: @{
1.1.1.7 root 3042: @dots{}
1.1 root 3043: @}
3044: @end example
3045:
3046: The length of an array is computed on entry to the brace-level where the
3047: array is declared and is remembered for the scope of the array in case you
3048: access it with @code{sizeof}.
3049:
3050: Jumping or breaking out of the scope of the array name will also deallocate
3051: the storage. Jumping into the scope is not allowed; you will get an error
3052: message for it.
3053:
3054: You can use the function @code{alloca} to get an effect much like
3055: variable-length arrays. The function @code{alloca} is available in
3056: many other C implementations (but not in all). On the other hand,
3057: variable-length arrays are more elegant.
3058:
3059: There are other differences between these two methods. Space allocated
3060: with @code{alloca} exists until the containing @emph{function} returns.
3061: The space for a variable-length array is deallocated as soon as the array
3062: name's scope ends. (If you use both variable-length arrays and
3063: @code{alloca} in the same function, deallocation of a variable-length array
3064: will also deallocate anything more recently allocated with @code{alloca}.)
3065:
3066: @node Subscripting, Pointer Arith, Variable-Length, Extensions
3067: @section Non-Lvalue Arrays May Have Subscripts
3068:
3069: Subscripting is allowed on arrays that are not lvalues, even though the
3070: unary @samp{&} operator is not. For example, this is valid in GNU C though
3071: not valid in other C dialects:
3072:
3073: @example
3074: struct foo @{int a[4];@};
3075:
3076: struct foo f();
3077:
3078: bar (int index)
3079: @{
3080: return f().a[index];
3081: @}
3082: @end example
3083:
3084: @node Pointer Arith, Initializers, Subscripting, Extensions
3085: @section Arithmetic on @code{void}-Pointers and Function Pointers
3086:
3087: In GNU C, addition and subtraction operations are supported on pointers to
3088: @code{void} and on pointers to functions. This is done by treating the
3089: size of a @code{void} or of a function as 1.
3090:
3091: A consequence of this is that @code{sizeof} is also allowed on @code{void}
3092: and on function types, and returns 1.
3093:
1.1.1.8 root 3094: The option @samp{-Wpointer-arith} requests a warning if these extensions
3095: are used.
3096:
1.1 root 3097: @node Initializers, Constructors, Pointer Arith, Extensions
3098: @section Non-Constant Initializers
3099:
1.1.1.8 root 3100: The elements of an aggregate initializer for an automatic variable are
3101: not required to be constant expressions in GNU C. Here is an example of
3102: an initializer with run-time varying elements:
1.1 root 3103:
3104: @example
3105: foo (float f, float g)
3106: @{
3107: float beat_freqs[2] = @{ f-g, f+g @};
3108: @dots{}
3109: @}
3110: @end example
3111:
1.1.1.5 root 3112: @node Constructors, Function Attributes, Initializers, Extensions
1.1 root 3113: @section Constructor Expressions
3114:
3115: GNU C supports constructor expressions. A constructor looks like a cast
3116: containing an initializer. Its value is an object of the type specified in
3117: the cast, containing the elements specified in the initializer. The type
3118: must be a structure, union or array type.
3119:
3120: Assume that @code{struct foo} and @code{structure} are declared as shown:
3121:
3122: @example
3123: struct foo @{int a; char b[2];@} structure;
3124: @end example
3125:
3126: @noindent
1.1.1.8 root 3127: Here is an example of constructing a @code{struct foo} with a constructor:
1.1 root 3128:
3129: @example
3130: structure = ((struct foo) @{x + y, 'a', 0@});
3131: @end example
3132:
3133: @noindent
3134: This is equivalent to writing the following:
3135:
3136: @example
3137: @{
3138: struct foo temp = @{x + y, 'a', 0@};
3139: structure = temp;
3140: @}
3141: @end example
3142:
3143: You can also construct an array. If all the elements of the constructor
3144: are (made up of) simple constant expressions, suitable for use in
3145: initializers, then the constructor is an lvalue and can be coerced to a
3146: pointer to its first element, as shown here:
3147:
3148: @example
3149: char **foo = (char *[]) @{ "x", "y", "z" @};
3150: @end example
3151:
3152: Array constructors whose elements are not simple constants are not very
3153: useful, because the constructor is not an lvalue. There are only two valid
3154: ways to use it: to subscript it, or initialize an array variable with it.
3155: The former is probably slower than a @code{switch} statement, while the
3156: latter does the same thing an ordinary C initializer would do.
3157:
3158: @example
3159: output = ((int[]) @{ 2, x, 28 @}) [input];
3160: @end example
3161:
1.1.1.8 root 3162: @node Function Attributes, Dollar Signs, Constructors, Extensions
1.1.1.5 root 3163: @section Declaring Attributes of Functions
3164:
3165: In GNU C, you declare certain things about functions called in your program
3166: which help the compiler optimize function calls.
3167:
3168: A few functions, such as @code{abort} and @code{exit}, cannot return.
3169: These functions should be declared @code{volatile}. For example,
3170:
3171: @example
3172: extern volatile void abort ();
3173: @end example
3174:
3175: @noindent
3176: tells the compiler that it can assume that @code{abort} will not return.
3177: This makes slightly better code, but more importantly it helps avoid
3178: spurious warnings of uninitialized variables.
3179:
3180: Many functions do not examine any values except their arguments, and
3181: have no effects except the return value. Such a function can be subject
3182: to common subexpression elimination and loop optimization just as an
3183: arithmetic operator would be. These functions should be declared
3184: @code{const}. For example,
3185:
3186: @example
3187: extern const void square ();
3188: @end example
3189:
3190: @noindent
3191: says that the hypothetical function @code{square} is safe to call
3192: fewer times than the program says.
3193:
3194: Note that a function that has pointer arguments and examines the data
3195: pointed to must @emph{not} be declared @code{const}. Likewise, a
1.1.1.10 root 3196: function that calls a non-@code{const} function usually must not be
1.1.1.5 root 3197: @code{const}.
3198:
3199: Some people object to this feature, claiming that ANSI C's @code{#pragma}
3200: should be used instead. There are two reasons I did not do this.
3201:
3202: @enumerate
3203: @item
3204: It is impossible to generate @code{#pragma} commands from a macro.
3205:
3206: @item
3207: The @code{#pragma} command is just as likely as these keywords to mean
3208: something else in another compiler.
3209: @end enumerate
3210:
3211: These two reasons apply to @emph{any} application whatever: as far as
3212: I can see, @code{#pragma} is never useful.
3213:
3214: @node Dollar Signs, Alignment, Function Attributes, Extensions
1.1 root 3215: @section Dollar Signs in Identifier Names
3216:
3217: In GNU C, you may use dollar signs in identifier names. This is because
3218: many traditional C implementations allow such identifiers.
3219:
1.1.1.9 root 3220: Dollar signs are allowed if you specify @samp{-traditional}; they are
3221: not allowed if you specify @samp{-ansi}. Whether they are allowed by
3222: default depends on the target machine; usually, they are not.
3223:
1.1 root 3224: @node Alignment, Inline, Dollar Signs, Extensions
3225: @section Inquiring about the Alignment of a Type or Variable
3226:
1.1.1.8 root 3227: The keyword @code{__alignof__} allows you to inquire about how an object
1.1 root 3228: is aligned, or the minimum alignment usually required by a type. Its
3229: syntax is just like @code{sizeof}.
3230:
3231: For example, if the target machine requires a @code{double} value to be
1.1.1.8 root 3232: aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
3233: This is true on many RISC machines. On more traditional machine
3234: designs, @code{__alignof__ (double)} is 4 or even 2.
1.1 root 3235:
3236: Some machines never actually require alignment; they allow reference to any
1.1.1.8 root 3237: data type even at an odd addresses. For these machines, @code{__alignof__}
1.1 root 3238: reports the @emph{recommended} alignment of a type.
3239:
1.1.1.8 root 3240: When the operand of @code{__alignof__} is an lvalue rather than a type, the
1.1 root 3241: value is the largest alignment that the lvalue is known to have. It may
3242: have this alignment as a result of its data type, or because it is part of
3243: a structure and inherits alignment from that structure. For example, after
3244: this declaration:
3245:
3246: @example
3247: struct foo @{ int x; char y; @} foo1;
3248: @end example
3249:
3250: @noindent
1.1.1.8 root 3251: the value of @code{__alignof__ (foo1.y)} is probably 2 or 4, the same as
3252: @code{__alignof__ (int)}, even though the data type of @code{foo1.y}
3253: does not itself demand any alignment.@refill
1.1 root 3254:
3255: @node Inline, Extended Asm, Alignment, Extensions
3256: @section An Inline Function is As Fast As a Macro
3257:
3258: By declaring a function @code{inline}, you can direct GNU CC to integrate
3259: that function's code into the code for its callers. This makes execution
3260: faster by eliminating the function-call overhead; in addition, if any of
3261: the actual argument values are constant, their known values may permit
3262: simplifications at compile time so that not all of the inline function's
3263: code needs to be included.
3264:
3265: To declare a function inline, use the @code{inline} keyword in its
3266: declaration, like this:
3267:
3268: @example
3269: inline int
3270: inc (int *a)
3271: @{
3272: (*a)++;
3273: @}
3274: @end example
3275:
1.1.1.7 root 3276: (If you are writing a header file to be included in ANSI C programs, write
1.1.1.8 root 3277: @code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.)
1.1.1.7 root 3278:
3279: You can also make all ``simple enough'' functions inline with the option
3280: @samp{-finline-functions}. Note that certain usages in a function
3281: definition can make it unsuitable for inline substitution.
1.1 root 3282:
3283: When a function is both inline and @code{static}, if all calls to the
1.1.1.8 root 3284: function are integrated into the caller, and the function's address is
3285: never used, then the function's own assembler code is never referenced.
3286: In this case, GNU CC does not actually output assembler code for the
3287: function, unless you specify the option @samp{-fkeep-inline-functions}.
3288: Some calls cannot be integrated for various reasons (in particular,
3289: calls that precede the function's definition cannot be integrated, and
3290: neither can recursive calls within the definition). If there is a
3291: nonintegrated call, then the function is compiled to assembler code as
3292: usual. The function must also be compiled as usual if the program
3293: refers to its address, because that can't be inlined.
1.1 root 3294:
3295: When an inline function is not @code{static}, then the compiler must assume
3296: that there may be calls from other source files; since a global symbol can
3297: be defined only once in any program, the function must not be defined in
3298: the other source files, so the calls therein cannot be integrated.
3299: Therefore, a non-@code{static} inline function is always compiled on its
3300: own in the usual fashion.
3301:
1.1.1.8 root 3302: If you specify both @code{inline} and @code{extern} in the function
3303: definition, then the definition is used only for inlining. In no case
3304: is the function compiled on its own, not even if you refer to its
3305: address explicitly. Such an address becomes an external reference, as
3306: if you had only declared the function, and had not defined it.
3307:
3308: This combination of @code{inline} and @code{extern} has almost the
3309: effect of a macro. The way to use it is to put a function definition in
3310: a header file with these keywords, and put another copy of the
3311: definition (lacking @code{inline} and @code{extern}) in a library file.
3312: The definition in the header file will cause most calls to the function
3313: to be inlined. If any uses of the function remain, they will refer to
3314: the single copy in the library.
3315:
1.1 root 3316: @node Extended Asm, Asm Labels, Inline, Extensions
3317: @section Assembler Instructions with C Expression Operands
3318:
3319: In an assembler instruction using @code{asm}, you can now specify the
3320: operands of the instruction using C expressions. This means no more
3321: guessing which registers or memory locations will contain the data you want
3322: to use.
3323:
3324: You must specify an assembler instruction template much like what appears
3325: in a machine description, plus an operand constraint string for each
3326: operand.
3327:
3328: For example, here is how to use the 68881's @code{fsinx} instruction:
3329:
3330: @example
3331: asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
3332: @end example
3333:
3334: @noindent
3335: Here @code{angle} is the C expression for the input operand while
3336: @code{result} is that of the output operand. Each has @samp{"f"} as its
3337: operand constraint, saying that a floating-point register is required. The
1.1.1.5 root 3338: @samp{=} in @samp{=f} indicates that the operand is an output; all output
1.1.1.4 root 3339: operands' constraints must use @samp{=}. The constraints use the same
3340: language used in the machine description (@pxref{Constraints}).
1.1 root 3341:
3342: Each operand is described by an operand-constraint string followed by the C
3343: expression in parentheses. A colon separates the assembler template from
3344: the first output operand, and another separates the last output operand
3345: from the first input, if any. Commas separate output operands and separate
1.1.1.4 root 3346: inputs. The total number of operands is limited to the maximum number of
1.1 root 3347: operands in any instruction pattern in the machine description.
3348:
1.1.1.4 root 3349: If there are no output operands, and there are input operands, then there
3350: must be two consecutive colons surrounding the place where the output
3351: operands would go.
3352:
1.1 root 3353: Output operand expressions must be lvalues; the compiler can check this.
3354: The input operands need not be lvalues. The compiler cannot check whether
3355: the operands have data types that are reasonable for the instruction being
3356: executed. It does not parse the assembler instruction template and does
3357: not know what it means, or whether it is valid assembler input. The
3358: extended @code{asm} feature is most often used for machine instructions
3359: that the compiler itself does not know exist.
3360:
3361: The output operands must be write-only; GNU CC will assume that the values
3362: in these operands before the instruction are dead and need not be
1.1.1.8 root 3363: generated. Extended asm does not support input-output or read-write
3364: operands. For this reason, the constraint character @samp{+}, which
3365: indicates such an operand, may not be used.
3366:
3367: When the assembler instruction has a read-write operand, or an operand
3368: in which only some of the bits are to be changed, you must logically
1.1 root 3369: split its function into two separate operands, one input operand and one
3370: write-only output operand. The connection between them is expressed by
3371: constraints which say they need to be in the same location when the
1.1.1.8 root 3372: instruction executes. You can use the same C expression for both
3373: operands, or different expressions. For example, here we write the
3374: (fictitious) @samp{combine} instruction with @code{bar} as its read-only
3375: source operand and @code{foo} as its read-write destination:
1.1 root 3376:
3377: @example
3378: asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
3379: @end example
3380:
3381: @noindent
3382: The constraint @samp{"0"} for operand 1 says that it must occupy the same
1.1.1.5 root 3383: location as operand 0. A digit in constraint is allowed only in an input
3384: operand, and it must refer to an output operand.
1.1 root 3385:
3386: Only a digit in the constraint can guarantee that one operand will be in
3387: the same place as another. The mere fact that @code{foo} is the value of
3388: both operands is not enough to guarantee that they will be in the same
3389: place in the generated assembler code. The following would not work:
3390:
3391: @example
3392: asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
3393: @end example
3394:
3395: Various optimizations or reloading could cause operands 0 and 1 to be in
3396: different registers; GNU CC knows no reason not to do so. For example, the
3397: compiler might find a copy of the value of @code{foo} in one register and
3398: use it for operand 1, but generate the output operand 0 in a different
3399: register (copying it afterward to @code{foo}'s own address). Of course,
3400: since the register for operand 1 is not even mentioned in the assembler
3401: code, the result will not work, but GNU CC can't tell that.
3402:
3403: Unless an output operand has the @samp{&} constraint modifier, GNU CC may
3404: allocate it in the same register as an unrelated input operand, on the
3405: assumption that the inputs are consumed before the outputs are produced.
3406: This assumption may be false if the assembler code actually consists of
3407: more than one instruction. In such a case, use @samp{&} for each output
3408: operand that may not overlap an input. @xref{Modifiers}.
3409:
1.1.1.4 root 3410: Some instructions clobber specific hard registers. To describe this, write
3411: a third colon after the input operands, followed by the names of the
3412: clobbered hard registers (given as strings). Here is a realistic example
3413: for the vax:
1.1 root 3414:
3415: @example
3416: asm volatile ("movc3 %0,%1,%2"
3417: : /* no outputs */
3418: : "g" (from), "g" (to), "g" (count)
3419: : "r0", "r1", "r2", "r3", "r4", "r5");
3420: @end example
3421:
1.1.1.4 root 3422: You can put multiple assembler instructions together in a single @code{asm}
1.1.1.7 root 3423: template, separated either with newlines (written as @samp{\n}) or with
3424: semicolons if the assembler allows such semicolons. The GNU assembler
3425: allows semicolons and all Unix assemblers seem to do so. The input
3426: operands are guaranteed not to use any of the clobbered registers, and
3427: neither will the output operands' addresses, so you can read and write the
3428: clobbered registers as many times as you like. Here is an example of
3429: multiple instructions in a template; it assumes that the subroutine
3430: @code{_foo} accepts arguments in registers 9 and 10:
1.1.1.4 root 3431:
3432: @example
3433: asm ("movl %0,r9;movl %1,r10;call _foo"
3434: : /* no outputs */
3435: : "g" (from), "g" (to)
3436: : "r9", "r10");
3437: @end example
3438:
1.1.1.7 root 3439: If you want to test the condition code produced by an assembler instruction,
3440: you must include a branch and a label in the @code{asm} construct, as follows:
3441:
3442: @example
3443: asm ("clr %0;frob %1;beq 0f;mov #1,%0;0:"
3444: : "g" (result)
3445: : "g" (input));
3446: @end example
3447:
3448: @noindent
3449: This assumes your assembler supports local labels, as the GNU assembler
3450: and most Unix assemblers do.
3451:
1.1 root 3452: Usually the most convenient way to use these @code{asm} instructions is to
3453: encapsulate them in macros that look like functions. For example,
3454:
3455: @example
3456: #define sin(x) \
3457: (@{ double __value, __arg = (x); \
3458: asm ("fsinx %1,%0": "=f" (__value): "f" (__arg)); \
3459: __value; @})
3460: @end example
3461:
3462: @noindent
3463: Here the variable @code{__arg} is used to make sure that the instruction
3464: operates on a proper @code{double} value, and to accept only those
3465: arguments @code{x} which can convert automatically to a @code{double}.
3466:
3467: Another way to make sure the instruction operates on the correct data type
3468: is to use a cast in the @code{asm}. This is different from using a
3469: variable @code{__arg} in that it converts more different types. For
3470: example, if the desired type were @code{int}, casting the argument to
3471: @code{int} would accept a pointer with no complaint, while assigning the
3472: argument to an @code{int} variable named @code{__arg} would warn about
3473: using a pointer unless the caller explicitly casts it.
3474:
1.1.1.4 root 3475: If an @code{asm} has output operands, GNU CC assumes for optimization
3476: purposes that the instruction has no side effects except to change the
3477: output operands. This does not mean that instructions with a side effect
3478: cannot be used, but you must be careful, because the compiler may eliminate
3479: them if the output operands aren't used, or move them out of loops, or
3480: replace two with one if they constitute a common subexpression. Also, if
3481: your instruction does have a side effect on a variable that otherwise
3482: appears not to change, the old value of the variable may be reused later if
3483: it happens to be found in a register.
1.1 root 3484:
3485: You can prevent an @code{asm} instruction from being deleted, moved or
3486: combined by writing the keyword @code{volatile} after the @code{asm}. For
3487: example:
3488:
3489: @example
3490: #define set_priority(x) \
3491: asm volatile ("set_priority %0": /* no outputs */ : "g" (x))
3492: @end example
3493:
1.1.1.7 root 3494: @noindent
3495: (However, an instruction without output operands will not be deleted
3496: or moved, regardless, unless it is unreachable.)
1.1.1.4 root 3497:
1.1 root 3498: It is a natural idea to look for a way to give access to the condition
3499: code left by the assembler instruction. However, when we attempted to
3500: implement this, we found no way to make it work reliably. The problem
3501: is that output operands might need reloading, which would result in
3502: additional following ``store'' instructions. On most machines, these
3503: instructions would alter the condition code before there was time to
3504: test it. This problem doesn't arise for ordinary ``test'' and
3505: ``compare'' instructions because they don't have any output operands.
3506:
1.1.1.7 root 3507: If you are writing a header file that should be includable in ANSI C
1.1.1.8 root 3508: programs, write @code{__asm__} instead of @code{asm}. @xref{Alternate
1.1.1.7 root 3509: Keywords}.
3510:
1.1.1.8 root 3511: @node Asm Labels, Explicit Reg Vars, Extended Asm, Extensions
1.1 root 3512: @section Controlling Names Used in Assembler Code
3513:
1.1.1.8 root 3514: You can specify the name to be used in the assembler code for a C
3515: function or variable by writing the @code{asm} (or @code{__asm__})
3516: keyword after the declarator as follows:
1.1 root 3517:
3518: @example
3519: int foo asm ("myfoo") = 2;
3520: @end example
3521:
3522: @noindent
3523: This specifies that the name to be used for the variable @code{foo} in
3524: the assembler code should be @samp{myfoo} rather than the usual
3525: @samp{_foo}.
3526:
3527: On systems where an underscore is normally prepended to the name of a C
3528: function or variable, this feature allows you to define names for the
3529: linker that do not start with an underscore.
3530:
3531: You cannot use @code{asm} in this way in a function @emph{definition}; but
3532: you can get the same effect by writing a declaration for the function
3533: before its definition and putting @code{asm} there, like this:
3534:
3535: @example
3536: extern func () asm ("FUNC");
3537:
3538: func (x, y)
3539: int x, y;
3540: @dots{}
3541: @end example
3542:
3543: It is up to you to make sure that the assembler names you choose do not
3544: conflict with any other assembler symbols. Also, you must not use a
3545: register name; that would produce completely invalid assembler code. GNU
3546: CC does not as yet have the ability to store static variables in registers.
3547: Perhaps that will be added.
3548:
1.1.1.8 root 3549: @node Explicit Reg Vars, Alternate Keywords, Asm Labels, Extensions
3550: @section Variables in Specified Registers
3551:
3552: GNU C allows you to put a few global variables into specified hardware
3553: registers. You can also specify the register in which an ordinary
3554: register variable should be allocated.
3555:
3556: @itemize @bullet
3557: @item
3558: Global register variables reserve registers throughout the program.
3559: This may be useful in programs such as programming language
3560: interpreters which have a couple of global variables that are accessed
3561: very often.
3562:
3563: @item
3564: Local register variables in specific registers do not reserve the
3565: registers. The compiler's data flow analysis is capable of
3566: determining where the specified registers contain live values, and
3567: where they are available for other uses. These local variables are
3568: sometimes convenient for use with the extended @code{asm} feature
3569: (@pxref{Extended Asm}).
3570: @end itemize
3571:
3572: @menu
3573: * Global Reg Vars::
3574: * Local Reg Vars::
3575: @end menu
1.1.1.5 root 3576:
1.1.1.8 root 3577: @node Global Reg Vars, Local Reg Vars, Explicit Reg Vars, Explicit Reg Vars
3578: @subsection Defining Global Register Variables
1.1.1.5 root 3579:
3580: You can define a global register variable in GNU C like this:
3581:
3582: @example
3583: register int *foo asm ("a5");
3584: @end example
3585:
3586: @noindent
3587: Here @code{a5} is the name of the register which should be used. Choose a
3588: register which is normally saved and restored by function calls on your
3589: machine, so that library routines will not clobber it.
3590:
3591: Naturally the register name is cpu-dependent, so you would need to
3592: conditionalize your program according to cpu type. The register
3593: @code{a5} would be a good choice on a 68000 for a variable of pointer
3594: type. On machines with register windows, be sure to choose a ``global''
1.1.1.8 root 3595: register that is not affected magically by the function call mechanism.
1.1.1.5 root 3596:
3597: In addition, operating systems on one type of cpu may differ in how they
3598: name the registers; then you would need additional conditionals. For
3599: example, some 68000 operating systems call this register @code{%a5}.
3600:
3601: Eventually there may be a way of asking the compiler to choose a register
3602: automatically, but first we need to figure out how it should choose and
1.1.1.6 root 3603: how to enable you to guide the choice. No solution is evident.
1.1.1.5 root 3604:
3605: Defining a global register variable in a certain register reserves that
3606: register entirely for this use, at least within the current compilation.
3607: The register will not be allocated for any other purpose in the functions
3608: in the current compilation. The register will not be saved and restored by
3609: these functions. Stores into this register are never deleted even if they
3610: would appear to be dead, but references may be deleted or moved or
3611: simplified.
3612:
3613: It is not safe to access the global register variables from signal
3614: handlers, or from more than one thread of control, because the system
3615: library routines may temporarily use the register for other things (unless
3616: you recompile them specially for the task at hand).
3617:
3618: It is not safe for one function that uses a global register variable to
3619: call another such function @code{foo} by way of a third function
3620: @code{lose} that was compiled without knowledge of this variable (i.e. in a
3621: different source file in which the variable wasn't declared). This is
3622: because @code{lose} might save the register and put some other value there.
3623: For example, you can't expect a global register variable to be available in
3624: the comparison-function that you pass to @code{qsort}, since @code{qsort}
3625: might have put something else in that register. (If you are prepared to
3626: recompile @code{qsort} with the same global register variable, you can
3627: solve this problem.)
3628:
3629: If you want to recompile @code{qsort} or other source files which do not
3630: actually use your global register variable, so that they will not use that
3631: register for any other purpose, then it suffices to specify the compiler
3632: option @samp{-ffixed-@var{reg}}. You need not actually add a global
3633: register declaration to their source code.
3634:
3635: A function which can alter the value of a global register variable cannot
3636: safely be called from a function compiled without this variable, because it
3637: could clobber the value the caller expects to find there on return.
3638: Therefore, the function which is the entry point into the part of the
3639: program that uses the global register variable must explicitly save and
3640: restore the value which belongs to its caller.
3641:
3642: On most machines, @code{longjmp} will restore to each global register
3643: variable the value it had at the time of the @code{setjmp}. On some
3644: machines, however, @code{longjmp} will not change the value of global
3645: register variables. To be portable, the function that called @code{setjmp}
3646: should make other arrangements to save the values of the global register
1.1.1.10 root 3647: variables, and to restore them in a @code{longjmp}. This way, the same
1.1.1.5 root 3648: thing will happen regardless of what @code{longjmp} does.
3649:
3650: All global register variable declarations must precede all function
3651: definitions. If such a declaration could appear after function
3652: definitions, the declaration would be too late to prevent the register from
3653: being used for other purposes in the preceding functions.
3654:
1.1.1.6 root 3655: Global register variables may not have initial values, because an
3656: executable file has no means to supply initial contents for a register.
3657:
1.1.1.9 root 3658: @node Local Reg Vars,, Global Reg Vars, Explicit Reg Vars
1.1.1.8 root 3659: @subsection Specifying Registers for Local Variables
3660:
3661: You can define a local register variable with a specified register
3662: like this:
3663:
3664: @example
3665: register int *foo asm ("a5");
3666: @end example
3667:
3668: @noindent
3669: Here @code{a5} is the name of the register which should be used. Note
3670: that this is the same syntax used for defining global register
3671: variables, but for a local variable it would appear within a function.
3672:
3673: Naturally the register name is cpu-dependent, but this is not a
3674: problem, since specific registers are most often useful with explicit
3675: assembler instructions (@pxref{Extended Asm}). Both of these things
3676: generally require that you conditionalize your program according to
3677: cpu type.
3678:
3679: In addition, operating systems on one type of cpu may differ in how they
3680: name the registers; then you would need additional conditionals. For
3681: example, some 68000 operating systems call this register @code{%a5}.
3682:
3683: Eventually there may be a way of asking the compiler to choose a register
3684: automatically, but first we need to figure out how it should choose and
3685: how to enable you to guide the choice. No solution is evident.
3686:
3687: Defining such a register variable does not reserve the register; it
1.1.1.10 root 3688: remains available for other uses in places where flow control determines
3689: the variable's value is not live. However, these registers are made
3690: unavailable for use in the reload pass. I would not be surprised if
3691: excessive use of this feature leaves the compiler too few available
1.1.1.8 root 3692: registers to compile certain functions.
3693:
3694: @node Alternate Keywords,, Explicit Reg Vars, Extensions
1.1.1.7 root 3695: @section Alternate Keywords
3696:
3697: The option @samp{-traditional} disables certain keywords; @samp{-ansi}
3698: disables certain others. This causes trouble when you want to use GNU C
3699: extensions, or ANSI C features, in a general-purpose header file that
3700: should be usable by all programs, including ANSI C programs and traditional
3701: ones. The keywords @code{asm}, @code{typeof} and @code{inline} cannot be
3702: used since they won't work in a program compiled with @samp{-ansi}, while
3703: the keywords @code{const}, @code{volatile}, @code{signed}, @code{typeof}
3704: and @code{inline} won't work in a program compiled with
3705: @samp{-traditional}.@refill
3706:
1.1.1.8 root 3707: The way to solve these problems is to put @samp{__} at the beginning and
3708: end of each problematical keyword. For example, use @code{__asm__}
3709: instead of @code{asm}, @code{__const__} instead of @code{const}, and
3710: @code{__inline__} instead of @code{inline}.
1.1.1.7 root 3711:
3712: Other C compilers won't accept these alternative keywords; if you want to
3713: compile with another compiler, you can define the alternate keywords as
3714: macros to replace them with the customary keywords. It looks like this:
3715:
3716: @example
3717: #ifndef __GNUC__
1.1.1.8 root 3718: #define __asm__ asm
1.1.1.7 root 3719: #endif
3720: @end example
3721:
1.1 root 3722: @node Bugs, Portability, Extensions, Top
3723: @chapter Reporting Bugs
3724:
3725: Your bug reports play an essential role in making GNU CC reliable.
3726:
1.1.1.11 root 3727: When you encounter a problem, the first thing to do is to see if it is
3728: already known. @xref{Trouble}. Also look in @ref{Incompatibilities}.
3729: If it isn't known, then you should report the problem.
3730:
3731: Reporting a bug may help you by bringing a solution to your problem, or
3732: it may not. (If it does not, look in the service directory; see
3733: @ref{Service}.) In any case, the principal function of a bug report
3734: is to help the entire community by making the next version of GNU CC
3735: work better. Bug reports are your contribution to the maintenance of
3736: GNU CC.
1.1 root 3737:
3738: In order for a bug report to serve its purpose, you must include the
3739: information that makes for fixing the bug.
3740:
3741: @menu
3742: * Criteria: Bug Criteria. Have you really found a bug?
3743: * Reporting: Bug Reporting. How to report a bug effectively.
3744: @end menu
3745:
3746: @node Bug Criteria, Bug Reporting, Bugs, Bugs
3747: @section Have You Found a Bug?
3748:
3749: If you are not sure whether you have found a bug, here are some guidelines:
3750:
3751: @itemize @bullet
3752: @item
3753: If the compiler gets a fatal signal, for any input whatever, that is a
3754: compiler bug. Reliable compilers never crash.
3755:
3756: @item
3757: If the compiler produces invalid assembly code, for any input whatever
3758: (except an @code{asm} statement), that is a compiler bug, unless the
3759: compiler reports errors (not just warnings) which would ordinarily
3760: prevent the assembler from being run.
3761:
3762: @item
3763: If the compiler produces valid assembly code that does not correctly
3764: execute the input source code, that is a compiler bug.
3765:
3766: However, you must double-check to make sure, because you may have run
3767: into an incompatibility between GNU C and traditional C
3768: (@pxref{Incompatibilities}). These incompatibilities might be considered
3769: bugs, but they are inescapable consequences of valuable features.
3770:
3771: Or you may have a program whose behavior is undefined, which happened
3772: by chance to give the desired results with another C compiler.
3773:
3774: For example, in many nonoptimizing compilers, you can write @samp{x;}
3775: at the end of a function instead of @samp{return x;}, with the same
1.1.1.8 root 3776: results. But the value of the function is undefined if @code{return}
1.1 root 3777: is omitted; it is not a bug when GNU CC produces different results.
3778:
3779: Problems often result from expressions with two increment operators,
1.1.1.8 root 3780: as in @code{f (*p++, *p++)}. Your previous compiler might have
1.1 root 3781: interpreted that expression the way you intended; GNU CC might
1.1.1.8 root 3782: interpret it another way. Neither compiler is wrong. The bug is
3783: in your code.
1.1 root 3784:
3785: After you have localized the error to a single source line, it should
3786: be easy to check for these things. If your program is correct and
3787: well defined, you have found a compiler bug.
3788:
3789: @item
3790: If the compiler produces an error message for valid input, that is a
3791: compiler bug.
3792:
3793: Note that the following is not valid input, and the error message for
3794: it is not a bug:
3795:
3796: @example
3797: int foo (char);
3798:
3799: int
3800: foo (x)
3801: char x;
3802: @{ @dots{} @}
3803: @end example
3804:
3805: @noindent
3806: The prototype says to pass a @code{char}, while the definition says to
3807: pass an @code{int} and treat the value as a @code{char}. This is what
3808: the ANSI standard says, and it makes sense.
3809:
3810: @item
3811: If the compiler does not produce an error message for invalid input,
3812: that is a compiler bug. However, you should note that your idea of
3813: ``invalid input'' might be my idea of ``an extension'' or ``support
3814: for traditional practice''.
3815:
3816: @item
3817: If you are an experienced user of C compilers, your suggestions
3818: for improvement of GNU CC are welcome in any case.
3819: @end itemize
3820:
3821: @node Bug Reporting,, Bug Criteria, Bugs
3822: @section How to Report Bugs
3823:
3824: Send bug reports for GNU C to one of these addresses:
3825:
3826: @example
3827: bug-gcc@@prep.ai.mit.edu
3828: @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gcc
3829: @end example
3830:
1.1.1.12! root 3831: @strong{Do not send bug reports to @samp{help-gcc}, or to the newsgroup
! 3832: @samp{gnu.gcc.help}.} Most users of GNU CC do not want to receive bug
1.1.1.8 root 3833: reports. Those that do, have asked to be on @samp{bug-gcc}.
3834:
3835: The mailing list @samp{bug-gcc} has a newsgroup which serves as a
3836: repeater. The mailing list and the newsgroup carry exactly the same
3837: messages. Often people think of posting bug reports to the newsgroup
3838: instead of mailing them. This appears to work, but it has one problem
3839: which can be crucial: a newsgroup posting does not contain a mail path
3840: back to the sender. Thus, if I need to ask for more information, I
3841: may be unable to reach you. For this reason, it is better to send bug
3842: reports to the mailing list.
3843:
3844: As a last resort, send bug reports on paper to:
1.1 root 3845:
3846: @example
3847: GNU Compiler Bugs
1.1.1.12! root 3848: Free Software Foundation
! 3849: 675 Mass Ave
1.1 root 3850: Cambridge, MA 02139
3851: @end example
3852:
3853: The fundamental principle of reporting bugs usefully is this:
1.1.1.8 root 3854: @strong{report all the facts}. If you are not sure whether to state a
3855: fact or leave it out, state it!
1.1 root 3856:
3857: Often people omit facts because they think they know what causes the
3858: problem and they conclude that some details don't matter. Thus, you might
3859: assume that the name of the variable you use in an example does not matter.
3860: Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a
3861: stray memory reference which happens to fetch from the location where that
3862: name is stored in memory; perhaps, if the name were different, the contents
3863: of that location would fool the compiler into doing the right thing despite
1.1.1.8 root 3864: the bug. Play it safe and give a specific, complete example. That is the
3865: easiest thing for you to do, and the most helpful.
1.1 root 3866:
1.1.1.8 root 3867: Keep in mind that the purpose of a bug report is to enable me to fix
3868: the bug if it is not known. It isn't very important what happens if
3869: the bug is already known. Therefore, always write your bug reports on
3870: the assumption that the bug is not known.
3871:
3872: Sometimes people give a few sketchy facts and ask, ``Does this ring a
3873: bell?'' Those bug reports are useless, and I urge everyone to
3874: @emph{refuse to respond to them} except to chide the sender to report
3875: bugs properly.
3876:
3877: To enable me to fix the bug, you should include all these things:
1.1 root 3878:
3879: @itemize @bullet
3880: @item
3881: The version of GNU CC. You can get this by running it with the
3882: @samp{-v} option.
3883:
3884: Without this, I won't know whether there is any point in looking for
3885: the bug in the current version of GNU CC.
3886:
3887: @item
3888: A complete input file that will reproduce the bug. If the bug is in
3889: the C preprocessor, send me a source file and any header files that it
3890: requires. If the bug is in the compiler proper (@file{cc1}), run your
3891: source file through the C preprocessor by doing @samp{gcc -E
3892: @var{sourcefile} > @var{outfile}}, then include the contents of
3893: @var{outfile} in the bug report. (Any @samp{-I}, @samp{-D} or
3894: @samp{-U} options that you used in actual compilation should also be
3895: used when doing this.)
3896:
3897: A single statement is not enough of an example. In order to compile
3898: it, it must be embedded in a function definition; and the bug might
3899: depend on the details of how this is done.
3900:
3901: Without a real example I can compile, all I can do about your bug
3902: report is wish you luck. It would be futile to try to guess how to
3903: provoke the bug. For example, bugs in register allocation and
3904: reloading frequently depend on every little detail of the function
3905: they happen in.
3906:
3907: @item
3908: The command arguments you gave GNU CC to compile that example and
3909: observe the bug. For example, did you use @samp{-O}? To guarantee
3910: you won't omit something important, list them all.
3911:
3912: If I were to try to guess the arguments, I would probably guess wrong
3913: and then I would not encounter the bug.
3914:
3915: @item
3916: The names of the files that you used for @file{tm.h} and @file{md}
3917: when you installed the compiler.
3918:
3919: @item
3920: The type of machine you are using, and the operating system name and
3921: version number.
3922:
3923: @item
3924: A description of what behavior you observe that you believe is
3925: incorrect. For example, ``It gets a fatal signal,'' or, ``There is an
3926: incorrect assembler instruction in the output.''
3927:
3928: Of course, if the bug is that the compiler gets a fatal signal, then I
3929: will certainly notice it. But if the bug is incorrect output, I might
3930: not notice unless it is glaringly wrong. I won't study all the
3931: assembler code from a 50-line C program just on the off chance that it
3932: might be wrong.
3933:
3934: Even if the problem you experience is a fatal signal, you should still
3935: say so explicitly. Suppose something strange is going on, such as,
3936: your copy of the compiler is out of synch, or you have encountered a
3937: bug in the C library on your system. (This has happened!) Your copy
3938: might crash and mine would not. If you @i{told} me to expect a crash,
3939: then when mine fails to crash, I would know that the bug was not
3940: happening for me. If you had not told me to expect a crash, then I
3941: would not be able to draw any conclusion from my observations.
3942:
1.1.1.8 root 3943: Often the observed symptom is incorrect output when your program is run.
3944: Sad to say, this is not enough information for me unless the program is
3945: short and simple. If you send me a large program, I don't have time to
3946: figure out how it would work if compiled correctly, much less which line
3947: of it was compiled wrong. So you will have to do that. Tell me which
3948: source line it is, and what incorrect result happens when that line is
3949: executed. A person who understands the test program can find this as
3950: easily as a bug in the program itself.
1.1 root 3951:
3952: @item
3953: If you send me examples of output from GNU CC, please use @samp{-g}
3954: when you make them. The debugging information includes source line
3955: numbers which are essential for correlating the output with the input.
3956:
3957: @item
3958: If you wish to suggest changes to the GNU CC source, send me context
3959: diffs. If you even discuss something in the GNU CC source, refer to
3960: it by context, not by line number.
3961:
3962: The line numbers in my development sources don't match those in your
3963: sources. Your line numbers would convey no useful information to me.
3964:
3965: @item
3966: Additional information from a debugger might enable me to find
3967: a problem on a machine which I do not have available myself.
3968: However, you need to think when you collect this information if
3969: you want it to have any chance of being useful.
3970:
3971: For example, many people send just a backtrace, but that is never
3972: useful by itself. A simple backtrace with arguments conveys little
3973: about GNU CC because the compiler is largely data-driven; the same
3974: functions are called over and over for different RTL insns, doing
3975: different things depending on the details of the insn.
3976:
3977: Most of the arguments listed in the backtrace are useless because they
3978: are pointers to RTL list structure. The numeric values of the
3979: pointers, which the debugger prints in the backtrace, have no
3980: significance whatever; all that matters is the contents of the objects
3981: they point to (and most of the contents are other such pointers).
3982:
3983: In addition, most compiler passes consist of one or more loops that
3984: scan the RTL insn sequence. The most vital piece of information about
1.1.1.8 root 3985: such a loop---which insn it has reached---is usually in a local variable,
1.1 root 3986: not in an argument.
3987:
3988: What you need to provide in addition to a backtrace are the values of
3989: the local variables for several stack frames up. When a local
3990: variable or an argument is an RTX, first print its value and then use
3991: the GDB command @code{pr} to print the RTL expression that it points
3992: to. (If GDB doesn't run on your machine, use your debugger to call
3993: the function @code{debug_rtx} with the RTX as an argument.) In
3994: general, whenever a variable is a pointer, its value is no use
3995: without the data it points to.
3996:
3997: In addition, include a debugging dump from just before the pass
3998: in which the crash happens. Most bugs involve a series of insns,
3999: not just one.
4000: @end itemize
4001:
4002: Here are some things that are not necessary:
4003:
4004: @itemize @bullet
4005: @item
4006: A description of the envelope of the bug.
4007:
4008: Often people who encounter a bug spend a lot of time investigating
4009: which changes to the input file will make the bug go away and which
4010: changes will not affect it.
4011:
4012: This is often time consuming and not very useful, because the way I
4013: will find the bug is by running a single example under the debugger
4014: with breakpoints, not by pure deduction from a series of examples.
1.1.1.8 root 4015: I recommend that you save your time for something else.
1.1 root 4016:
4017: Of course, if you can find a simpler example to report @emph{instead}
4018: of the original one, that is a convenience for me. Errors in the
4019: output will be easier to spot, running under the debugger will take
4020: less time, etc. Most GNU CC bugs involve just one function, so the
4021: most straightforward way to simplify an example is to delete all the
4022: function definitions except the one where the bug occurs. Those
4023: earlier in the file may be replaced by external declarations if the
1.1.1.8 root 4024: crucial function depends on them. (Exception: inline functions may
4025: affect compilation of functions defined later in the file.)
1.1 root 4026:
4027: However, simplification is not vital; if you don't want to do this,
1.1.1.8 root 4028: report the bug anyway and send me the entire test case you used.
1.1 root 4029:
4030: @item
4031: A patch for the bug.
4032:
4033: A patch for the bug does help me if it is a good one. But don't omit
1.1.1.8 root 4034: the necessary information, such as the test case, on the assumption that
4035: a patch is all I need. I might see problems with your patch and decide
4036: to fix the problem another way, or I might not understand it at all.
1.1 root 4037:
4038: Sometimes with a program as complicated as GNU CC it is very hard to
4039: construct an example that will make the program follow a certain path
4040: through the code. If you don't send me the example, I won't be able
4041: to construct one, so I won't be able to verify that the bug is fixed.
4042:
1.1.1.8 root 4043: And if I can't understand what bug you are trying to fix, or why your
4044: patch should be an improvement, I won't install it. A test case will
4045: help me to understand.
4046:
1.1 root 4047: @item
4048: A guess about what the bug is or what it depends on.
4049:
4050: Such guesses are usually wrong. Even I can't guess right about such
1.1.1.8 root 4051: things without first using the debugger to find the facts.
1.1 root 4052: @end itemize
4053:
4054: @node Portability, Interface, Bugs, Top
4055: @chapter GNU CC and Portability
4056:
4057: The main goal of GNU CC was to make a good, fast compiler for machines in
4058: the class that the GNU system aims to run on: 32-bit machines that address
4059: 8-bit bytes and have several general registers. Elegance, theoretical
4060: power and simplicity are only secondary.
4061:
4062: GNU CC gets most of the information about the target machine from a machine
4063: description which gives an algebraic formula for each of the machine's
4064: instructions. This is a very clean way to describe the target. But when
4065: the compiler needs information that is difficult to express in this
4066: fashion, I have not hesitated to define an ad-hoc parameter to the machine
4067: description. The purpose of portability is to reduce the total work needed
4068: on the compiler; it was not of interest for its own sake.
4069:
4070: GNU CC does not contain machine dependent code, but it does contain code
4071: that depends on machine parameters such as endianness (whether the most
4072: significant byte has the highest or lowest address of the bytes in a word)
4073: and the availability of autoincrement addressing. In the RTL-generation
4074: pass, it is often necessary to have multiple strategies for generating code
4075: for a particular kind of syntax tree, strategies that are usable for different
4076: combinations of parameters. Often I have not tried to address all possible
4077: cases, but only the common ones or only the ones that I have encountered.
4078: As a result, a new target may require additional strategies. You will know
4079: if this happens because the compiler will call @code{abort}. Fortunately,
4080: the new strategies can be added in a machine-independent fashion, and will
4081: affect only the target machines that need them.
4082:
4083: @node Interface, Passes, Portability, Top
4084: @chapter Interfacing to GNU CC Output
4085:
4086: GNU CC is normally configured to use the same function calling convention
4087: normally in use on the target system. This is done with the
4088: machine-description macros described (@pxref{Machine Macros}).
4089:
4090: However, returning of structure and union values is done differently on
4091: some target machines. As a result, functions compiled with PCC
4092: returning such types cannot be called from code compiled with GNU CC,
4093: and vice versa. This does not cause trouble often because few Unix
4094: library routines return structures or unions.
4095:
4096: GNU CC code returns structures and unions that are 1, 2, 4 or 8 bytes
4097: long in the same registers used for @code{int} or @code{double} return
4098: values. (GNU CC typically allocates variables of such types in
4099: registers also.) Structures and unions of other sizes are returned by
4100: storing them into an address passed by the caller (usually in a
4101: register). The machine-description macros @code{STRUCT_VALUE} and
4102: @code{STRUCT_INCOMING_VALUE} tell GNU CC where to pass this address.
4103:
4104: By contrast, PCC on most target machines returns structures and unions
4105: of any size by copying the data into an area of static storage, and then
4106: returning the address of that storage as if it were a pointer value.
4107: The caller must copy the data from that memory area to the place where
4108: the value is wanted. This is slower than the method used by GNU CC, and
4109: fails to be reentrant.
4110:
4111: On some target machines, such as RISC machines and the 80386, the
4112: standard system convention is to pass to the subroutine the address of
4113: where to return the value. On these machines, GNU CC has been
4114: configured to be compatible with the standard compiler, when this method
4115: is used. It may not be compatible for structures of 1, 2, 4 or 8 bytes.
4116:
4117: GNU CC uses the system's standard convention for passing arguments. On
4118: some machines, the first few arguments are passed in registers; in
4119: others, all are passed on the stack. It would be possible to use
4120: registers for argument passing on any machine, and this would probably
4121: result in a significant speedup. But the result would be complete
4122: incompatibility with code that follows the standard convention. So this
4123: change is practical only if you are switching to GNU CC as the sole C
4124: compiler for the system. We may implement register argument passing on
4125: certain machines once we have a complete GNU system so that we can
4126: compile the libraries with GNU CC.
4127:
4128: If you use @code{longjmp}, beware of automatic variables. ANSI C says that
4129: automatic variables that are not declared @code{volatile} have undefined
4130: values after a @code{longjmp}. And this is all GNU CC promises to do,
4131: because it is very difficult to restore register variables correctly, and
4132: one of GNU CC's features is that it can put variables in registers without
4133: your asking it to.
4134:
4135: If you want a variable to be unaltered by @code{longjmp}, and you don't
4136: want to write @code{volatile} because old C compilers don't accept it,
4137: just take the address of the variable. If a variable's address is ever
4138: taken, even if just to compute it and ignore it, then the variable cannot
4139: go in a register:
4140:
4141: @example
4142: @{
4143: int careful;
4144: &careful;
4145: @dots{}
4146: @}
4147: @end example
4148:
4149: Code compiled with GNU CC may call certain library routines. Most of
4150: them handle arithmetic for which there are no instructions. This
4151: includes multiply and divide on some machines, and floating point
4152: operations on any machine for which floating point support is disabled
4153: with @samp{-msoft-float}. Some standard parts of the C library, such as
4154: @code{bcopy} or @code{memcpy}, are also called automatically. The usual
4155: function call interface is used for calling the library routines.
4156:
4157: These library routines should be defined in the library @file{gnulib},
4158: which GNU CC automatically searches whenever it links a program. On
4159: machines that have multiply and divide instructions, if hardware
4160: floating point is in use, normally @file{gnulib} is not needed, but it
4161: is searched just in case.
4162:
4163: Each arithmetic function is defined in @file{gnulib.c} to use the
4164: corresponding C arithmetic operator. As long as the file is compiled
4165: with another C compiler, which supports all the C arithmetic operators,
4166: this file will work portably. However, @file{gnulib.c} does not work if
4167: compiled with GNU CC, because each arithmetic function would compile
4168: into a call to itself!
4169:
4170: @node Passes, RTL, Interface, Top
4171: @chapter Passes and Files of the Compiler
4172:
4173: The overall control structure of the compiler is in @file{toplev.c}. This
4174: file is responsible for initialization, decoding arguments, opening and
4175: closing files, and sequencing the passes.
4176:
4177: The parsing pass is invoked only once, to parse the entire input. The RTL
4178: intermediate code for a function is generated as the function is parsed, a
4179: statement at a time. Each statement is read in as a syntax tree and then
4180: converted to RTL; then the storage for the tree for the statement is
4181: reclaimed. Storage for types (and the expressions for their sizes),
4182: declarations, and a representation of the binding contours and how they nest,
4183: remains until the function is finished being compiled; these are all needed
4184: to output the debugging information.
4185:
4186: Each time the parsing pass reads a complete function definition or
4187: top-level declaration, it calls the function
4188: @code{rest_of_compilation} or @code{rest_of_decl_compilation} in
4189: @file{toplev.c}, which are responsible for all further processing
4190: necessary, ending with output of the assembler language. All other
4191: compiler passes run, in sequence, within @code{rest_of_compilation}.
4192: When that function returns from compiling a function definition, the
4193: storage used for that function definition's compilation is entirely
4194: freed, unless it is an inline function (@pxref{Inline}).
4195:
4196: Here is a list of all the passes of the compiler and their source files.
4197: Also included is a description of where debugging dumps can be requested
4198: with @samp{-d} options.
4199:
4200: @itemize @bullet
4201: @item
4202: Parsing. This pass reads the entire text of a function definition,
4203: constructing partial syntax trees. This and RTL generation are no longer
4204: truly separate passes (formerly they were), but it is easier to think
4205: of them as separate.
4206:
4207: The tree representation does not entirely follow C syntax, because it is
4208: intended to support other languages as well.
4209:
4210: C data type analysis is also done in this pass, and every tree node
4211: that represents an expression has a data type attached. Variables are
4212: represented as declaration nodes.
4213:
4214: Constant folding and associative-law simplifications are also done
4215: during this pass.
4216:
4217: The source files for parsing are @file{c-parse.y}, @file{c-decl.c},
4218: @file{c-typeck.c}, @file{c-convert.c}, @file{stor-layout.c},
4219: @file{fold-const.c}, and @file{tree.c}. The last three files are
4220: intended to be language-independent. There are also header files
4221: @file{c-parse.h}, @file{c-tree.h}, @file{tree.h} and @file{tree.def}.
4222: The last two define the format of the tree representation.@refill
4223:
4224: @item
4225: RTL generation. This is the conversion of syntax tree into RTL code.
4226: It is actually done statement-by-statement during parsing, but for
4227: most purposes it can be thought of as a separate pass.
4228:
4229: This is where the bulk of target-parameter-dependent code is found,
4230: since often it is necessary for strategies to apply only when certain
4231: standard kinds of instructions are available. The purpose of named
4232: instruction patterns is to provide this information to the RTL
4233: generation pass.
4234:
4235: Optimization is done in this pass for @code{if}-conditions that are
4236: comparisons, boolean operations or conditional expressions. Tail
4237: recursion is detected at this time also. Decisions are made about how
4238: best to arrange loops and how to output @code{switch} statements.
4239:
4240: The source files for RTL generation are @file{stmt.c}, @file{expr.c},
4241: @file{explow.c}, @file{expmed.c}, @file{optabs.c} and @file{emit-rtl.c}.
4242: Also, the file @file{insn-emit.c}, generated from the machine description
4243: by the program @code{genemit}, is used in this pass. The header files
4244: @file{expr.h} is used for communication within this pass.@refill
4245:
4246: The header files @file{insn-flags.h} and @file{insn-codes.h},
4247: generated from the machine description by the programs @code{genflags}
4248: and @code{gencodes}, tell this pass which standard names are available
4249: for use and which patterns correspond to them.@refill
4250:
4251: Aside from debugging information output, none of the following passes
4252: refers to the tree structure representation of the function (only
4253: part of which is saved).
4254:
4255: The decision of whether the function can and should be expanded inline
4256: in its subsequent callers is made at the end of rtl generation. The
4257: function must meet certain criteria, currently related to the size of
4258: the function and the types and number of parameters it has. Note that
4259: this function may contain loops, recursive calls to itself
4260: (tail-recursive functions can be inlined!), gotos, in short, all
4261: constructs supported by GNU CC.
4262:
4263: The option @samp{-dr} causes a debugging dump of the RTL code after
4264: this pass. This dump file's name is made by appending @samp{.rtl} to
4265: the input file name.
4266:
4267: @item
4268: Jump optimization. This pass simplifies jumps to the following
4269: instruction, jumps across jumps, and jumps to jumps. It deletes
4270: unreferenced labels and unreachable code, except that unreachable code
4271: that contains a loop is not recognized as unreachable in this pass.
4272: (Such loops are deleted later in the basic block analysis.)
4273:
4274: Jump optimization is performed two or three times. The first time is
4275: immediately following RTL generation. The second time is after CSE,
4276: but only if CSE says repeated jump optimization is needed. The
4277: last time is right before the final pass. That time, cross-jumping
4278: and deletion of no-op move instructions are done together with the
4279: optimizations described above.
4280:
4281: The source file of this pass is @file{jump.c}.
4282:
4283: The option @samp{-dj} causes a debugging dump of the RTL code after
4284: this pass is run for the first time. This dump file's name is made by
4285: appending @samp{.jump} to the input file name.
4286:
4287: @item
4288: Register scan. This pass finds the first and last use of each
4289: register, as a guide for common subexpression elimination. Its source
4290: is in @file{regclass.c}.
4291:
4292: @item
4293: Common subexpression elimination. This pass also does constant
4294: propagation. Its source file is @file{cse.c}. If constant
4295: propagation causes conditional jumps to become unconditional or to
4296: become no-ops, jump optimization is run again when CSE is finished.
4297:
4298: The option @samp{-ds} causes a debugging dump of the RTL code after
4299: this pass. This dump file's name is made by appending @samp{.cse} to
4300: the input file name.
4301:
4302: @item
1.1.1.8 root 4303: Loop optimization. This pass moves constant expressions out of loops,
4304: and optionally does strength-reduction as well. Its source file is
4305: @file{loop.c}.
1.1 root 4306:
4307: The option @samp{-dL} causes a debugging dump of the RTL code after
4308: this pass. This dump file's name is made by appending @samp{.loop} to
4309: the input file name.
4310:
4311: @item
4312: Stupid register allocation is performed at this point in a
4313: nonoptimizing compilation. It does a little data flow analysis as
4314: well. When stupid register allocation is in use, the next pass
4315: executed is the reloading pass; the others in between are skipped.
4316: The source file is @file{stupid.c}.
4317:
4318: @item
4319: Data flow analysis (@file{flow.c}). This pass divides the program
4320: into basic blocks (and in the process deletes unreachable loops); then
4321: it computes which pseudo-registers are live at each point in the
4322: program, and makes the first instruction that uses a value point at
4323: the instruction that computed the value.
4324:
4325: This pass also deletes computations whose results are never used, and
4326: combines memory references with add or subtract instructions to make
4327: autoincrement or autodecrement addressing.
4328:
4329: The option @samp{-df} causes a debugging dump of the RTL code after
4330: this pass. This dump file's name is made by appending @samp{.flow} to
4331: the input file name. If stupid register allocation is in use, this
4332: dump file reflects the full results of such allocation.
4333:
4334: @item
4335: Instruction combination (@file{combine.c}). This pass attempts to
4336: combine groups of two or three instructions that are related by data
4337: flow into single instructions. It combines the RTL expressions for
4338: the instructions by substitution, simplifies the result using algebra,
4339: and then attempts to match the result against the machine description.
4340:
4341: The option @samp{-dc} causes a debugging dump of the RTL code after
4342: this pass. This dump file's name is made by appending @samp{.combine}
4343: to the input file name.
4344:
4345: @item
4346: Register class preferencing. The RTL code is scanned to find out
4347: which register class is best for each pseudo register. The source
4348: file is @file{regclass.c}.
4349:
4350: @item
4351: Local register allocation (@file{local-alloc.c}). This pass allocates
4352: hard registers to pseudo registers that are used only within one basic
4353: block. Because the basic block is linear, it can use fast and
4354: powerful techniques to do a very good job.
4355:
4356: The option @samp{-dl} causes a debugging dump of the RTL code after
4357: this pass. This dump file's name is made by appending @samp{.lreg} to
4358: the input file name.
4359:
4360: @item
4361: Global register allocation (@file{global-alloc.c}). This pass
4362: allocates hard registers for the remaining pseudo registers (those
4363: whose life spans are not contained in one basic block).
4364:
4365: @item
4366: Reloading. This pass renumbers pseudo registers with the hardware
4367: registers numbers they were allocated. Pseudo registers that did not
4368: get hard registers are replaced with stack slots. Then it finds
4369: instructions that are invalid because a value has failed to end up in
4370: a register, or has ended up in a register of the wrong kind. It fixes
4371: up these instructions by reloading the problematical values
4372: temporarily into registers. Additional instructions are generated to
4373: do the copying.
4374:
4375: Source files are @file{reload.c} and @file{reload1.c}, plus the header
4376: @file{reload.h} used for communication between them.
4377:
4378: The option @samp{-dg} causes a debugging dump of the RTL code after
4379: this pass. This dump file's name is made by appending @samp{.greg} to
4380: the input file name.
4381:
4382: @item
4383: Jump optimization is repeated, this time including cross-jumping
1.1.1.5 root 4384: and deletion of no-op move instructions.
1.1 root 4385:
4386: The option @samp{-dJ} causes a debugging dump of the RTL code after
4387: this pass. This dump file's name is made by appending @samp{.jump2}
4388: to the input file name.
4389:
4390: @item
1.1.1.8 root 4391: Delayed branch scheduling may be done at this point. The source file
4392: name is @file{dbranch.c}.
4393:
4394: The option @samp{-dd} causes a debugging dump of the RTL code after
4395: this pass. This dump file's name is made by appending @samp{.dbr}
4396: to the input file name.
4397:
4398: @item
1.1 root 4399: Final. This pass outputs the assembler code for the function. It is
4400: also responsible for identifying spurious test and compare
1.1.1.5 root 4401: instructions. Machine-specific peephole optimizations are performed
4402: at the same time. The function entry and exit sequences are generated
1.1 root 4403: directly as assembler code in this pass; they never exist as RTL.
4404:
4405: The source files are @file{final.c} plus @file{insn-output.c}; the
4406: latter is generated automatically from the machine description by the
4407: tool @file{genoutput}. The header file @file{conditions.h} is used
4408: for communication between these files.
4409:
4410: @item
4411: Debugging information output. This is run after final because it must
4412: output the stack slot offsets for pseudo registers that did not get
4413: hard registers. Source files are @file{dbxout.c} for DBX symbol table
4414: format and @file{symout.c} for GDB's own symbol table format.
4415: @end itemize
4416:
4417: Some additional files are used by all or many passes:
4418:
4419: @itemize @bullet
4420: @item
4421: Every pass uses @file{machmode.def}, which defines the machine modes.
4422:
4423: @item
4424: All the passes that work with RTL use the header files @file{rtl.h}
4425: and @file{rtl.def}, and subroutines in file @file{rtl.c}. The tools
4426: @code{gen*} also use these files to read and work with the machine
4427: description RTL.
4428:
4429: @item
4430: Several passes refer to the header file @file{insn-config.h} which
4431: contains a few parameters (C macro definitions) generated
4432: automatically from the machine description RTL by the tool
4433: @code{genconfig}.
4434:
4435: @item
4436: Several passes use the instruction recognizer, which consists of
4437: @file{recog.c} and @file{recog.h}, plus the files @file{insn-recog.c}
4438: and @file{insn-extract.c} that are generated automatically from the
4439: machine description by the tools @file{genrecog} and
4440: @file{genextract}.@refill
4441:
4442: @item
4443: Several passes use the header files @file{regs.h} which defines the
4444: information recorded about pseudo register usage, and @file{basic-block.h}
4445: which defines the information recorded about basic blocks.
4446:
4447: @item
4448: @file{hard-reg-set.h} defines the type @code{HARD_REG_SET}, a bit-vector
4449: with a bit for each hard register, and some macros to manipulate it.
4450: This type is just @code{int} if the machine has few enough hard registers;
4451: otherwise it is an array of @code{int} and some of the macros expand
4452: into loops.
4453: @end itemize
4454:
4455: @node RTL, Machine Desc, Passes, Top
4456: @chapter RTL Representation
4457:
4458: Most of the work of the compiler is done on an intermediate representation
4459: called register transfer language. In this language, the instructions to be
4460: output are described, pretty much one by one, in an algebraic form that
4461: describes what the instruction does.
4462:
4463: RTL is inspired by Lisp lists. It has both an internal form, made up of
4464: structures that point at other structures, and a textual form that is used
4465: in the machine description and in printed debugging dumps. The textual
4466: form uses nested parentheses to indicate the pointers in the internal form.
4467:
4468: @menu
4469: * RTL Objects:: Expressions vs vectors vs strings vs integers.
4470: * Accessors:: Macros to access expression operands or vector elts.
4471: * Flags:: Other flags in an RTL expression.
4472: * Machine Modes:: Describing the size and format of a datum.
4473: * Constants:: Expressions with constant values.
4474: * Regs and Memory:: Expressions representing register contents or memory.
4475: * Arithmetic:: Expressions representing arithmetic on other expressions.
4476: * Comparisons:: Expressions representing comparison of expressions.
4477: * Bit Fields:: Expressions representing bit-fields in memory or reg.
4478: * Conversions:: Extending, truncating, floating or fixing.
4479: * RTL Declarations:: Declaring volatility, constancy, etc.
4480: * Side Effects:: Expressions for storing in registers, etc.
4481: * Incdec:: Embedded side-effects for autoincrement addressing.
1.1.1.9 root 4482: * Assembler:: Representing @code{asm} with operands.
1.1 root 4483: * Insns:: Expression types for entire insns.
1.1.1.9 root 4484: * Calls:: RTL representation of function call insns.
1.1 root 4485: * Sharing:: Some expressions are unique; others *must* be copied.
4486: @end menu
4487:
4488: @node RTL Objects, Accessors, RTL, RTL
4489: @section RTL Object Types
4490:
4491: RTL uses four kinds of objects: expressions, integers, strings and vectors.
4492: Expressions are the most important ones. An RTL expression (``RTX'', for
4493: short) is a C structure, but it is usually referred to with a pointer; a
4494: type that is given the typedef name @code{rtx}.
4495:
4496: An integer is simply an @code{int}, and a string is a @code{char *}.
1.1.1.8 root 4497: Within RTL code, strings appear only inside @code{symbol_ref} expressions,
1.1 root 4498: but they appear in other contexts in the RTL expressions that make up
4499: machine descriptions. Their written form uses decimal digits.
4500:
4501: A string is a sequence of characters. In core it is represented as a
4502: @code{char *} in usual C fashion, and it is written in C syntax as well.
4503: However, strings in RTL may never be null. If you write an empty string in
4504: a machine description, it is represented in core as a null pointer rather
4505: than as a pointer to a null character. In certain contexts, these null
4506: pointers instead of strings are valid.
4507:
4508: A vector contains an arbitrary, specified number of pointers to
4509: expressions. The number of elements in the vector is explicitly present in
4510: the vector. The written form of a vector consists of square brackets
4511: (@samp{[@dots{}]}) surrounding the elements, in sequence and with
4512: whitespace separating them. Vectors of length zero are not created; null
4513: pointers are used instead.
4514:
4515: Expressions are classified by @dfn{expression codes} (also called RTX
4516: codes). The expression code is a name defined in @file{rtl.def}, which is
4517: also (in upper case) a C enumeration constant. The possible expression
4518: codes and their meanings are machine-independent. The code of an RTX can
4519: be extracted with the macro @code{GET_CODE (@var{x})} and altered with
4520: @code{PUT_CODE (@var{x}, @var{newcode})}.
4521:
4522: The expression code determines how many operands the expression contains,
4523: and what kinds of objects they are. In RTL, unlike Lisp, you cannot tell
4524: by looking at an operand what kind of object it is. Instead, you must know
4525: from its context---from the expression code of the containing expression.
1.1.1.8 root 4526: For example, in an expression of code @code{subreg}, the first operand is
1.1 root 4527: to be regarded as an expression and the second operand as an integer. In
1.1.1.8 root 4528: an expression of code @code{plus}, there are two operands, both of which
4529: are to be regarded as expressions. In a @code{symbol_ref} expression,
1.1 root 4530: there is one operand, which is to be regarded as a string.
4531:
4532: Expressions are written as parentheses containing the name of the
4533: expression type, its flags and machine mode if any, and then the operands
4534: of the expression (separated by spaces).
4535:
4536: Expression code names in the @samp{md} file are written in lower case,
4537: but when they appear in C code they are written in upper case. In this
1.1.1.8 root 4538: manual, they are shown as follows: @code{const_int}.
1.1 root 4539:
4540: In a few contexts a null pointer is valid where an expression is normally
1.1.1.4 root 4541: wanted. The written form of this is @code{(nil)}.
1.1 root 4542:
4543: @node Accessors, Flags, RTL Objects, RTL
4544: @section Access to Operands
4545:
4546: For each expression type @file{rtl.def} specifies the number of contained
4547: objects and their kinds, with four possibilities: @samp{e} for expression
4548: (actually a pointer to an expression), @samp{i} for integer, @samp{s} for
4549: string, and @samp{E} for vector of expressions. The sequence of letters
4550: for an expression code is called its @dfn{format}. Thus, the format of
1.1.1.8 root 4551: @code{subreg} is @samp{ei}.@refill
1.1 root 4552:
4553: Two other format characters are used occasionally: @samp{u} and @samp{0}.
4554: @samp{u} is equivalent to @samp{e} except that it is printed differently in
4555: debugging dumps, and @samp{0} means a slot whose contents do not fit any
4556: normal category. @samp{0} slots are not printed at all in dumps, and are
4557: often used in special ways by small parts of the compiler.@refill
4558:
4559: There are macros to get the number of operands and the format of an
4560: expression code:
4561:
4562: @table @code
4563: @item GET_RTX_LENGTH (@var{code})
4564: Number of operands of an RTX of code @var{code}.
4565:
4566: @item GET_RTX_FORMAT (@var{code})
4567: The format of an RTX of code @var{code}, as a C string.
4568: @end table
4569:
4570: Operands of expressions are accessed using the macros @code{XEXP},
4571: @code{XINT} and @code{XSTR}. Each of these macros takes two arguments: an
4572: expression-pointer (RTX) and an operand number (counting from zero).
4573: Thus,@refill
4574:
4575: @example
4576: XEXP (@var{x}, 2)
4577: @end example
4578:
4579: @noindent
4580: accesses operand 2 of expression @var{x}, as an expression.
4581:
4582: @example
4583: XINT (@var{x}, 2)
4584: @end example
4585:
4586: @noindent
4587: accesses the same operand as an integer. @code{XSTR}, used in the same
4588: fashion, would access it as a string.
4589:
4590: Any operand can be accessed as an integer, as an expression or as a string.
4591: You must choose the correct method of access for the kind of value actually
4592: stored in the operand. You would do this based on the expression code of
4593: the containing expression. That is also how you would know how many
4594: operands there are.
4595:
1.1.1.8 root 4596: For example, if @var{x} is a @code{subreg} expression, you know that it has
1.1 root 4597: two operands which can be correctly accessed as @code{XEXP (@var{x}, 0)}
4598: and @code{XINT (@var{x}, 1)}. If you did @code{XINT (@var{x}, 0)}, you
4599: would get the address of the expression operand but cast as an integer;
4600: that might occasionally be useful, but it would be cleaner to write
4601: @code{(int) XEXP (@var{x}, 0)}. @code{XEXP (@var{x}, 1)} would also
4602: compile without error, and would return the second, integer operand cast as
4603: an expression pointer, which would probably result in a crash when
4604: accessed. Nothing stops you from writing @code{XEXP (@var{x}, 28)} either,
4605: but this will access memory past the end of the expression with
4606: unpredictable results.@refill
4607:
4608: Access to operands which are vectors is more complicated. You can use the
4609: macro @code{XVEC} to get the vector-pointer itself, or the macros
4610: @code{XVECEXP} and @code{XVECLEN} to access the elements and length of a
4611: vector.
4612:
4613: @table @code
4614: @item XVEC (@var{exp}, @var{idx})
4615: Access the vector-pointer which is operand number @var{idx} in @var{exp}.
4616:
4617: @item XVECLEN (@var{exp}, @var{idx})
4618: Access the length (number of elements) in the vector which is
4619: in operand number @var{idx} in @var{exp}. This value is an @code{int}.
4620:
4621: @item XVECEXP (@var{exp}, @var{idx}, @var{eltnum})
4622: Access element number @var{eltnum} in the vector which is
4623: in operand number @var{idx} in @var{exp}. This value is an RTX.
4624:
4625: It is up to you to make sure that @var{eltnum} is not negative
4626: and is less than @code{XVECLEN (@var{exp}, @var{idx})}.
4627: @end table
4628:
4629: All the macros defined in this section expand into lvalues and therefore
4630: can be used to assign the operands, lengths and vector elements as well as
4631: to access them.
4632:
4633: @node Flags, Machine Modes, Accessors, RTL
4634: @section Flags in an RTL Expression
4635:
4636: RTL expressions contain several flags (one-bit bit-fields) that are used
4637: in certain types of expression. Most often they are accessed with the
4638: following macros:
4639:
4640: @table @code
1.1.1.10 root 4641: @item EXTERNAL_SYMBOL_P (@var{x})
4642: In a @code{symbol_ref} expression, nonzero if it corresponds to a variable
4643: declared extern in the users code. Zero for all other variables. Stored in
4644: the @code{volatil} field and printed as @samp{/v}.
4645:
1.1 root 4646: @item MEM_VOLATILE_P (@var{x})
1.1.1.8 root 4647: In @code{mem} expressions, nonzero for volatile memory references.
1.1 root 4648: Stored in the @code{volatil} field and printed as @samp{/v}.
4649:
4650: @item MEM_IN_STRUCT_P (@var{x})
1.1.1.8 root 4651: In @code{mem} expressions, nonzero for reference to an entire
1.1 root 4652: structure, union or array, or to a component of one. Zero for
4653: references to a scalar variable or through a pointer to a scalar.
4654: Stored in the @code{in_struct} field and printed as @samp{/s}.
4655:
4656: @item REG_USER_VAR_P (@var{x})
1.1.1.8 root 4657: In a @code{reg}, nonzero if it corresponds to a variable present in
1.1 root 4658: the user's source code. Zero for temporaries generated internally by
4659: the compiler. Stored in the @code{volatil} field and printed as
4660: @samp{/v}.
4661:
4662: @item REG_FUNCTION_VALUE_P (@var{x})
1.1.1.8 root 4663: Nonzero in a @code{reg} if it is the place in which this function's
1.1 root 4664: value is going to be returned. (This happens only in a hard
4665: register.) Stored in the @code{integrated} field and printed as
4666: @samp{/i}.
4667:
4668: The same hard register may be used also for collecting the values of
4669: functions called by this one, but @code{REG_FUNCTION_VALUE_P} is zero
4670: in this kind of use.
4671:
4672: @item RTX_UNCHANGING_P (@var{x})
1.1.1.8 root 4673: Nonzero in a @code{reg} or @code{mem} if the value is not changed
1.1 root 4674: explicitly by the current function. (If it is a memory reference then
4675: it may be changed by other functions or by aliasing.) Stored in the
4676: @code{unchanging} field and printed as @samp{/u}.
4677:
4678: @item RTX_INTEGRATED_P (@var{insn})
4679: Nonzero in an insn if it resulted from an in-line function call.
4680: Stored in the @code{integrated} field and printed as @samp{/i}. This
4681: may be deleted; nothing currently depends on it.
4682:
4683: @item INSN_DELETED_P (@var{insn})
4684: In an insn, nonzero if the insn has been deleted. Stored in the
4685: @code{volatil} field and printed as @samp{/v}.
4686:
4687: @item CONSTANT_POOL_ADDRESS_P (@var{x})
1.1.1.8 root 4688: Nonzero in a @code{symbol_ref} if it refers to part of the current
1.1 root 4689: function's ``constants pool''. These are addresses close to the
4690: beginning of the function, and GNU CC assumes they can be addressed
4691: directly (perhaps with the help of base registers). Stored in the
4692: @code{unchanging} field and printed as @samp{/u}.
4693: @end table
4694:
4695: These are the fields which the above macros refer to:
4696:
4697: @table @code
4698: @item used
4699: This flag is used only momentarily, at the end of RTL generation for a
4700: function, to count the number of times an expression appears in insns.
4701: Expressions that appear more than once are copied, according to the
4702: rules for shared structure (@pxref{Sharing}).
4703:
4704: @item volatil
1.1.1.10 root 4705: This flag is used in @code{mem},@code{symbol_ref} and @code{reg} expressions
4706: and in insns. In RTL dump files, it is printed as @samp{/v}.
1.1 root 4707:
1.1.1.8 root 4708: In a @code{mem} expression, it is 1 if the memory reference is volatile.
1.1 root 4709: Volatile memory references may not be deleted, reordered or combined.
4710:
1.1.1.8 root 4711: In a @code{reg} expression, it is 1 if the value is a user-level variable.
1.1 root 4712: 0 indicates an internal compiler temporary.
4713:
1.1.1.10 root 4714: In a @code{symbol_ref} expression, it is 1 if the symbol is declared
4715: @code{extern}.
4716:
1.1 root 4717: In an insn, 1 means the insn has been deleted.
4718:
4719: @item in_struct
1.1.1.8 root 4720: This flag is used in @code{mem} expressions. It is 1 if the memory
1.1 root 4721: datum referred to is all or part of a structure or array; 0 if it is (or
4722: might be) a scalar variable. A reference through a C pointer has 0
4723: because the pointer might point to a scalar variable.
4724:
4725: This information allows the compiler to determine something about possible
4726: cases of aliasing.
4727:
4728: In an RTL dump, this flag is represented as @samp{/s}.
4729:
4730: @item unchanging
1.1.1.8 root 4731: This flag is used in @code{reg} and @code{mem} expressions. 1 means
1.1 root 4732: that the value of the expression never changes (at least within the
4733: current function).
4734:
4735: In an RTL dump, this flag is represented as @samp{/u}.
4736:
4737: @item integrated
4738: In some kinds of expressions, including insns, this flag means the
4739: rtl was produced by procedure integration.
4740:
1.1.1.8 root 4741: In a @code{reg} expression, this flag indicates the register
1.1 root 4742: containing the value to be returned by the current function. On
4743: machines that pass parameters in registers, the same register number
4744: may be used for parameters as well, but this flag is not set on such
4745: uses.
4746: @end table
4747:
4748: @node Machine Modes, Constants, Flags, RTL
4749: @section Machine Modes
4750:
4751: A machine mode describes a size of data object and the representation used
4752: for it. In the C code, machine modes are represented by an enumeration
4753: type, @code{enum machine_mode}, defined in @file{machmode.def}. Each RTL
4754: expression has room for a machine mode and so do certain kinds of tree
4755: expressions (declarations and types, to be precise).
4756:
4757: In debugging dumps and machine descriptions, the machine mode of an RTL
4758: expression is written after the expression code with a colon to separate
4759: them. The letters @samp{mode} which appear at the end of each machine mode
1.1.1.8 root 4760: name are omitted. For example, @code{(reg:SI 38)} is a @code{reg}
1.1 root 4761: expression with machine mode @code{SImode}. If the mode is
4762: @code{VOIDmode}, it is not written at all.
4763:
4764: Here is a table of machine modes.
4765:
4766: @table @code
4767: @item QImode
4768: ``Quarter-Integer'' mode represents a single byte treated as an integer.
4769:
4770: @item HImode
4771: ``Half-Integer'' mode represents a two-byte integer.
4772:
1.1.1.7 root 4773: @item PSImode
4774: ``Partial Single Integer'' mode represents an integer which occupies
4775: four bytes but which doesn't really use all four. On some machines,
4776: this is the right mode to use for pointers.
4777:
1.1 root 4778: @item SImode
4779: ``Single Integer'' mode represents a four-byte integer.
4780:
1.1.1.7 root 4781: @item PDImode
4782: ``Partial Double Integer'' mode represents an integer which occupies
4783: eight bytes but which doesn't really use all eight. On some machines,
4784: this is the right mode to use for certain pointers.
4785:
1.1 root 4786: @item DImode
4787: ``Double Integer'' mode represents an eight-byte integer.
4788:
4789: @item TImode
4790: ``Tetra Integer'' (?) mode represents a sixteen-byte integer.
4791:
4792: @item SFmode
4793: ``Single Floating'' mode represents a single-precision (four byte) floating
4794: point number.
4795:
4796: @item DFmode
4797: ``Double Floating'' mode represents a double-precision (eight byte) floating
4798: point number.
4799:
1.1.1.7 root 4800: @item XFmode
4801: ``Extended Floating'' mode represents a triple-precision (twelve byte)
4802: floating point number. This mode is used for IEEE extended floating
4803: point.
4804:
1.1 root 4805: @item TFmode
4806: ``Tetra Floating'' mode represents a quadruple-precision (sixteen byte)
4807: floating point number.
4808:
4809: @item BLKmode
4810: ``Block'' mode represents values that are aggregates to which none of
4811: the other modes apply. In RTL, only memory references can have this mode,
4812: and only if they appear in string-move or vector instructions. On machines
4813: which have no such instructions, @code{BLKmode} will not appear in RTL.
4814:
4815: @item VOIDmode
4816: Void mode means the absence of a mode or an unspecified mode.
1.1.1.8 root 4817: For example, RTL expressions of code @code{const_int} have mode
1.1 root 4818: @code{VOIDmode} because they can be taken to have whatever mode the context
4819: requires. In debugging dumps of RTL, @code{VOIDmode} is expressed by
4820: the absence of any mode.
4821:
4822: @item EPmode
4823: ``Entry Pointer'' mode is intended to be used for function variables in
4824: Pascal and other block structured languages. Such values contain
4825: both a function address and a static chain pointer for access to
4826: automatic variables of outer levels. This mode is only partially
4827: implemented since C does not use it.
4828:
4829: @item CSImode@r{, @dots{}}
4830: ``Complex Single Integer'' mode stands for a complex number represented
4831: as a pair of @code{SImode} integers. Any of the integer and floating modes
4832: may have @samp{C} prefixed to its name to obtain a complex number mode.
4833: For example, there are @code{CQImode}, @code{CSFmode}, and @code{CDFmode}.
4834: Since C does not support complex numbers, these machine modes are only
4835: partially implemented.
4836:
4837: @item BImode
4838: This is the machine mode of a bit-field in a structure. It is used
4839: only in the syntax tree, never in RTL, and in the syntax tree it appears
4840: only in declaration nodes. In C, it appears only in @code{FIELD_DECL}
4841: nodes for structure fields defined with a bit size.
4842: @end table
4843:
4844: The machine description defines @code{Pmode} as a C macro which expands
4845: into the machine mode used for addresses. Normally this is @code{SImode}.
4846:
4847: The only modes which a machine description @i{must} support are
4848: @code{QImode}, @code{SImode}, @code{SFmode} and @code{DFmode}. The
4849: compiler will attempt to use @code{DImode} for two-word structures and
1.1.1.7 root 4850: unions, but this can be prevented by overriding the definition of
4851: @code{MAX_FIXED_MODE_SIZE}. Likewise, you can arrange for the C type
4852: @code{short int} to avoid using @code{HImode}. In the long term it
4853: might be desirable to make the set of available machine modes
4854: machine-dependent and eliminate all assumptions about specific machine
4855: modes or their uses from the machine-independent code of the compiler.
1.1 root 4856:
1.1.1.4 root 4857: To help begin this process, the machine modes are divided into mode
4858: classes. These are represented by the enumeration type @code{enum
4859: mode_class} defined in @file{rtl.h}. The possible mode classes are:
4860:
4861: @table @code
4862: @item MODE_INT
4863: Integer modes. By default these are @code{QImode}, @code{HImode},
4864: @code{SImode}, @code{DImode}, @code{TImode}, and also @code{BImode}.
4865:
4866: @item MODE_FLOAT
4867: Floating-point modes. By default these are @code{QFmode},
4868: @code{HFmode}, @code{SFmode}, @code{DFmode} and @code{TFmode}, but the
4869: MC68881 also defines @code{XFmode} to be an 80-bit extended-precision
4870: floating-point mode.
4871:
4872: @item MODE_COMPLEX_INT
4873: Complex integer modes. By default these are @code{CQImode},
4874: @code{CHImode}, @code{CSImode}, @code{CDImode} and @code{CTImode}.
4875:
4876: @item MODE_COMPLEX_FLOAT
4877: Complex floating-point modes. By default these are @code{CQFmode},
4878: @code{CHFmode}, @code{CSFmode}, @code{CDFmode} and @code{CTFmode},
4879:
4880: @item MODE_FUNCTION
4881: Algol or Pascal function variables including a static chain.
4882: (These are not currently implemented).
4883:
4884: @item MODE_RANDOM
4885: This is a catchall mode class for modes which don't fit into the above
4886: classes. Currently @code{VOIDmode}, @code{BLKmode} and @code{EPmode}
4887: are in @code{MODE_RANDOM}.
4888: @end table
4889:
1.1 root 4890: Here are some C macros that relate to machine modes:
4891:
4892: @table @code
4893: @item GET_MODE (@var{x})
4894: Returns the machine mode of the RTX @var{x}.
4895:
4896: @item PUT_MODE (@var{x}, @var{newmode})
4897: Alters the machine mode of the RTX @var{x} to be @var{newmode}.
4898:
1.1.1.4 root 4899: @item NUM_MACHINE_MODES
4900: Stands for the number of machine modes available on the target
4901: machine. This is one greater than the largest numeric value of any
4902: machine mode.
4903:
4904: @item GET_MODE_NAME (@var{m})
4905: Returns the name of mode @var{m} as a string.
4906:
4907: @item GET_MODE_CLASS (@var{m})
4908: Returns the mode class of mode @var{m}.
4909:
1.1 root 4910: @item GET_MODE_SIZE (@var{m})
4911: Returns the size in bytes of a datum of mode @var{m}.
4912:
4913: @item GET_MODE_BITSIZE (@var{m})
4914: Returns the size in bits of a datum of mode @var{m}.
4915:
4916: @item GET_MODE_UNIT_SIZE (@var{m})
4917: Returns the size in bits of the subunits of a datum of mode @var{m}.
4918: This is the same as @code{GET_MODE_SIZE} except in the case of
4919: complex modes and @code{EPmode}. For them, the unit size is the
4920: size of the real or imaginary part, or the size of the function
4921: pointer or the context pointer.
4922: @end table
4923:
4924: @node Constants, Regs and Memory, Machine Modes, RTL
4925: @section Constant Expression Types
4926:
4927: The simplest RTL expressions are those that represent constant values.
4928:
4929: @table @code
4930: @item (const_int @var{i})
4931: This type of expression represents the integer value @var{i}. @var{i}
4932: is customarily accessed with the macro @code{INTVAL} as in
4933: @code{INTVAL (@var{exp})}, which is equivalent to @code{XINT (@var{exp}, 0)}.
4934:
4935: There is only one expression object for the integer value zero;
4936: it is the value of the variable @code{const0_rtx}. Likewise, the
4937: only expression for integer value one is found in @code{const1_rtx}.
1.1.1.8 root 4938: Any attempt to create an expression of code @code{const_int} and
1.1 root 4939: value zero or one will return @code{const0_rtx} or @code{const1_rtx}
4940: as appropriate.
4941:
4942: @item (const_double:@var{m} @var{i0} @var{i1})
1.1.1.6 root 4943: Represents a 64-bit constant of mode @var{m}. All floating point
1.1 root 4944: constants are represented in this way, and so are 64-bit @code{DImode}
4945: integer constants.
4946:
4947: The two integers @var{i0} and @var{i1} together contain the bits of
4948: the value. If the constant is floating point (either single or double
4949: precision), then they represent a @code{double}. To convert them to a
4950: @code{double}, do
4951:
4952: @example
4953: union @{ double d; int i[2];@} u;
1.1.1.8 root 4954: u.i[0] = CONST_DOUBLE_LOW(x);
4955: u.i[1] = CONST_DOUBLE_HIGH(x);
1.1 root 4956: @end example
4957:
4958: @noindent
4959: and then refer to @code{u.d}.
4960:
4961: The global variables @code{dconst0_rtx} and @code{fconst0_rtx} hold
1.1.1.8 root 4962: @code{const_double} expressions with value 0, in modes @code{DFmode}
1.1.1.7 root 4963: and @code{SFmode}, respectively. The macro @code{CONST0_RTX
1.1.1.8 root 4964: (@var{mode})} refers to a @code{const_double} expression with value 0
1.1.1.7 root 4965: in mode @var{mode}. The mode @var{mode} must be of mode class
4966: @code{MODE_FLOAT}.
1.1 root 4967:
4968: @item (symbol_ref @var{symbol})
4969: Represents the value of an assembler label for data. @var{symbol} is
4970: a string that describes the name of the assembler label. If it starts
4971: with a @samp{*}, the label is the rest of @var{symbol} not including
4972: the @samp{*}. Otherwise, the label is @var{symbol}, prefixed with
4973: @samp{_}.
4974:
4975: @item (label_ref @var{label})
4976: Represents the value of an assembler label for code. It contains one
1.1.1.8 root 4977: operand, an expression, which must be a @code{code_label} that appears
1.1 root 4978: in the instruction sequence to identify the place where the label
4979: should go.
4980:
4981: The reason for using a distinct expression type for code label
4982: references is so that jump optimization can distinguish them.
4983:
4984: @item (const @var{exp})
4985: Represents a constant that is the result of an assembly-time
4986: arithmetic computation. The operand, @var{exp}, is an expression that
1.1.1.8 root 4987: contains only constants (@code{const_int}, @code{symbol_ref} and
4988: @code{label_ref} expressions) combined with @code{plus} and
4989: @code{minus}. However, not all combinations are valid, since the
1.1 root 4990: assembler cannot do arbitrary arithmetic on relocatable symbols.
4991: @end table
4992:
4993: @node Regs and Memory, Arithmetic, Constants, RTL
4994: @section Registers and Memory
4995:
4996: Here are the RTL expression types for describing access to machine
4997: registers and to main memory.
4998:
4999: @table @code
5000: @item (reg:@var{m} @var{n})
5001: For small values of the integer @var{n} (less than
5002: @code{FIRST_PSEUDO_REGISTER}), this stands for a reference to machine
5003: register number @var{n}: a @dfn{hard register}. For larger values of
5004: @var{n}, it stands for a temporary value or @dfn{pseudo register}.
5005: The compiler's strategy is to generate code assuming an unlimited
5006: number of such pseudo registers, and later convert them into hard
5007: registers or into memory references.
5008:
5009: The symbol @code{FIRST_PSEUDO_REGISTER} is defined by the machine
5010: description, since the number of hard registers on the machine is an
5011: invariant characteristic of the machine. Note, however, that not
5012: all of the machine registers must be general registers. All the
5013: machine registers that can be used for storage of data are given
5014: hard register numbers, even those that can be used only in certain
5015: instructions or can hold only certain types of data.
5016:
5017: Each pseudo register number used in a function's RTL code is
1.1.1.8 root 5018: represented by a unique @code{reg} expression.
1.1 root 5019:
5020: @var{m} is the machine mode of the reference. It is necessary because
5021: machines can generally refer to each register in more than one mode.
5022: For example, a register may contain a full word but there may be
5023: instructions to refer to it as a half word or as a single byte, as
5024: well as instructions to refer to it as a floating point number of
5025: various precisions.
5026:
5027: Even for a register that the machine can access in only one mode,
5028: the mode must always be specified.
5029:
5030: A hard register may be accessed in various modes throughout one
5031: function, but each pseudo register is given a natural mode
5032: and is accessed only in that mode. When it is necessary to describe
1.1.1.8 root 5033: an access to a pseudo register using a nonnatural mode, a @code{subreg}
1.1 root 5034: expression is used.
5035:
1.1.1.8 root 5036: A @code{reg} expression with a machine mode that specifies more than
1.1 root 5037: one word of data may actually stand for several consecutive registers.
5038: If in addition the register number specifies a hardware register, then
5039: it actually represents several consecutive hardware registers starting
5040: with the specified one.
5041:
1.1.1.8 root 5042: Such multi-word hardware register @code{reg} expressions must not be live
1.1 root 5043: across the boundary of a basic block. The lifetime analysis pass does not
5044: know how to record properly that several consecutive registers are
5045: actually live there, and therefore register allocation would be confused.
5046: The CSE pass must go out of its way to make sure the situation does
5047: not arise.
5048:
5049: @item (subreg:@var{m} @var{reg} @var{wordnum})
1.1.1.8 root 5050: @code{subreg} expressions are used to refer to a register in a machine
1.1 root 5051: mode other than its natural one, or to refer to one register of
1.1.1.8 root 5052: a multi-word @code{reg} that actually refers to several registers.
1.1 root 5053:
5054: Each pseudo-register has a natural mode. If it is necessary to
5055: operate on it in a different mode---for example, to perform a fullword
1.1.1.8 root 5056: move instruction on a pseudo-register that contains a single
5057: byte---the pseudo-register must be enclosed in a @code{subreg}. In
5058: such a case, @var{wordnum} is zero.
1.1 root 5059:
1.1.1.8 root 5060: The other use of @code{subreg} is to extract the individual registers
1.1 root 5061: of a multi-register value. Machine modes such as @code{DImode} and
5062: @code{EPmode} indicate values longer than a word, values which usually
5063: require two consecutive registers. To access one of the registers,
1.1.1.8 root 5064: use a @code{subreg} with mode @code{SImode} and a @var{wordnum} that
1.1 root 5065: says which register.
5066:
5067: The compilation parameter @code{WORDS_BIG_ENDIAN}, if defined, says
5068: that word number zero is the most significant part; otherwise, it is
5069: the least significant part.
5070:
5071: Between the combiner pass and the reload pass, it is possible to have
1.1.1.8 root 5072: a @code{subreg} which contains a @code{mem} instead of a @code{reg} as
1.1 root 5073: its first operand. The reload pass eliminates these cases by
1.1.1.8 root 5074: reloading the @code{mem} into a suitable register.
1.1 root 5075:
5076: Note that it is not valid to access a @code{DFmode} value in @code{SFmode}
1.1.1.8 root 5077: using a @code{subreg}. On some machines the most significant part of a
1.1 root 5078: @code{DFmode} value does not have the same format as a single-precision
5079: floating value.
5080:
5081: @item (cc0)
5082: This refers to the machine's condition code register. It has no
1.1.1.10 root 5083: operands and may not have a machine mode. There are two ways to use it:
5084:
5085: @itemize @bullet
5086: @item
5087: To stand for a complete set of condition code flags. This is best on
5088: most machines, where each comparison sets the entire series of flags.
5089:
5090: With this technique, @code{(cc0)} may be validly used in only two
5091: contexts: as the destination of an assignment (in test and compare
5092: instructions) and in comparison operators comparing against zero
5093: (@code{const_int} with value zero; that is to say, @code{const0_rtx}).
5094:
5095: @item
5096: To stand for a single flag that is the result of a single condition.
5097: This is useful on machines that have only a single flag bit, and in
5098: which comparison instructions must specify the condition to test.
5099:
5100: With this technique, @code{(cc0)} may be validly used in only two
5101: contexts: as the destination of an assignment (in test and compare
5102: instructions) where the source is a comparison operator, and as the
5103: first operand of @code{if_then_else} (in a conditional branch).
5104: @end itemize
1.1 root 5105:
1.1.1.8 root 5106: There is only one expression object of code @code{cc0}; it is the
1.1 root 5107: value of the variable @code{cc0_rtx}. Any attempt to create an
1.1.1.8 root 5108: expression of code @code{cc0} will return @code{cc0_rtx}.
1.1 root 5109:
5110: One special thing about the condition code register is that
5111: instructions can set it implicitly. On many machines, nearly all
5112: instructions set the condition code based on the value that they
5113: compute or store. It is not necessary to record these actions
5114: explicitly in the RTL because the machine description includes a
5115: prescription for recognizing the instructions that do so (by means of
5116: the macro @code{NOTICE_UPDATE_CC}). Only instructions whose sole
5117: purpose is to set the condition code, and instructions that use the
5118: condition code, need mention @code{(cc0)}.
5119:
1.1.1.10 root 5120: In some cases, better code may result from recognizing combinations or
5121: peepholes that include instructions that set the condition codes, even
5122: in cases where some reloading is inevitable. For examples, search for
5123: @samp{addcc} and @samp{andcc} in @file{sparc.md}.
5124:
1.1 root 5125: @item (pc)
5126: This represents the machine's program counter. It has no operands and
5127: may not have a machine mode. @code{(pc)} may be validly used only in
5128: certain specific contexts in jump instructions.
5129:
1.1.1.8 root 5130: There is only one expression object of code @code{pc}; it is the value
1.1 root 5131: of the variable @code{pc_rtx}. Any attempt to create an expression of
1.1.1.8 root 5132: code @code{pc} will return @code{pc_rtx}.
1.1 root 5133:
5134: All instructions that do not jump alter the program counter implicitly
5135: by incrementing it, but there is no need to mention this in the RTL.
5136:
5137: @item (mem:@var{m} @var{addr})
5138: This RTX represents a reference to main memory at an address
5139: represented by the expression @var{addr}. @var{m} specifies how large
5140: a unit of memory is accessed.
5141: @end table
5142:
5143: @node Arithmetic, Comparisons, Regs and Memory, RTL
5144: @section RTL Expressions for Arithmetic
5145:
5146: @table @code
5147: @item (plus:@var{m} @var{x} @var{y})
5148: Represents the sum of the values represented by @var{x} and @var{y}
5149: carried out in machine mode @var{m}. This is valid only if
5150: @var{x} and @var{y} both are valid for mode @var{m}.
5151:
5152: @item (minus:@var{m} @var{x} @var{y})
1.1.1.8 root 5153: Like @code{plus} but represents subtraction.
1.1 root 5154:
1.1.1.6 root 5155: @item (compare @var{x} @var{y})
1.1 root 5156: Represents the result of subtracting @var{y} from @var{x}
5157: for purposes of comparison. The absence of a machine mode
1.1.1.8 root 5158: in the @code{compare} expression indicates that the result is
1.1 root 5159: computed without overflow, as if with infinite precision.
5160:
5161: Of course, machines can't really subtract with infinite precision.
5162: However, they can pretend to do so when only the sign of the
5163: result will be used, which is the case when the result is stored
5164: in @code{(cc0)}. And that is the only way this kind of expression
5165: may validly be used: as a value to be stored in the condition codes.
5166:
5167: @item (neg:@var{m} @var{x})
5168: Represents the negation (subtraction from zero) of the value
5169: represented by @var{x}, carried out in mode @var{m}. @var{x} must be
5170: valid for mode @var{m}.
5171:
5172: @item (mult:@var{m} @var{x} @var{y})
5173: Represents the signed product of the values represented by @var{x} and
5174: @var{y} carried out in machine mode @var{m}. If
5175: @var{x} and @var{y} are both valid for mode @var{m}, this is ordinary
5176: size-preserving multiplication. Alternatively, both @var{x} and @var{y}
5177: may be valid for a different, narrower mode. This represents the
5178: kind of multiplication that generates a product wider than the operands.
5179: Widening multiplication and same-size multiplication are completely
5180: distinct and supported by different machine instructions; machines may
5181: support one but not the other.@refill
5182:
1.1.1.8 root 5183: @code{mult} may be used for floating point multiplication as well.
1.1 root 5184: Then @var{m} is a floating point machine mode.
5185:
5186: @item (umult:@var{m} @var{x} @var{y})
1.1.1.8 root 5187: Like @code{mult} but represents unsigned multiplication. It may be
5188: used in both same-size and widening forms, like @code{mult}.
5189: @code{umult} is used only for fixed-point multiplication.
1.1 root 5190:
5191: @item (div:@var{m} @var{x} @var{y})
5192: Represents the quotient in signed division of @var{x} by @var{y},
5193: carried out in machine mode @var{m}. If @var{m} is a floating-point
5194: mode, it represents the exact quotient; otherwise, the integerized
5195: quotient. If @var{x} and @var{y} are both valid for mode @var{m},
5196: this is ordinary size-preserving division. Some machines have
5197: division instructions in which the operands and quotient widths are
1.1.1.8 root 5198: not all the same; such instructions are represented by @code{div}
1.1 root 5199: expressions in which the machine modes are not all the same.
5200:
5201: @item (udiv:@var{m} @var{x} @var{y})
1.1.1.8 root 5202: Like @code{div} but represents unsigned division.
1.1 root 5203:
5204: @item (mod:@var{m} @var{x} @var{y})
5205: @itemx (umod:@var{m} @var{x} @var{y})
1.1.1.8 root 5206: Like @code{div} and @code{udiv} but represent the remainder instead of
1.1 root 5207: the quotient.
5208:
5209: @item (not:@var{m} @var{x})
5210: Represents the bitwise complement of the value represented by @var{x},
5211: carried out in mode @var{m}, which must be a fixed-point machine mode.
5212: @var{x} must be valid for mode @var{m}, which must be a fixed-point mode.
5213:
5214: @item (and:@var{m} @var{x} @var{y})
5215: Represents the bitwise logical-and of the values represented by
5216: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
5217: valid only if @var{x} and @var{y} both are valid for mode @var{m},
5218: which must be a fixed-point mode.
5219:
5220: @item (ior:@var{m} @var{x} @var{y})
5221: Represents the bitwise inclusive-or of the values represented by
5222: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
5223: valid only if @var{x} and @var{y} both are valid for mode @var{m},
5224: which must be a fixed-point mode.
5225:
5226: @item (xor:@var{m} @var{x} @var{y})
5227: Represents the bitwise exclusive-or of the values represented by
5228: @var{x} and @var{y}, carried out in machine mode @var{m}. This is
5229: valid only if @var{x} and @var{y} both are valid for mode @var{m},
5230: which must be a fixed-point mode.
5231:
5232: @item (lshift:@var{m} @var{x} @var{c})
5233: Represents the result of logically shifting @var{x} left by @var{c}
5234: places. @var{x} must be valid for the mode @var{m}, a fixed-point
5235: machine mode. @var{c} must be valid for a fixed-point mode;
5236: which mode is determined by the mode called for in the machine
5237: description entry for the left-shift instruction. For example,
5238: on the Vax, the mode of @var{c} is @code{QImode} regardless of @var{m}.
5239:
5240: On some machines, negative values of @var{c} may be meaningful; this
5241: is why logical left shift and arithmetic left shift are distinguished.
5242: For example, Vaxes have no right-shift instructions, and right shifts
5243: are represented as left-shift instructions whose counts happen
5244: to be negative constants or else computed (in a previous instruction)
5245: by negation.
5246:
5247: @item (ashift:@var{m} @var{x} @var{c})
1.1.1.8 root 5248: Like @code{lshift} but for arithmetic left shift.
1.1 root 5249:
5250: @item (lshiftrt:@var{m} @var{x} @var{c})
5251: @itemx (ashiftrt:@var{m} @var{x} @var{c})
1.1.1.8 root 5252: Like @code{lshift} and @code{ashift} but for right shift.
1.1 root 5253:
5254: @item (rotate:@var{m} @var{x} @var{c})
5255: @itemx (rotatert:@var{m} @var{x} @var{c})
5256: Similar but represent left and right rotate.
5257:
5258: @item (abs:@var{m} @var{x})
5259: Represents the absolute value of @var{x}, computed in mode @var{m}.
5260: @var{x} must be valid for @var{m}.
5261:
5262: @item (sqrt:@var{m} @var{x})
5263: Represents the square root of @var{x}, computed in mode @var{m}.
5264: @var{x} must be valid for @var{m}. Most often @var{m} will be
5265: a floating point mode.
5266:
5267: @item (ffs:@var{m} @var{x})
1.1.1.10 root 5268: Represents one plus the index of the least significant 1-bit in
1.1 root 5269: @var{x}, represented as an integer of mode @var{m}. (The value is
5270: zero if @var{x} is zero.) The mode of @var{x} need not be @var{m};
5271: depending on the target machine, various mode combinations may be
5272: valid.
5273: @end table
5274:
5275: @node Comparisons, Bit Fields, Arithmetic, RTL
5276: @section Comparison Operations
5277:
1.1.1.10 root 5278: Comparison operators test a relation on two operands and are considered
5279: to represent a machine-dependent nonzero value (@code{STORE_FLAG_VALUE})
5280: if the relation holds, or zero if it does not. The mode of the
5281: comparison is determined by the operands; they must both be valid for a
5282: common machine mode. A comparison with both operands constant would be
5283: invalid as the machine mode could not be deduced from it, but such a
5284: comparison should never exist in RTL due to constant folding.
1.1 root 5285:
5286: Inequality comparisons come in two flavors, signed and unsigned. Thus,
1.1.1.8 root 5287: there are distinct expression codes @code{gt} and @code{gtu} for signed and
1.1 root 5288: unsigned greater-than. These can produce different results for the same
5289: pair of integer values: for example, 1 is signed greater-than -1 but not
5290: unsigned greater-than, because -1 when regarded as unsigned is actually
5291: @code{0xffffffff} which is greater than 1.
5292:
5293: The signed comparisons are also used for floating point values. Floating
5294: point comparisons are distinguished by the machine modes of the operands.
5295:
5296: The comparison operators may be used to compare the condition codes
5297: @code{(cc0)} against zero, as in @code{(eq (cc0) (const_int 0))}. Such a
5298: construct actually refers to the result of the preceding instruction in
5299: which the condition codes were set. The above example stands for 1 if the
5300: condition codes were set to say ``zero'' or ``equal'', 0 otherwise.
5301: Although the same comparison operators are used for this as may be used in
5302: other contexts on actual data, no confusion can result since the machine
5303: description would never allow both kinds of uses in the same context.
5304:
5305: @table @code
5306: @item (eq @var{x} @var{y})
5307: 1 if the values represented by @var{x} and @var{y} are equal,
5308: otherwise 0.
5309:
5310: @item (ne @var{x} @var{y})
5311: 1 if the values represented by @var{x} and @var{y} are not equal,
5312: otherwise 0.
5313:
5314: @item (gt @var{x} @var{y})
5315: 1 if the @var{x} is greater than @var{y}. If they are fixed-point,
5316: the comparison is done in a signed sense.
5317:
5318: @item (gtu @var{x} @var{y})
1.1.1.8 root 5319: Like @code{gt} but does unsigned comparison, on fixed-point numbers only.
1.1 root 5320:
5321: @item (lt @var{x} @var{y})
5322: @item (ltu @var{x} @var{y})
1.1.1.8 root 5323: Like @code{gt} and @code{gtu} but test for ``less than''.
1.1 root 5324:
5325: @item (ge @var{x} @var{y})
5326: @item (geu @var{x} @var{y})
1.1.1.8 root 5327: Like @code{gt} and @code{gtu} but test for ``greater than or equal''.
1.1 root 5328:
5329: @item (le @var{x} @var{y})
5330: @item (leu @var{x} @var{y})
1.1.1.8 root 5331: Like @code{gt} and @code{gtu} but test for ``less than or equal''.
1.1 root 5332:
5333: @item (if_then_else @var{cond} @var{then} @var{else})
5334: This is not a comparison operation but is listed here because it is
5335: always used in conjunction with a comparison operation. To be
5336: precise, @var{cond} is a comparison expression. This expression
5337: represents a choice, according to @var{cond}, between the value
5338: represented by @var{then} and the one represented by @var{else}.
5339:
1.1.1.8 root 5340: On most machines, @code{if_then_else} expressions are valid only
1.1 root 5341: to express conditional jumps.
5342: @end table
5343:
5344: @node Bit Fields, Conversions, Comparisons, RTL
5345: @section Bit-fields
5346:
5347: Special expression codes exist to represent bit-field instructions.
5348: These types of expressions are lvalues in RTL; they may appear
1.1.1.10 root 5349: on the left side of an assignment, indicating insertion of a value
1.1 root 5350: into the specified bit field.
5351:
5352: @table @code
5353: @item (sign_extract:SI @var{loc} @var{size} @var{pos})
5354: This represents a reference to a sign-extended bit-field contained or
5355: starting in @var{loc} (a memory or register reference). The bit field
5356: is @var{size} bits wide and starts at bit @var{pos}. The compilation
5357: option @code{BITS_BIG_ENDIAN} says which end of the memory unit
5358: @var{pos} counts from.
5359:
5360: Which machine modes are valid for @var{loc} depends on the machine,
5361: but typically @var{loc} should be a single byte when in memory
5362: or a full word in a register.
5363:
5364: @item (zero_extract:SI @var{loc} @var{size} @var{pos})
1.1.1.8 root 5365: Like @code{sign_extract} but refers to an unsigned or zero-extended
1.1 root 5366: bit field. The same sequence of bits are extracted, but they
5367: are filled to an entire word with zeros instead of by sign-extension.
5368: @end table
5369:
5370: @node Conversions, RTL Declarations, Bit Fields, RTL
5371: @section Conversions
5372:
5373: All conversions between machine modes must be represented by
5374: explicit conversion operations. For example, an expression
5375: which is the sum of a byte and a full word cannot be written as
1.1.1.8 root 5376: @code{(plus:SI (reg:QI 34) (reg:SI 80))} because the @code{plus}
1.1 root 5377: operation requires two operands of the same machine mode.
5378: Therefore, the byte-sized operand is enclosed in a conversion
5379: operation, as in
5380:
5381: @example
5382: (plus:SI (sign_extend:SI (reg:QI 34)) (reg:SI 80))
5383: @end example
5384:
5385: The conversion operation is not a mere placeholder, because there
5386: may be more than one way of converting from a given starting mode
5387: to the desired final mode. The conversion operation code says how
5388: to do it.
5389:
5390: @table @code
5391: @item (sign_extend:@var{m} @var{x})
5392: Represents the result of sign-extending the value @var{x}
5393: to machine mode @var{m}. @var{m} must be a fixed-point mode
5394: and @var{x} a fixed-point value of a mode narrower than @var{m}.
5395:
5396: @item (zero_extend:@var{m} @var{x})
5397: Represents the result of zero-extending the value @var{x}
5398: to machine mode @var{m}. @var{m} must be a fixed-point mode
5399: and @var{x} a fixed-point value of a mode narrower than @var{m}.
5400:
5401: @item (float_extend:@var{m} @var{x})
5402: Represents the result of extending the value @var{x}
5403: to machine mode @var{m}. @var{m} must be a floating point mode
5404: and @var{x} a floating point value of a mode narrower than @var{m}.
5405:
5406: @item (truncate:@var{m} @var{x})
5407: Represents the result of truncating the value @var{x}
5408: to machine mode @var{m}. @var{m} must be a fixed-point mode
5409: and @var{x} a fixed-point value of a mode wider than @var{m}.
5410:
5411: @item (float_truncate:@var{m} @var{x})
5412: Represents the result of truncating the value @var{x}
5413: to machine mode @var{m}. @var{m} must be a floating point mode
5414: and @var{x} a floating point value of a mode wider than @var{m}.
5415:
5416: @item (float:@var{m} @var{x})
5417: Represents the result of converting fixed point value @var{x},
5418: regarded as signed, to floating point mode @var{m}.
5419:
5420: @item (unsigned_float:@var{m} @var{x})
5421: Represents the result of converting fixed point value @var{x},
5422: regarded as unsigned, to floating point mode @var{m}.
5423:
5424: @item (fix:@var{m} @var{x})
5425: When @var{m} is a fixed point mode, represents the result of
5426: converting floating point value @var{x} to mode @var{m}, regarded as
5427: signed. How rounding is done is not specified, so this operation may
5428: be used validly in compiling C code only for integer-valued operands.
5429:
5430: @item (unsigned_fix:@var{m} @var{x})
5431: Represents the result of converting floating point value @var{x} to
5432: fixed point mode @var{m}, regarded as unsigned. How rounding is done
5433: is not specified.
5434:
5435: @item (fix:@var{m} @var{x})
5436: When @var{m} is a floating point mode, represents the result of
5437: converting floating point value @var{x} (valid for mode @var{m}) to an
5438: integer, still represented in floating point mode @var{m}, by rounding
5439: towards zero.
5440: @end table
5441:
5442: @node RTL Declarations, Side Effects, Conversions, RTL
5443: @section Declarations
5444:
5445: Declaration expression codes do not represent arithmetic operations
5446: but rather state assertions about their operands.
5447:
5448: @table @code
5449: @item (strict_low_part (subreg:@var{m} (reg:@var{n} @var{r}) 0))
5450: This expression code is used in only one context: operand 0 of a
1.1.1.8 root 5451: @code{set} expression. In addition, the operand of this expression
5452: must be a @code{subreg} expression.
1.1 root 5453:
1.1.1.8 root 5454: The presence of @code{strict_low_part} says that the part of the
1.1 root 5455: register which is meaningful in mode @var{n}, but is not part of
5456: mode @var{m}, is not to be altered. Normally, an assignment to such
5457: a subreg is allowed to have undefined effects on the rest of the
5458: register when @var{m} is less than a word.
5459: @end table
5460:
5461: @node Side Effects, Incdec, RTL Declarations, RTL
5462: @section Side Effect Expressions
5463:
5464: The expression codes described so far represent values, not actions.
5465: But machine instructions never produce values; they are meaningful
5466: only for their side effects on the state of the machine. Special
5467: expression codes are used to represent side effects.
5468:
5469: The body of an instruction is always one of these side effect codes;
5470: the codes described above, which represent values, appear only as
5471: the operands of these.
5472:
5473: @table @code
5474: @item (set @var{lval} @var{x})
5475: Represents the action of storing the value of @var{x} into the place
5476: represented by @var{lval}. @var{lval} must be an expression
1.1.1.8 root 5477: representing a place that can be stored in: @code{reg} (or
5478: @code{subreg} or @code{strict_low_part}), @code{mem}, @code{pc} or
5479: @code{cc0}.@refill
1.1 root 5480:
1.1.1.8 root 5481: If @var{lval} is a @code{reg}, @code{subreg} or @code{mem}, it has a
1.1 root 5482: machine mode; then @var{x} must be valid for that mode.@refill
5483:
1.1.1.8 root 5484: If @var{lval} is a @code{reg} whose machine mode is less than the full
1.1 root 5485: width of the register, then it means that the part of the register
5486: specified by the machine mode is given the specified value and the
5487: rest of the register receives an undefined value. Likewise, if
1.1.1.8 root 5488: @var{lval} is a @code{subreg} whose machine mode is narrower than
1.1 root 5489: @code{SImode}, the rest of the register can be changed in an undefined way.
5490:
1.1.1.8 root 5491: If @var{lval} is a @code{strict_low_part} of a @code{subreg}, then the
1.1 root 5492: part of the register specified by the machine mode of the
1.1.1.8 root 5493: @code{subreg} is given the value @var{x} and the rest of the register
1.1 root 5494: is not changed.@refill
5495:
5496: If @var{lval} is @code{(cc0)}, it has no machine mode, and @var{x} may
5497: have any mode. This represents a ``test'' or ``compare'' instruction.@refill
5498:
5499: If @var{lval} is @code{(pc)}, we have a jump instruction, and the
5500: possibilities for @var{x} are very limited. It may be a
1.1.1.8 root 5501: @code{label_ref} expression (unconditional jump). It may be an
5502: @code{if_then_else} (conditional jump), in which case either the
1.1 root 5503: second or the third operand must be @code{(pc)} (for the case which
1.1.1.8 root 5504: does not jump) and the other of the two must be a @code{label_ref}
5505: (for the case which does jump). @var{x} may also be a @code{mem} or
5506: @code{(plus:SI (pc) @var{y})}, where @var{y} may be a @code{reg} or a
5507: @code{mem}; these unusual patterns are used to represent jumps through
1.1 root 5508: branch tables.@refill
5509:
5510: @item (return)
5511: Represents a return from the current function, on machines where this
5512: can be done with one instruction, such as Vaxes. On machines where a
5513: multi-instruction ``epilogue'' must be executed in order to return
5514: from the function, returning is done by jumping to a label which
1.1.1.8 root 5515: precedes the epilogue, and the @code{return} expression code is never
1.1 root 5516: used.
5517:
5518: @item (call @var{function} @var{nargs})
1.1.1.8 root 5519: Represents a function call. @var{function} is a @code{mem} expression
1.1 root 5520: whose address is the address of the function to be called.
5521: @var{nargs} is an expression which can be used for two purposes: on
5522: some machines it represents the number of bytes of stack argument; on
5523: others, it represents the number of argument registers.
5524:
5525: Each machine has a standard machine mode which @var{function} must
5526: have. The machine description defines macro @code{FUNCTION_MODE} to
5527: expand into the requisite mode name. The purpose of this mode is to
5528: specify what kind of addressing is allowed, on machines where the
5529: allowed kinds of addressing depend on the machine mode being
5530: addressed.
5531:
5532: @item (clobber @var{x})
5533: Represents the storing or possible storing of an unpredictable,
1.1.1.8 root 5534: undescribed value into @var{x}, which must be a @code{reg} or
5535: @code{mem} expression.
1.1 root 5536:
5537: One place this is used is in string instructions that store standard
5538: values into particular hard registers. It may not be worth the
5539: trouble to describe the values that are stored, but it is essential to
5540: inform the compiler that the registers will be altered, lest it
5541: attempt to keep data in them across the string instruction.
5542:
5543: @var{x} may also be null---a null C pointer, no expression at all.
5544: Such a @code{(clobber (null))} expression means that all memory
5545: locations must be presumed clobbered.
5546:
5547: Note that the machine description classifies certain hard registers as
5548: ``call-clobbered''. All function call instructions are assumed by
5549: default to clobber these registers, so there is no need to use
1.1.1.8 root 5550: @code{clobber} expressions to indicate this fact. Also, each function
1.1.1.6 root 5551: call is assumed to have the potential to alter any memory location,
5552: unless the function is declared @code{const}.
1.1 root 5553:
1.1.1.8 root 5554: When a @code{clobber} expression for a register appears inside a
5555: @code{parallel} with other side effects, GNU CC guarantees that the
1.1.1.4 root 5556: register is unoccupied both before and after that insn. Therefore, it
5557: is safe for the assembler code produced by the insn to use the
5558: register as a temporary. You can clobber either a specific hard
5559: register or a pseudo register; in the latter case, GNU CC will
5560: allocate a hard register that is available there for use as a
5561: temporary.
5562:
1.1.1.8 root 5563: If you clobber a pseudo register in this way, use a pseudo register
5564: which appears nowhere else---generate a new one each time. Otherwise,
5565: you may confuse CSE.
5566:
5567: There is one other known use for clobbering a pseudo register in a
5568: @code{parallel}: when one of the input operands of the insn is also
5569: clobbered by the insn. In this case, using the same pseudo register in
5570: the clobber and elsewhere in the insn produces the expected results.
5571:
1.1 root 5572: @item (use @var{x})
5573: Represents the use of the value of @var{x}. It indicates that the
5574: value in @var{x} at this point in the program is needed, even though
5575: it may not be apparent why this is so. Therefore, the compiler will
1.1.1.4 root 5576: not attempt to delete previous instructions whose only effect is to
1.1.1.8 root 5577: store a value in @var{x}. @var{x} must be a @code{reg} expression.
1.1 root 5578:
5579: @item (parallel [@var{x0} @var{x1} @dots{}])
5580: Represents several side effects performed in parallel. The square
1.1.1.8 root 5581: brackets stand for a vector; the operand of @code{parallel} is a
1.1 root 5582: vector of expressions. @var{x0}, @var{x1} and so on are individual
1.1.1.8 root 5583: side effect expressions---expressions of code @code{set}, @code{call},
5584: @code{return}, @code{clobber} or @code{use}.@refill
1.1 root 5585:
5586: ``In parallel'' means that first all the values used in the individual
5587: side-effects are computed, and second all the actual side-effects are
5588: performed. For example,
5589:
5590: @example
5591: (parallel [(set (reg:SI 1) (mem:SI (reg:SI 1)))
5592: (set (mem:SI (reg:SI 1)) (reg:SI 1))])
5593: @end example
5594:
5595: @noindent
5596: says unambiguously that the values of hard register 1 and the memory
5597: location addressed by it are interchanged. In both places where
5598: @code{(reg:SI 1)} appears as a memory address it refers to the value
1.1.1.4 root 5599: in register 1 @emph{before} the execution of the insn.
5600:
1.1.1.8 root 5601: It follows that it is @emph{incorrect} to use @code{parallel} and
5602: expect the result of one @code{set} to be available for the next one.
1.1.1.4 root 5603: For example, people sometimes attempt to represent a jump-if-zero
5604: instruction this way:
5605:
5606: @example
5607: (parallel [(set (cc0) (reg:SI 34))
1.1.1.9 root 5608: (set (pc) (if_then_else
5609: (eq (cc0) (const_int 0))
5610: (label_ref @dots{})
5611: (pc)))])
1.1.1.4 root 5612: @end example
5613:
5614: @noindent
5615: But this is incorrect, because it says that the jump condition depends
5616: on the condition code value @emph{before} this instruction, not on the
5617: new value that is set by this instruction.
1.1 root 5618:
1.1.1.5 root 5619: Peephole optimization, which takes place in together with final assembly
1.1.1.8 root 5620: code output, can produce insns whose patterns consist of a @code{parallel}
1.1 root 5621: whose elements are the operands needed to output the resulting
1.1.1.8 root 5622: assembler code---often @code{reg}, @code{mem} or constant expressions.
1.1 root 5623: This would not be well-formed RTL at any other stage in compilation,
5624: but it is ok then because no further optimization remains to be done.
1.1.1.4 root 5625: However, the definition of the macro @code{NOTICE_UPDATE_CC} must
5626: deal with such insns if you define any peephole optimizations.
1.1 root 5627:
5628: @item (sequence [@var{insns} @dots{}])
5629: Represents a sequence of insns. Each of the @var{insns} that appears
5630: in the vector is suitable for appearing in the chain of insns, so it
1.1.1.8 root 5631: must be an @code{insn}, @code{jump_insn}, @code{call_insn},
5632: @code{code_label}, @code{barrier} or @code{note}.
1.1 root 5633:
1.1.1.8 root 5634: A @code{sequence} RTX never appears in an actual insn. It represents
5635: the sequence of insns that result from a @code{define_expand}
1.1 root 5636: @emph{before} those insns are passed to @code{emit_insn} to insert
5637: them in the chain of insns. When actually inserted, the individual
1.1.1.8 root 5638: sub-insns are separated out and the @code{sequence} is forgotten.
1.1 root 5639: @end table
5640:
5641: Three expression codes appear in place of a side effect, as the body of an
5642: insn, though strictly speaking they do not describe side effects as such:
5643:
5644: @table @code
5645: @item (asm_input @var{s})
5646: Represents literal assembler code as described by the string @var{s}.
5647:
5648: @item (addr_vec:@var{m} [@var{lr0} @var{lr1} @dots{}])
5649: Represents a table of jump addresses. The vector elements @var{lr0},
1.1.1.8 root 5650: etc., are @code{label_ref} expressions. The mode @var{m} specifies
1.1 root 5651: how much space is given to each address; normally @var{m} would be
5652: @code{Pmode}.
5653:
5654: @item (addr_diff_vec:@var{m} @var{base} [@var{lr0} @var{lr1} @dots{}])
5655: Represents a table of jump addresses expressed as offsets from
1.1.1.8 root 5656: @var{base}. The vector elements @var{lr0}, etc., are @code{label_ref}
1.1 root 5657: expressions and so is @var{base}. The mode @var{m} specifies how much
5658: space is given to each address-difference.@refill
5659: @end table
5660:
5661: @node Incdec, Assembler, Side Effects, RTL
5662: @section Embedded Side-Effects on Addresses
5663:
5664: Four special side-effect expression codes appear as memory addresses.
5665:
5666: @table @code
5667: @item (pre_dec:@var{m} @var{x})
5668: Represents the side effect of decrementing @var{x} by a standard
5669: amount and represents also the value that @var{x} has after being
1.1.1.8 root 5670: decremented. @var{x} must be a @code{reg} or @code{mem}, but most
5671: machines allow only a @code{reg}. @var{m} must be the machine mode
1.1 root 5672: for pointers on the machine in use. The amount @var{x} is decremented
5673: by is the length in bytes of the machine mode of the containing memory
5674: reference of which this expression serves as the address. Here is an
5675: example of its use:@refill
5676:
5677: @example
5678: (mem:DF (pre_dec:SI (reg:SI 39)))
5679: @end example
5680:
5681: @noindent
5682: This says to decrement pseudo register 39 by the length of a @code{DFmode}
5683: value and use the result to address a @code{DFmode} value.
5684:
5685: @item (pre_inc:@var{m} @var{x})
5686: Similar, but specifies incrementing @var{x} instead of decrementing it.
5687:
5688: @item (post_dec:@var{m} @var{x})
1.1.1.8 root 5689: Represents the same side effect as @code{pre_dec} but a different
1.1 root 5690: value. The value represented here is the value @var{x} has @i{before}
5691: being decremented.
5692:
5693: @item (post_inc:@var{m} @var{x})
5694: Similar, but specifies incrementing @var{x} instead of decrementing it.
5695: @end table
5696:
5697: These embedded side effect expressions must be used with care. Instruction
5698: patterns may not use them. Until the @samp{flow} pass of the compiler,
5699: they may occur only to represent pushes onto the stack. The @samp{flow}
5700: pass finds cases where registers are incremented or decremented in one
5701: instruction and used as an address shortly before or after; these cases are
5702: then transformed to use pre- or post-increment or -decrement.
5703:
5704: Explicit popping of the stack could be represented with these embedded
5705: side effect operators, but that would not be safe; the instruction
5706: combination pass could move the popping past pushes, thus changing
5707: the meaning of the code.
5708:
5709: An instruction that can be represented with an embedded side effect
1.1.1.8 root 5710: could also be represented using @code{parallel} containing an additional
5711: @code{set} to describe how the address register is altered. This is not
1.1 root 5712: done because machines that allow these operations at all typically
5713: allow them wherever a memory address is called for. Describing them as
5714: additional parallel stores would require doubling the number of entries
5715: in the machine description.
5716:
5717: @node Assembler, Insns, IncDec, RTL
5718: @section Assembler Instructions as Expressions
5719:
1.1.1.8 root 5720: The RTX code @code{asm_operands} represents a value produced by a
1.1 root 5721: user-specified assembler instruction. It is used to represent
5722: an @code{asm} statement with arguments. An @code{asm} statement with
5723: a single output operand, like this:
5724:
5725: @example
1.1.1.6 root 5726: asm ("foo %1,%2,%0" : "=a" (outputvar) : "g" (x + y), "di" (*z));
1.1 root 5727: @end example
5728:
5729: @noindent
1.1.1.8 root 5730: is represented using a single @code{asm_operands} RTX which represents
1.1 root 5731: the value that is stored in @code{outputvar}:
5732:
5733: @example
5734: (set @var{rtx-for-outputvar}
5735: (asm_operands "foo %1,%2,%0" "a" 0
5736: [@var{rtx-for-addition-result} @var{rtx-for-*z}]
5737: [(asm_input:@var{m1} "g")
5738: (asm_input:@var{m2} "di")]))
5739: @end example
5740:
5741: @noindent
1.1.1.8 root 5742: Here the operands of the @code{asm_operands} RTX are the assembler
1.1 root 5743: template string, the output-operand's constraint, the index-number of the
5744: output operand among the output operands specified, a vector of input
5745: operand RTX's, and a vector of input-operand modes and constraints. The
5746: mode @var{m1} is the mode of the sum @code{x+y}; @var{m2} is that of
5747: @code{*z}.
5748:
5749: When an @code{asm} statement has multiple output values, its insn has
1.1.1.8 root 5750: several such @code{set} RTX's inside of a @code{parallel}. Each @code{set}
5751: contains a @code{asm_operands}; all of these share the same assembler
1.1 root 5752: template and vectors, but each contains the constraint for the respective
5753: output operand. They are also distinguished by the output-operand index
5754: number, which is 0, 1, @dots{} for successive output operands.
5755:
5756: @node Insns, Calls, Assembler, RTL
5757: @section Insns
5758:
5759: The RTL representation of the code for a function is a doubly-linked
5760: chain of objects called @dfn{insns}. Insns are expressions with
5761: special codes that are used for no other purpose. Some insns are
5762: actual instructions; others represent dispatch tables for @code{switch}
5763: statements; others represent labels to jump to or various sorts of
5764: declarative information.
5765:
5766: In addition to its own specific data, each insn must have a unique id-number
5767: that distinguishes it from all other insns in the current function, and
5768: chain pointers to the preceding and following insns. These three fields
5769: occupy the same position in every insn, independent of the expression code
5770: of the insn. They could be accessed with @code{XEXP} and @code{XINT},
5771: but instead three special macros are always used:
5772:
5773: @table @code
5774: @item INSN_UID (@var{i})
5775: Accesses the unique id of insn @var{i}.
5776:
5777: @item PREV_INSN (@var{i})
5778: Accesses the chain pointer to the insn preceding @var{i}.
5779: If @var{i} is the first insn, this is a null pointer.
5780:
5781: @item NEXT_INSN (@var{i})
5782: Accesses the chain pointer to the insn following @var{i}.
5783: If @var{i} is the last insn, this is a null pointer.
5784: @end table
5785:
5786: The @code{NEXT_INSN} and @code{PREV_INSN} pointers must always
1.1.1.6 root 5787: correspond: if @var{insn} is not the first insn,
1.1 root 5788:
5789: @example
5790: NEXT_INSN (PREV_INSN (@var{insn})) == @var{insn}
5791: @end example
5792:
5793: @noindent
5794: is always true.
5795:
5796: Every insn has one of the following six expression codes:
5797:
1.1.1.8 root 5798: @table @code
1.1 root 5799: @item insn
1.1.1.8 root 5800: The expression code @code{insn} is used for instructions that do not jump
5801: and do not do function calls. Insns with code @code{insn} have four
1.1 root 5802: additional fields beyond the three mandatory ones listed above.
5803: These four are described in a table below.
5804:
5805: @item jump_insn
1.1.1.8 root 5806: The expression code @code{jump_insn} is used for instructions that may jump
5807: (or, more generally, may contain @code{label_ref} expressions).
5808: @code{jump_insn} insns have the same extra fields as @code{insn} insns,
1.1.1.10 root 5809: accessed in the same way. If there is an instruction to return from the
5810: current function, it is recorded as a @code{jump_insn}.
1.1 root 5811:
5812: @item call_insn
1.1.1.8 root 5813: The expression code @code{call_insn} is used for instructions that may do
1.1 root 5814: function calls. It is important to distinguish these instructions because
5815: they imply that certain registers and memory locations may be altered
5816: unpredictably.
5817:
1.1.1.8 root 5818: @code{call_insn} insns have the same extra fields as @code{insn} insns,
1.1 root 5819: accessed in the same way.
5820:
5821: @item code_label
1.1.1.8 root 5822: A @code{code_label} insn represents a label that a jump insn can jump to.
1.1 root 5823: It contains one special field of data in addition to the three standard ones.
5824: It is used to hold the @dfn{label number}, a number that identifies this
5825: label uniquely among all the labels in the compilation (not just in the
5826: current function). Ultimately, the label is represented in the assembler
5827: output as an assembler label @samp{L@var{n}} where @var{n} is the label number.
5828:
5829: @item barrier
5830: Barriers are placed in the instruction stream after unconditional
5831: jump instructions to indicate that the jumps are unconditional.
5832: They contain no information beyond the three standard fields.
5833:
5834: @item note
1.1.1.8 root 5835: @code{note} insns are used to represent additional debugging and
1.1 root 5836: declarative information. They contain two nonstandard fields, an
5837: integer which is accessed with the macro @code{NOTE_LINE_NUMBER} and a
5838: string accessed with @code{NOTE_SOURCE_FILE}.
5839:
5840: If @code{NOTE_LINE_NUMBER} is positive, the note represents the
5841: position of a source line and @code{NOTE_SOURCE_FILE} is the source file name
5842: that the line came from. These notes control generation of line
5843: number data in the assembler output.
5844:
5845: Otherwise, @code{NOTE_LINE_NUMBER} is not really a line number but a
5846: code with one of the following values (and @code{NOTE_SOURCE_FILE}
5847: must contain a null pointer):
5848:
5849: @table @code
5850: @item NOTE_INSN_DELETED
5851: Such a note is completely ignorable. Some passes of the compiler
5852: delete insns by altering them into notes of this kind.
5853:
5854: @item NOTE_INSN_BLOCK_BEG
5855: @itemx NOTE_INSN_BLOCK_END
5856: These types of notes indicate the position of the beginning and end
5857: of a level of scoping of variable names. They control the output
5858: of debugging information.
5859:
5860: @item NOTE_INSN_LOOP_BEG
5861: @itemx NOTE_INSN_LOOP_END
5862: These types of notes indicate the position of the beginning and end
5863: of a @code{while} or @code{for} loop. They enable the loop optimizer
5864: to find loops quickly.
1.1.1.6 root 5865: @item NOTE_INSN_FUNCTION_END
5866: Appears near the end of the function body, just before the label that
5867: @code{return} statements jump to (on machine where a single instruction
5868: does not suffice for returning). This note may be deleted by jump
5869: optimization.
5870: @item NOTE_INSN_SETJMP
5871: Appears following each call to @code{setjmp} or a related function.
1.1.1.7 root 5872:
1.1.1.10 root 5873: @item NOTE_INSN_LOOP_CONT
1.1.1.7 root 5874: Appears at the place in a loop that @code{continue} statements jump to.
1.1 root 5875: @end table
1.1.1.7 root 5876:
5877: These codes are printed symbolically when they appear in debugging dumps.
1.1 root 5878: @end table
5879:
1.1.1.6 root 5880: The machine mode of an insn is normally zero (@code{VOIDmode}), but the
5881: reload pass sets it to @code{QImode} if the insn needs reloading.
5882:
1.1.1.8 root 5883: Here is a table of the extra fields of @code{insn}, @code{jump_insn}
5884: and @code{call_insn} insns:
1.1 root 5885:
5886: @table @code
5887: @item PATTERN (@var{i})
5888: An expression for the side effect performed by this insn.
5889:
1.1.1.6 root 5890: @item INSN_CODE (@var{i})
5891: An integer that says which pattern in the machine description matches
5892: this insn, or -1 if the matching has not yet been attempted.
5893:
5894: Such matching is never attempted and this field is not used on an insn
1.1.1.8 root 5895: whose pattern consists of a single @code{use}, @code{clobber},
5896: @code{asm}, @code{addr_vec} or @code{addr_diff_vec} expression.
1.1 root 5897:
5898: @item LOG_LINKS (@var{i})
1.1.1.8 root 5899: A list (chain of @code{insn_list} expressions) of previous ``related''
1.1 root 5900: insns: insns which store into registers values that are used for the
5901: first time in this insn. (An additional constraint is that neither a
5902: jump nor a label may come between the related insns). This list is
5903: set up by the flow analysis pass; it is a null pointer until then.
5904:
1.1.1.6 root 5905: @item REG_NOTES (@var{i})
1.1.1.8 root 5906: A list (chain of @code{expr_list} expressions) giving information
1.1.1.6 root 5907: about the usage of registers in this insn. This list is set up by the
5908: flow analysis pass; it is a null pointer until then.
1.1 root 5909: @end table
5910:
1.1.1.8 root 5911: The @code{LOG_LINKS} field of an insn is a chain of @code{insn_list}
1.1 root 5912: expressions. Each of these has two operands: the first is an insn,
1.1.1.8 root 5913: and the second is another @code{insn_list} expression (the next one in
5914: the chain). The last @code{insn_list} in the chain has a null pointer
1.1 root 5915: as second operand. The significant thing about the chain is which
1.1.1.8 root 5916: insns appear in it (as first operands of @code{insn_list}
1.1 root 5917: expressions). Their order is not significant.
5918:
5919: The @code{REG_NOTES} field of an insn is a similar chain but of
1.1.1.8 root 5920: @code{expr_list} expressions instead of @code{insn_list}. There are
1.1.1.5 root 5921: several kinds of register notes, which are distinguished by the machine
1.1.1.8 root 5922: mode of the @code{expr_list}, which in a register note is really
1.1.1.5 root 5923: understood as being an @code{enum reg_note}. The first operand @var{op}
1.1.1.8 root 5924: of the @code{expr_list} is data whose meaning depends on the kind of
1.1.1.5 root 5925: note. Here are the kinds of register note:
1.1 root 5926:
5927: @table @code
5928: @item REG_DEAD
5929: The register @var{op} dies in this insn; that is to say, altering the
5930: value immediately after this insn would not affect the future behavior
5931: of the program.
5932:
5933: @item REG_INC
5934: The register @var{op} is incremented (or decremented; at this level
5935: there is no distinction) by an embedded side effect inside this insn.
1.1.1.8 root 5936: This means it appears in a @code{post_inc}, @code{pre_inc},
5937: @code{post_dec} or @code{pre_dec} RTX.
1.1 root 5938:
5939: @item REG_EQUIV
5940: The register that is set by this insn will be equal to @var{op} at run
5941: time, and could validly be replaced in all its occurrences by
5942: @var{op}. (``Validly'' here refers to the data flow of the program;
5943: simple replacement may make some insns invalid.)
5944:
5945: The value which the insn explicitly copies into the register may look
5946: different from @var{op}, but they will be equal at run time.
5947:
5948: For example, when a constant is loaded into a register that is never
5949: assigned any other value, this kind of note is used.
5950:
5951: When a parameter is copied into a pseudo-register at entry to a function,
5952: a note of this kind records that the register is equivalent to the stack
5953: slot where the parameter was passed. Although in this case the register
5954: may be set by other insns, it is still valid to replace the register
5955: by the stack slot throughout the function.
5956:
5957: @item REG_EQUAL
5958: The register that is set by this insn will be equal to @var{op} at run
5959: time at the end of this insn (but not necessarily elsewhere in the
5960: function).
5961:
5962: The RTX @var{op} is typically an arithmetic expression. For example,
5963: when a sequence of insns such as a library call is used to perform an
5964: arithmetic operation, this kind of note is attached to the insn that
5965: produces or copies the final value. It tells the CSE pass how to
5966: think of that value.
5967:
5968: @item REG_RETVAL
5969: This insn copies the value of a library call, and @var{op} is the
5970: first insn that was generated to set up the arguments for the library
5971: call.
5972:
5973: Flow analysis uses this note to delete all of a library call whose
5974: result is dead.
5975:
5976: @item REG_WAS_0
5977: The register @var{op} contained zero before this insn. You can rely
5978: on this note if it is present; its absence implies nothing.
5979:
5980: @item REG_LIBCALL
5981: This is the inverse of @code{REG_RETVAL}: it is placed on the first
5982: insn of a library call, and it points to the last one.
5983:
5984: Loop optimization uses this note to move an entire library call out
5985: of a loop when its value is constant.
5986:
5987: @item REG_NONNEG
5988: The register @var{op} is known to have nonnegative value when this
5989: insn is reached.
5990: @end table
5991:
1.1.1.8 root 5992: For convenience, the machine mode in an @code{insn_list} or
5993: @code{expr_list} is printed using these symbolic codes in debugging dumps.
1.1.1.7 root 5994:
1.1.1.8 root 5995: The only difference between the expression codes @code{insn_list} and
5996: @code{expr_list} is that the first operand of an @code{insn_list} is
1.1 root 5997: assumed to be an insn and is printed in debugging dumps as the insn's
1.1.1.8 root 5998: unique id; the first operand of an @code{expr_list} is printed in the
1.1.1.7 root 5999: ordinary way as an expression.
1.1 root 6000:
6001: @node Calls, Sharing, Insns, RTL
6002: @section RTL Representation of Function-Call Insns
6003:
1.1.1.8 root 6004: Insns that call subroutines have the RTL expression code @code{call_insn}.
1.1 root 6005: These insns must satisfy special rules, and their bodies must use a special
1.1.1.8 root 6006: RTL expression code, @code{call}.
1.1 root 6007:
1.1.1.8 root 6008: A @code{call} expression has two operands, as follows:
1.1 root 6009:
6010: @example
1.1.1.6 root 6011: (call (mem:@var{fm} @var{addr}) @var{nbytes})
1.1 root 6012: @end example
6013:
6014: @noindent
6015: Here @var{nbytes} is an operand that represents the number of bytes of
6016: argument data being passed to the subroutine, @var{fm} is a machine mode
6017: (which must equal as the definition of the @code{FUNCTION_MODE} macro in
6018: the machine description) and @var{addr} represents the address of the
6019: subroutine.
6020:
1.1.1.8 root 6021: For a subroutine that returns no value, the @code{call} RTX as shown above
1.1 root 6022: is the entire body of the insn.
6023:
6024: For a subroutine that returns a value whose mode is not @code{BLKmode},
6025: the value is returned in a hard register. If this register's number is
6026: @var{r}, then the body of the call insn looks like this:
6027:
6028: @example
6029: (set (reg:@var{m} @var{r})
1.1.1.9 root 6030: (call (mem:@var{fm} @var{addr}) @var{nbytes}))
1.1 root 6031: @end example
6032:
6033: @noindent
6034: This RTL expression makes it clear (to the optimizer passes) that the
6035: appropriate register receives a useful value in this insn.
6036:
6037: Immediately after RTL generation, if the value of the subroutine is
6038: actually used, this call insn is always followed closely by an insn which
6039: refers to the register @var{r}. This remains true through all the
6040: optimizer passes until cross jumping occurs.
6041:
6042: The following insn has one of two forms. Either it copies the value into a
6043: pseudo-register, like this:
6044:
6045: @example
6046: (set (reg:@var{m} @var{p}) (reg:@var{m} @var{r}))
6047: @end example
6048:
6049: @noindent
6050: or (in the case where the calling function will simply return whatever
6051: value the call produced, and no operation is needed to do this):
6052:
6053: @example
6054: (use (reg:@var{m} @var{r}))
6055: @end example
6056:
6057: @noindent
6058: Between the call insn and this following insn there may intervene only a
1.1.1.8 root 6059: stack-adjustment insn (and perhaps some @code{note} insns).
1.1 root 6060:
6061: When a subroutine returns a @code{BLKmode} value, it is handled by
6062: passing to the subroutine the address of a place to store the value.
6063: So the call insn itself does not ``return'' any value, and it has the
6064: same RTL form as a call that returns nothing.
6065:
6066: @node Sharing,, Calls, RTL
6067: @section Structure Sharing Assumptions
6068:
6069: The compiler assumes that certain kinds of RTL expressions are unique;
6070: there do not exist two distinct objects representing the same value.
6071: In other cases, it makes an opposite assumption: that no RTL expression
6072: object of a certain kind appears in more than one place in the
6073: containing structure.
6074:
6075: These assumptions refer to a single function; except for the RTL
6076: objects that describe global variables and external functions,
6077: no RTL objects are common to two functions.
6078:
6079: @itemize @bullet
6080: @item
1.1.1.8 root 6081: Each pseudo-register has only a single @code{reg} object to represent it,
1.1 root 6082: and therefore only a single machine mode.
6083:
6084: @item
1.1.1.8 root 6085: For any symbolic label, there is only one @code{symbol_ref} object
1.1 root 6086: referring to it.
6087:
6088: @item
1.1.1.8 root 6089: There is only one @code{const_int} expression with value zero,
1.1 root 6090: and only one with value one.
6091:
6092: @item
1.1.1.8 root 6093: There is only one @code{pc} expression.
1.1 root 6094:
6095: @item
1.1.1.8 root 6096: There is only one @code{cc0} expression.
1.1 root 6097:
6098: @item
1.1.1.8 root 6099: There is only one @code{const_double} expression with mode
1.1 root 6100: @code{SFmode} and value zero, and only one with mode @code{DFmode} and
6101: value zero.
6102:
6103: @item
1.1.1.8 root 6104: No @code{label_ref} appears in more than one place in the RTL
1.1 root 6105: structure; in other words, it is safe to do a tree-walk of all the
1.1.1.8 root 6106: insns in the function and assume that each time a @code{label_ref} is
1.1 root 6107: seen it is distinct from all others that are seen.
6108:
6109: @item
1.1.1.8 root 6110: Only one @code{mem} object is normally created for each static
1.1 root 6111: variable or stack slot, so these objects are frequently shared in all
6112: the places they appear. However, separate but equal objects for these
6113: variables are occasionally made.
6114:
6115: @item
1.1.1.5 root 6116: When a single @code{asm} statement has multiple output operands,
6117: a distinct @code{asm_operands} RTX is made for each output operand.
6118: However, these all share the vector which contains the sequence of
6119: input operands. Because this sharing is used later on to test whether
6120: two @code{asm_operands} RTX's come from the same statement, the sharing
6121: must be guaranteed to be preserved.
6122:
6123: @item
1.1 root 6124: No RTL object appears in more than one place in the RTL structure
6125: except as described above. Many passes of the compiler rely on this
6126: by assuming that they can modify RTL objects in place without unwanted
6127: side-effects on other insns.
6128:
6129: @item
6130: During initial RTL generation, shared structure is freely introduced.
6131: After all the RTL for a function has been generated, all shared
6132: structure is copied by @code{unshare_all_rtl} in @file{emit-rtl.c},
6133: after which the above rules are guaranteed to be followed.
6134:
6135: @item
6136: During the combiner pass, shared structure with an insn can exist
6137: temporarily. However, the shared structure is copied before the
6138: combiner is finished with the insn. This is done by
1.1.1.8 root 6139: @code{copy_substitutions} in @file{combine.c}.
1.1 root 6140: @end itemize
6141:
6142: @node Machine Desc, Machine Macros, RTL, Top
6143: @chapter Machine Descriptions
6144:
6145: A machine description has two parts: a file of instruction patterns
6146: (@file{.md} file) and a C header file of macro definitions.
6147:
6148: The @file{.md} file for a target machine contains a pattern for each
6149: instruction that the target machine supports (or at least each instruction
6150: that is worth telling the compiler about). It may also contain comments.
6151: A semicolon causes the rest of the line to be a comment, unless the semicolon
6152: is inside a quoted string.
6153:
6154: See the next chapter for information on the C header file.
6155:
6156: @menu
6157: * Patterns:: How to write instruction patterns.
1.1.1.8 root 6158: * Example:: An explained example of a @code{define_insn} pattern.
1.1 root 6159: * RTL Template:: The RTL template defines what insns match a pattern.
6160: * Output Template:: The output template says how to make assembler code
6161: from such an insn.
6162: * Output Statement:: For more generality, write C code to output
6163: the assembler code.
6164: * Constraints:: When not all operands are general operands.
6165: * Standard Names:: Names mark patterns to use for code generation.
6166: * Pattern Ordering:: When the order of patterns makes a difference.
6167: * Dependent Patterns:: Having one pattern may make you need another.
6168: * Jump Patterns:: Special considerations for patterns for jump insns.
6169: * Peephole Definitions::Defining machine-specific peephole optimizations.
6170: * Expander Definitions::Generating a sequence of several RTL insns
6171: for a standard operation.
6172: @end menu
6173:
6174: @node Patterns, Example, Machine Desc, Machine Desc
6175: @section Everything about Instruction Patterns
6176:
6177: Each instruction pattern contains an incomplete RTL expression, with pieces
6178: to be filled in later, operand constraints that restrict how the pieces can
6179: be filled in, and an output pattern or C code to generate the assembler
1.1.1.8 root 6180: output, all wrapped up in a @code{define_insn} expression.
1.1 root 6181:
1.1.1.8 root 6182: A @code{define_insn} is an RTL expression containing four or five operands:
1.1 root 6183:
6184: @enumerate
6185: @item
6186: An optional name. The presence of a name indicate that this instruction
6187: pattern can perform a certain standard job for the RTL-generation
6188: pass of the compiler. This pass knows certain names and will use
6189: the instruction patterns with those names, if the names are defined
6190: in the machine description.
6191:
6192: The absence of a name is indicated by writing an empty string
6193: where the name should go. Nameless instruction patterns are never
6194: used for generating RTL code, but they may permit several simpler insns
6195: to be combined later on.
6196:
6197: Names that are not thus known and used in RTL-generation have no
6198: effect; they are equivalent to no name at all.
6199:
6200: @item
6201: The @dfn{RTL template} (@pxref{RTL Template}) is a vector of
6202: incomplete RTL expressions which show what the instruction should look
1.1.1.8 root 6203: like. It is incomplete because it may contain @code{match_operand}
6204: and @code{match_dup} expressions that stand for operands of the
1.1 root 6205: instruction.
6206:
1.1.1.10 root 6207: If the vector has only one element, that element is the template for the
6208: instruction pattern. If the vector has multiple elements, then the
6209: instruction pattern is a @code{parallel} expression containing the
6210: elements described.
1.1 root 6211:
6212: @item
6213: A condition. This is a string which contains a C expression that is
6214: the final test to decide whether an insn body matches this pattern.
6215:
6216: For a named pattern, the condition (if present) may not depend on
6217: the data in the insn being matched, but only the target-machine-type
6218: flags. The compiler needs to test these conditions during
6219: initialization in order to learn exactly which named instructions are
6220: available in a particular run.
6221:
6222: For nameless patterns, the condition is applied only when matching an
6223: individual insn, and only after the insn has matched the pattern's
6224: recognition template. The insn's operands may be found in the vector
6225: @code{operands}.
6226:
6227: @item
6228: The @dfn{output template}: a string that says how to output matching
6229: insns as assembler code. @samp{%} in this string specifies where
6230: to substitute the value of an operand. @xref{Output Template}.
6231:
6232: When simple substitution isn't general enough, you can specify a piece
6233: of C code to compute the output. @xref{Output Statement}.
6234:
6235: @item
6236: Optionally, some @dfn{machine-specific information}. The meaning
6237: of this information is defined only by an individual machine description;
6238: typically it might say whether this insn alters the condition codes,
6239: or how many bytes of output it generates.
6240:
6241: This operand is written as a string containing a C initializer
6242: (complete with braces) for the structure type @code{INSN_MACHINE_INFO},
6243: whose definition is up to you (@pxref{Misc}).
6244: @end enumerate
6245:
6246: @node Example, RTL Template, Patterns, Machine Desc
1.1.1.8 root 6247: @section Example of @code{define_insn}
1.1 root 6248:
6249: Here is an actual example of an instruction pattern, for the 68000/68020.
6250:
6251: @example
6252: (define_insn "tstsi"
6253: [(set (cc0)
6254: (match_operand:SI 0 "general_operand" "rm"))]
6255: ""
6256: "*
6257: @{ if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
6258: return \"tstl %0\";
6259: return \"cmpl #0,%0\"; @}")
6260: @end example
6261:
6262: This is an instruction that sets the condition codes based on the value of
6263: a general operand. It has no condition, so any insn whose RTL description
6264: has the form shown may be handled according to this pattern. The name
6265: @samp{tstsi} means ``test a @code{SImode} value'' and tells the RTL generation
6266: pass that, when it is necessary to test such a value, an insn to do so
6267: can be constructed using this pattern.
6268:
6269: The output control string is a piece of C code which chooses which
6270: output template to return based on the kind of operand and the specific
6271: type of CPU for which code is being generated.
6272:
6273: @samp{"rm"} is an operand constraint. Its meaning is explained below.
6274:
6275: @node RTL Template, Output Template, Example, Machine Desc
6276: @section RTL Template for Generating and Recognizing Insns
6277:
6278: The RTL template is used to define which insns match the particular pattern
6279: and how to find their operands. For named patterns, the RTL template also
6280: says how to construct an insn from specified operands.
6281:
6282: Construction involves substituting specified operands into a copy of the
6283: template. Matching involves determining the values that serve as the
6284: operands in the insn being matched. Both of these activities are
6285: controlled by special expression types that direct matching and
6286: substitution of the operands.
6287:
6288: @table @code
1.1.1.8 root 6289: @item (match_operand:@var{m} @var{n} @var{pred} @var{constraint})
1.1 root 6290: This expression is a placeholder for operand number @var{n} of
6291: the insn. When constructing an insn, operand number @var{n}
6292: will be substituted at this point. When matching an insn, whatever
6293: appears at this position in the insn will be taken as operand
1.1.1.8 root 6294: number @var{n}; but it must satisfy @var{pred} or this instruction
1.1 root 6295: pattern will not match at all.
6296:
6297: Operand numbers must be chosen consecutively counting from zero in
1.1.1.8 root 6298: each instruction pattern. There may be only one @code{match_operand}
1.1 root 6299: expression in the pattern for each operand number. Usually operands
1.1.1.8 root 6300: are numbered in the order of appearance in @code{match_operand}
1.1 root 6301: expressions.
6302:
1.1.1.8 root 6303: @var{pred} is a string that is the name of a C function that accepts
6304: two arguments, an expression and a machine mode. During matching, the
6305: function will be called with the putative operand as the expression
6306: and @var{m} as the mode argument. If it returns zero, this
6307: instruction pattern fails to match. @var{pred} may be an empty
6308: string; then it means no test is to be done on the operand,
6309: so anything which occurs in this position is valid.
6310:
6311: @var{constraint} controls reloading and the choice of the best register
6312: class to use for a value, as explained later (@pxref{Constraints}).
6313:
6314: People are often unclear on the difference between the constraint and the
6315: predicate. The predicate helps decide whether a given insn matches the
6316: pattern. The constraint plays no role in this decision; instead, it
6317: controls various decisions in the case of an insn which does match.
6318:
6319: Most often, @var{pred} is @code{"general_operand"}. This function checks
6320: that the putative operand is either a constant, a register or a memory
6321: reference, and that it is valid for mode @var{m}.
1.1 root 6322:
1.1.1.8 root 6323: For an operand that must be a register, @var{pred} should be
1.1 root 6324: @code{"register_operand"}. It would be valid to use
6325: @code{"general_operand"}, since the reload pass would copy any
6326: non-register operands through registers, but this would make GNU CC do
6327: extra work, and it would prevent the register allocator from doing the
6328: best possible job.
6329:
1.1.1.8 root 6330: For an operand that must be a constant, either @var{pred} should be
1.1 root 6331: @code{"immediate_operand"}, or the instruction pattern's extra
6332: condition should check for constants, or both. You cannot expect the
6333: constraints to do this work! If the constraints allow only constants,
6334: but the predicate allows something else, the compiler will crash when
6335: that case arises.
6336:
6337: @item (match_dup @var{n})
6338: This expression is also a placeholder for operand number @var{n}.
6339: It is used when the operand needs to appear more than once in the
6340: insn.
6341:
1.1.1.8 root 6342: In construction, @code{match_dup} behaves exactly like
6343: @code{match_operand}: the operand is substituted into the insn being
6344: constructed. But in matching, @code{match_dup} behaves differently.
1.1 root 6345: It assumes that operand number @var{n} has already been determined by
1.1.1.8 root 6346: a @code{match_operand} appearing earlier in the recognition template,
1.1 root 6347: and it matches only an identical-looking expression.
6348:
1.1.1.4 root 6349: @item (match_operator:@var{m} @var{n} "@var{predicate}" [@var{operands}@dots{}])
6350: This pattern is a kind of placeholder for a variable RTL expression
6351: code.
6352:
6353: When constructing an insn, it stands for an RTL expression whose
6354: expression code is taken from that of operand @var{n}, and whose
6355: operands are constructed from the patterns @var{operands}.
6356:
6357: When matching an expression, it matches an expression if the function
6358: @var{predicate} returns nonzero on that expression @emph{and} the
6359: patterns @var{operands} match the operands of the expression.
6360:
6361: Suppose that the function @code{commutative_operator} is defined as
6362: follows, to match any expression whose operator is one of the six
6363: commutative arithmetic operators of RTL and whose mode is @var{mode}:
6364:
6365: @example
6366: int
6367: commutative_operator (x, mode)
6368: rtx x;
6369: enum machine_mode mode;
6370: @{
6371: enum rtx_code code = GET_CODE (x);
6372: if (GET_MODE (x) != mode)
6373: return 0;
6374: return (code == PLUS || code == MULT || code == UMULT
6375: || code == AND || code == IOR || code == XOR);
6376: @}
6377: @end example
6378:
6379: Then the following pattern will match any RTL expression consisting
6380: of a commutative operator applied to two general operands:
6381:
6382: @example
6383: (match_operator:SI 2 "commutative_operator"
6384: [(match_operand:SI 3 "general_operand" "g")
6385: (match_operand:SI 4 "general_operand" "g")])
6386: @end example
6387:
6388: Here the vector @code{[@var{operands}@dots{}]} contains two patterns
6389: because the expressions to be matched all contain two operands.
6390:
6391: When this pattern does match, the two operands of the commutative
6392: operator are recorded as operands 3 and 4 of the insn. (This is done
1.1.1.8 root 6393: by the two instances of @code{match_operand}.) Operand 2 of the insn
1.1.1.4 root 6394: will be the entire commutative expression: use @code{GET_CODE
6395: (operands[2])} to see which commutative operator was used.
6396:
1.1.1.8 root 6397: The machine mode @var{m} of @code{match_operator} works like that of
6398: @code{match_operand}: it is passed as the second argument to the
1.1.1.4 root 6399: predicate function, and that function is solely responsible for
6400: deciding whether the expression to be matched ``has'' that mode.
6401:
6402: When constructing an insn, argument 2 of the gen-function will specify
6403: the operation (i.e. the expression code) for the expression to be
6404: made. It should be an RTL expression, whose expression code is copied
6405: into a new expression whose operands are arguments 3 and 4 of the
6406: gen-function. The subexpressions of argument 2 are not used;
6407: only its expression code matters.
6408:
1.1.1.8 root 6409: There is no way to specify constraints in @code{match_operator}. The
6410: operand of the insn which corresponds to the @code{match_operator}
1.1.1.4 root 6411: never has any constraints because it is never reloaded as a whole.
6412: However, if parts of its @var{operands} are matched by
1.1.1.8 root 6413: @code{match_operand} patterns, those parts may have constraints of
1.1.1.4 root 6414: their own.
6415:
1.1 root 6416: @item (address (match_operand:@var{m} @var{n} "address_operand" ""))
6417: This complex of expressions is a placeholder for an operand number
6418: @var{n} in a ``load address'' instruction: an operand which specifies
6419: a memory location in the usual way, but for which the actual operand
6420: value used is the address of the location, not the contents of the
6421: location.
6422:
1.1.1.8 root 6423: @code{address} expressions never appear in RTL code, only in machine
1.1 root 6424: descriptions. And they are used only in machine descriptions that do
6425: not use the operand constraint feature. When operand constraints are
6426: in use, the letter @samp{p} in the constraint serves this purpose.
6427:
6428: @var{m} is the machine mode of the @emph{memory location being
6429: addressed}, not the machine mode of the address itself. That mode is
6430: always the same on a given target machine (it is @code{Pmode}, which
6431: normally is @code{SImode}), so there is no point in mentioning it;
1.1.1.8 root 6432: thus, no machine mode is written in the @code{address} expression. If
1.1 root 6433: some day support is added for machines in which addresses of different
6434: kinds of objects appear differently or are used differently (such as
6435: the PDP-10), different formats would perhaps need different machine
1.1.1.8 root 6436: modes and these modes might be written in the @code{address}
1.1 root 6437: expression.
6438: @end table
6439:
6440: @node Output Template, Output Statement, RTL Template, Machine Desc
6441: @section Output Templates and Operand Substitution
6442:
1.1.1.6 root 6443: The @dfn{output template} is a string which specifies how to output the
6444: assembler code for an instruction pattern. Most of the template is a
6445: fixed string which is output literally. The character @samp{%} is used
6446: to specify where to substitute an operand; it can also be used to
6447: identify places where different variants of the assembler require
1.1 root 6448: different syntax.
6449:
6450: In the simplest case, a @samp{%} followed by a digit @var{n} says to output
6451: operand @var{n} at that point in the string.
6452:
6453: @samp{%} followed by a letter and a digit says to output an operand in an
6454: alternate fashion. Four letters have standard, built-in meanings described
6455: below. The machine description macro @code{PRINT_OPERAND} can define
6456: additional letters with nonstandard meanings.
6457:
6458: @samp{%c@var{digit}} can be used to substitute an operand that is a
6459: constant value without the syntax that normally indicates an immediate
6460: operand.
6461:
6462: @samp{%n@var{digit}} is like @samp{%c@var{digit}} except that the value of
6463: the constant is negated before printing.
6464:
6465: @samp{%a@var{digit}} can be used to substitute an operand as if it were a
6466: memory reference, with the actual operand treated as the address. This may
6467: be useful when outputting a ``load address'' instruction, because often the
6468: assembler syntax for such an instruction requires you to write the operand
6469: as if it were a memory reference.
6470:
6471: @samp{%l@var{digit}} is used to substitute a @code{label_ref} into a jump
6472: instruction.
6473:
6474: @samp{%} followed by a punctuation character specifies a substitution that
6475: does not use an operand. Only one case is standard: @samp{%%} outputs a
6476: @samp{%} into the assembler code. Other nonstandard cases can be
1.1.1.8 root 6477: defined in the @code{PRINT_OPERAND} macro. You must also define
6478: which punctuation characters are valid with the
6479: @code{PRINT_OPERAND_PUNCT_VALID_P} macro.
1.1 root 6480:
6481: The template may generate multiple assembler instructions. Write the text
6482: for the instructions, with @samp{\;} between them.
6483:
1.1.1.6 root 6484: When the RTL contains two operands which are required by constraint to match
1.1 root 6485: each other, the output template must refer only to the lower-numbered operand.
6486: Matching operands are not always identical, and the rest of the compiler
6487: arranges to put the proper RTL expression for printing into the lower-numbered
6488: operand.
6489:
6490: One use of nonstandard letters or punctuation following @samp{%} is to
6491: distinguish between different assembler languages for the same machine; for
6492: example, Motorola syntax versus MIT syntax for the 68000. Motorola syntax
6493: requires periods in most opcode names, while MIT syntax does not. For
6494: example, the opcode @samp{movel} in MIT syntax is @samp{move.l} in Motorola
6495: syntax. The same file of patterns is used for both kinds of output syntax,
6496: but the character sequence @samp{%.} is used in each place where Motorola
6497: syntax wants a period. The @code{PRINT_OPERAND} macro for Motorola syntax
6498: defines the sequence to output a period; the macro for MIT syntax defines
6499: it to do nothing.
6500:
6501: @node Output Statement, Constraints, Output Template, Machine Desc
6502: @section C Statements for Generating Assembler Output
6503:
6504: Often a single fixed template string cannot produce correct and efficient
6505: assembler code for all the cases that are recognized by a single
6506: instruction pattern. For example, the opcodes may depend on the kinds of
6507: operands; or some unfortunate combinations of operands may require extra
6508: machine instructions.
6509:
6510: If the output control string starts with a @samp{*}, then it is not an
6511: output template but rather a piece of C program that should compute a
6512: template. It should execute a @code{return} statement to return the
6513: template-string you want. Most such templates use C string literals, which
6514: require doublequote characters to delimit them. To include these
6515: doublequote characters in the string, prefix each one with @samp{\}.
6516:
6517: The operands may be found in the array @code{operands}, whose C data type
6518: is @code{rtx []}.
6519:
6520: It is possible to output an assembler instruction and then go on to output
6521: or compute more of them, using the subroutine @code{output_asm_insn}. This
6522: receives two arguments: a template-string and a vector of operands. The
6523: vector may be @code{operands}, or it may be another array of @code{rtx}
6524: that you declare locally and initialize yourself.
6525:
6526: When an insn pattern has multiple alternatives in its constraints, often
1.1.1.5 root 6527: the appearance of the assembler code is determined mostly by which alternative
1.1 root 6528: was matched. When this is so, the C code can test the variable
6529: @code{which_alternative}, which is the ordinal number of the alternative
6530: that was actually satisfied (0 for the first, 1 for the second alternative,
6531: etc.).
6532:
6533: For example, suppose there are two opcodes for storing zero, @samp{clrreg}
6534: for registers and @samp{clrmem} for memory locations. Here is how
6535: a pattern could use @code{which_alternative} to choose between them:
6536:
6537: @example
6538: (define_insn ""
6539: [(set (match_operand:SI 0 "general_operand" "r,m")
6540: (const_int 0))]
6541: ""
6542: "*
6543: return (which_alternative == 0
6544: ? \"clrreg %0\" : \"clrmem %0\");
6545: ")
6546: @end example
6547:
6548: @node Constraints, Standard Names, Output Statement, Machine Desc
6549: @section Operand Constraints
6550:
1.1.1.8 root 6551: Each @code{match_operand} in an instruction pattern can specify a
1.1 root 6552: constraint for the type of operands allowed. Constraints can say whether
6553: an operand may be in a register, and which kinds of register; whether the
6554: operand can be a memory reference, and which kinds of address; whether the
6555: operand may be an immediate constant, and which possible values it may
6556: have. Constraints can also require two operands to match.
6557:
6558: @menu
6559: * Simple Constraints:: Basic use of constraints.
6560: * Multi-Alternative:: When an insn has two alternative constraint-patterns.
6561: * Class Preferences:: Constraints guide which hard register to put things in.
6562: * Modifiers:: More precise control over effects of constraints.
6563: * No Constraints:: Describing a clean machine without constraints.
6564: @end menu
6565:
6566: @node Simple Constraints, Multi-Alternative, Constraints, Constraints
6567: @subsection Simple Constraints
6568:
6569: The simplest kind of constraint is a string full of letters, each of
6570: which describes one kind of operand that is permitted. Here are
6571: the letters that are allowed:
6572:
6573: @table @asis
6574: @item @samp{m}
6575: A memory operand is allowed, with any kind of address that the machine
6576: supports in general.
6577:
6578: @item @samp{o}
6579: A memory operand is allowed, but only if the address is
1.1.1.8 root 6580: @dfn{offsettable}. This means that adding a small integer (actually,
1.1 root 6581: the width in bytes of the operand, as determined by its machine mode)
6582: may be added to the address and the result is also a valid memory
6583: address.
6584:
1.1.1.8 root 6585: For example, an address which is constant is offsettable; so is an
1.1 root 6586: address that is the sum of a register and a constant (as long as a
6587: slightly larger constant is also within the range of address-offsets
6588: supported by the machine); but an autoincrement or autodecrement
1.1.1.8 root 6589: address is not offsettable. More complicated indirect/indexed
6590: addresses may or may not be offsettable depending on the other
1.1 root 6591: addressing modes that the machine supports.
6592:
6593: Note that in an output operand which can be matched by another
6594: operand, the constraint letter @samp{o} is valid only when accompanied
6595: by both @samp{<} (if the target machine has predecrement addressing)
6596: and @samp{>} (if the target machine has preincrement addressing).
6597:
6598: When the constraint letter @samp{o} is used, the reload pass may
1.1.1.8 root 6599: generate instructions which copy a nonoffsettable address into an index
1.1 root 6600: register. The idea is that the register can be used as a replacement
1.1.1.8 root 6601: offsettable address. But this method requires that there be patterns
1.1 root 6602: to copy any kind of address into a register. Auto-increment
6603: and auto-decrement addresses are an exception; there need not be an
6604: instruction that can copy such an address into a register, because
6605: reload handles these cases specially.
6606:
6607: Most older machine designs have ``load address'' instructions which do
6608: just what is needed here. Some RISC machines do not advertise such
6609: instructions, but the possible addresses on these machines are very
6610: limited, so it is easy to fake them.
6611:
6612: @item @samp{<}
6613: A memory operand with autodecrement addressing (either predecrement or
6614: postdecrement) is allowed.
6615:
6616: @item @samp{>}
6617: A memory operand with autoincrement addressing (either preincrement or
6618: postincrement) is allowed.
6619:
6620: @item @samp{r}
6621: A register operand is allowed provided that it is in a general
6622: register.
6623:
6624: @item @samp{d}, @samp{a}, @samp{f}, @dots{}
6625: Other letters can be defined in machine-dependent fashion to stand for
6626: particular classes of registers. @samp{d}, @samp{a} and @samp{f} are
6627: defined on the 68000/68020 to stand for data, address and floating
6628: point registers.
6629:
6630: @item @samp{i}
6631: An immediate integer operand (one with constant value) is allowed.
6632: This includes symbolic constants whose values will be known only at
6633: assembly time.
6634:
6635: @item @samp{n}
6636: An immediate integer operand with a known numeric value is allowed.
6637: Many systems cannot support assembly-time constants for operands less
6638: than a word wide. Constraints for these operands should use @samp{n}
6639: rather than @samp{i}.
6640:
6641: @item @samp{I}, @samp{J}, @samp{K}, @dots{}
6642: Other letters in the range @samp{I} through @samp{M} may be defined in
6643: a machine-dependent fashion to permit immediate integer operands with
6644: explicit integer values in specified ranges. For example, on the
6645: 68000, @samp{I} is defined to stand for the range of values 1 to 8.
6646: This is the range permitted as a shift count in the shift
6647: instructions.
6648:
6649: @item @samp{F}
1.1.1.8 root 6650: An immediate floating operand (expression code @code{const_double}) is
1.1 root 6651: allowed.
6652:
6653: @item @samp{G}, @samp{H}
6654: @samp{G} and @samp{H} may be defined in a machine-dependent fashion to
6655: permit immediate floating operands in particular ranges of values.
6656:
6657: @item @samp{s}
6658: An immediate integer operand whose value is not an explicit integer is
6659: allowed.
6660:
6661: This might appear strange; if an insn allows a constant operand with a
6662: value not known at compile time, it certainly must allow any known
6663: value. So why use @samp{s} instead of @samp{i}? Sometimes it allows
6664: better code to be generated.
6665:
6666: For example, on the 68000 in a fullword instruction it is possible to
1.1.1.9 root 6667: use an immediate operand; but if the immediate value is between -128
6668: and 127, better code results from loading the value into a register and
1.1 root 6669: using the register. This is because the load into the register can be
6670: done with a @samp{moveq} instruction. We arrange for this to happen
6671: by defining the letter @samp{K} to mean ``any integer outside the
1.1.1.9 root 6672: range -128 to 127'', and then specifying @samp{Ks} in the operand
1.1 root 6673: constraints.
6674:
6675: @item @samp{g}
6676: Any register, memory or immediate integer operand is allowed, except for
6677: registers that are not general registers.
6678:
6679: @item @samp{@var{n}} (a digit)
6680: An operand that matches operand number @var{n} is allowed.
6681: If a digit is used together with letters, the digit should come last.
6682:
6683: This is called a @dfn{matching constraint} and what it really means is
6684: that the assembler has only a single operand that fills two roles
6685: considered separate in the RTL insn. For example, an add insn has two
6686: input operands and one output operand in the RTL, but on most machines
6687: an add instruction really has only two operands, one of them an
6688: input-output operand.
6689:
6690: Matching constraints work only in circumstances like that add insn.
6691: More precisely, the matching constraint must appear in an input-only
6692: operand and the operand that it matches must be an output-only operand
1.1.1.5 root 6693: with a lower number. Thus, operand @var{n} must have @samp{=} in its
6694: constraint.
1.1 root 6695:
6696: For operands to match in a particular case usually means that they
6697: are identical-looking RTL expressions. But in a few special cases
6698: specific kinds of dissimilarity are allowed. For example, @code{*x}
6699: as an input operand will match @code{*x++} as an output operand.
6700: For proper results in such cases, the output template should always
6701: use the output-operand's number when printing the operand.
6702:
6703: @item @samp{p}
6704: An operand that is a valid memory address is allowed. This is
6705: for ``load address'' and ``push address'' instructions.
6706:
1.1.1.8 root 6707: @samp{p} in the constraint must be accompanies by @code{address_operand}
6708: as the predicate in the @code{match_operand}.
1.1 root 6709: @end table
6710:
6711: In order to have valid assembler code, each operand must satisfy
6712: its constraint. But a failure to do so does not prevent the pattern
6713: from applying to an insn. Instead, it directs the compiler to modify
6714: the code so that the constraint will be satisfied. Usually this is
6715: done by copying an operand into a register.
6716:
6717: Contrast, therefore, the two instruction patterns that follow:
6718:
6719: @example
6720: (define_insn ""
6721: [(set (match_operand:SI 0 "general_operand" "r")
6722: (plus:SI (match_dup 0)
6723: (match_operand:SI 1 "general_operand" "r")))]
6724: ""
6725: "@dots{}")
6726: @end example
6727:
6728: @noindent
6729: which has two operands, one of which must appear in two places, and
6730:
6731: @example
6732: (define_insn ""
6733: [(set (match_operand:SI 0 "general_operand" "r")
6734: (plus:SI (match_operand:SI 1 "general_operand" "0")
6735: (match_operand:SI 2 "general_operand" "r")))]
6736: ""
6737: "@dots{}")
6738: @end example
6739:
6740: @noindent
6741: which has three operands, two of which are required by a constraint to be
6742: identical. If we are considering an insn of the form
6743:
6744: @example
6745: (insn @var{n} @var{prev} @var{next}
6746: (set (reg:SI 3)
6747: (plus:SI (reg:SI 6) (reg:SI 109)))
6748: @dots{})
6749: @end example
6750:
6751: @noindent
6752: the first pattern would not apply at all, because this insn does not
6753: contain two identical subexpressions in the right place. The pattern would
6754: say, ``That does not look like an add instruction; try other patterns.''
6755: The second pattern would say, ``Yes, that's an add instruction, but there
6756: is something wrong with it.'' It would direct the reload pass of the
6757: compiler to generate additional insns to make the constraint true. The
6758: results might look like this:
6759:
6760: @example
6761: (insn @var{n2} @var{prev} @var{n}
6762: (set (reg:SI 3) (reg:SI 6))
6763: @dots{})
6764:
6765: (insn @var{n} @var{n2} @var{next}
6766: (set (reg:SI 3)
6767: (plus:SI (reg:SI 3) (reg:SI 109)))
6768: @dots{})
6769: @end example
6770:
6771: It is up to you to make sure that each operand, in each pattern, has
6772: constraints that can handle any RTL expression that could be present for
6773: that operand. (When multiple alternatives are in use, each pattern must,
6774: for each possible combination of operand expressions, have at least one
6775: alternative which can handle that combination of operands.) The
6776: constraints don't need to @emph{allow} any possible operand---when this is
6777: the case, they do not constrain---but they must at least point the way to
6778: reloading any possible operand so that it will fit.
6779:
6780: @itemize @bullet
6781: @item
6782: If the constraint accepts whatever operands the predicate permits,
6783: there is no problem: reloading is never necessary for this operand.
6784:
6785: For example, an operand whose constraints permit everything except
6786: registers is safe provided its predicate rejects registers.
6787:
6788: An operand whose predicate accepts only constant values is safe
6789: provided its constraints include the letter @samp{i}. If any possible
6790: constant value is accepted, then nothing less than @samp{i} will do;
1.1.1.5 root 6791: if the predicate is more selective, then the constraints may also be
1.1 root 6792: more selective.
6793:
6794: @item
6795: Any operand expression can be reloaded by copying it into a register.
6796: So if an operand's constraints allow some kind of register, it is
6797: certain to be safe. It need not permit all classes of registers; the
6798: compiler knows how to copy a register into another register of the
6799: proper class in order to make an instruction valid.
6800:
6801: @item
1.1.1.8 root 6802: A nonoffsettable memory reference can be reloaded by copying the
1.1 root 6803: address into a register. So if the constraint uses the letter
6804: @samp{o}, all memory references are taken care of.
6805:
6806: @item
1.1.1.8 root 6807: A constant operand can be reloaded by allocating space in memory to
6808: hold it as preinitialized data. Then the memory reference can be used
6809: in place of the constant. So if the constraint uses the letters
6810: @samp{o} or @samp{m}, constant operands are not a problem.
1.1 root 6811: @end itemize
6812:
6813: If the operand's predicate can recognize registers, but the constraint does
6814: not permit them, it can make the compiler crash. When this operand happens
6815: to be a register, the reload pass will be stymied, because it does not know
6816: how to copy a register temporarily into memory.
6817:
6818: @node Multi-Alternative, Class Preferences, Simple Constraints, Constraints
6819: @subsection Multiple Alternative Constraints
6820:
6821: Sometimes a single instruction has multiple alternative sets of possible
6822: operands. For example, on the 68000, a logical-or instruction can combine
6823: register or an immediate value into memory, or it can combine any kind of
6824: operand into a register; but it cannot combine one memory location into
6825: another.
6826:
6827: These constraints are represented as multiple alternatives. An alternative
6828: can be described by a series of letters for each operand. The overall
6829: constraint for an operand is made from the letters for this operand
6830: from the first alternative, a comma, the letters for this operand from
6831: the second alternative, a comma, and so on until the last alternative.
6832: Here is how it is done for fullword logical-or on the 68000:
6833:
6834: @example
6835: (define_insn "iorsi3"
1.1.1.9 root 6836: [(set (match_operand:SI 0 "general_operand" "=m,d")
6837: (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
1.1 root 6838: (match_operand:SI 2 "general_operand" "dKs,dmKs")))]
6839: @dots{})
6840: @end example
6841:
6842: The first alternative has @samp{m} (memory) for operand 0, @samp{0} for
1.1.1.9 root 6843: operand 1 (meaning it must match operand 0), and @samp{dKs} for operand
6844: 2. The second alternative has @samp{d} (data register) for operand 0,
6845: @samp{0} for operand 1, and @samp{dmKs} for operand 2. The @samp{=} and
6846: @samp{%} in the constraints apply to all the alternatives; their meaning
1.1 root 6847: is explained in the next section.
6848:
6849: If all the operands fit any one alternative, the instruction is valid.
6850: Otherwise, for each alternative, the compiler counts how many instructions
6851: must be added to copy the operands so that that alternative applies.
6852: The alternative requiring the least copying is chosen. If two alternatives
6853: need the same amount of copying, the one that comes first is chosen.
6854: These choices can be altered with the @samp{?} and @samp{!} characters:
6855:
6856: @table @samp
6857: @item ?
6858: Disparage slightly the alternative that the @samp{?} appears in,
6859: as a choice when no alternative applies exactly. The compiler regards
6860: this alternative as one unit more costly for each @samp{?} that appears
6861: in it.
6862:
6863: @item !
6864: Disparage severely the alternative that the @samp{!} appears in.
6865: When operands must be copied into registers, the compiler will
6866: never choose this alternative as the one to strive for.
6867: @end table
6868:
1.1.1.5 root 6869: When an insn pattern has multiple alternatives in its constraints, often
6870: the appearance of the assembler code is determined mostly by which
1.1 root 6871: alternative was matched. When this is so, the C code for writing the
6872: assembler code can use the variable @code{which_alternative}, which is
1.1.1.5 root 6873: the ordinal number of the alternative that was actually satisfied (0 for
6874: the first, 1 for the second alternative, etc.). For example:
1.1 root 6875:
6876: @example
6877: (define_insn ""
6878: [(set (match_operand:SI 0 "general_operand" "r,m")
6879: (const_int 0))]
6880: ""
6881: "*
6882: return (which_alternative == 0
6883: ? \"clrreg %0\" : \"clrmem %0\");
6884: ")
6885: @end example
6886:
6887: @node Class Preferences, Modifiers, Multi-Alternative, Constraints
6888: @subsection Register Class Preferences
6889:
6890: The operand constraints have another function: they enable the compiler
6891: to decide which kind of hardware register a pseudo register is best
6892: allocated to. The compiler examines the constraints that apply to the
6893: insns that use the pseudo register, looking for the machine-dependent
6894: letters such as @samp{d} and @samp{a} that specify classes of registers.
6895: The pseudo register is put in whichever class gets the most ``votes''.
6896: The constraint letters @samp{g} and @samp{r} also vote: they vote in
6897: favor of a general register. The machine description says which registers
6898: are considered general.
6899:
6900: Of course, on some machines all registers are equivalent, and no register
6901: classes are defined. Then none of this complexity is relevant.
6902:
6903: @node Modifiers, No Constraints, Class Preferences, Constraints
6904: @subsection Constraint Modifier Characters
6905:
6906: @table @samp
6907: @item =
6908: Means that this operand is write-only for this instruction: the previous
6909: value is discarded and replaced by output data.
6910:
6911: @item +
6912: Means that this operand is both read and written by the instruction.
6913:
6914: When the compiler fixes up the operands to satisfy the constraints,
6915: it needs to know which operands are inputs to the instruction and
6916: which are outputs from it. @samp{=} identifies an output; @samp{+}
6917: identifies an operand that is both input and output; all other operands
6918: are assumed to be input only.
6919:
6920: @item &
6921: Means (in a particular alternative) that this operand is written
6922: before the instruction is finished using the input operands.
6923: Therefore, this operand may not lie in a register that is used as an
6924: input operand or as part of any memory address.
6925:
6926: @samp{&} applies only to the alternative in which it is written. In
6927: constraints with multiple alternatives, sometimes one alternative
6928: requires @samp{&} while others do not. See, for example, the
6929: @samp{movdf} insn of the 68000.
6930:
6931: @samp{&} does not obviate the need to write @samp{=}.
6932:
6933: @item %
6934: Declares the instruction to be commutative for this operand and the
6935: following operand. This means that the compiler may interchange the
6936: two operands if that is the cheapest way to make all operands fit the
6937: constraints. This is often used in patterns for addition instructions
6938: that really have only two operands: the result must go in one of the
6939: arguments. Here for example, is how the 68000 halfword-add
6940: instruction is defined:
6941:
6942: @example
6943: (define_insn "addhi3"
6944: [(set (match_operand:HI 0 "general_operand" "=m,r")
6945: (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
6946: (match_operand:HI 2 "general_operand" "di,g")))]
6947: @dots{})
6948: @end example
6949:
6950: Note that in previous versions of GNU CC the @samp{%} constraint
6951: modifier always applied to operands 1 and 2 regardless of which
6952: operand it was written in. The usual custom was to write it in
6953: operand 0. Now it must be in operand 1 if the operands to be
6954: exchanged are 1 and 2.
6955:
6956: @item #
6957: Says that all following characters, up to the next comma, are to be
6958: ignored as a constraint. They are significant only for choosing
6959: register preferences.
6960:
6961: @item *
6962: Says that the following character should be ignored when choosing
6963: register preferences. @samp{*} has no effect on the meaning of the
6964: constraint as a constraint.
6965:
6966: Here is an example: the 68000 has an instruction to sign-extend a
6967: halfword in a data register, and can also sign-extend a value by
6968: copying it into an address register. While either kind of register is
6969: acceptable, the constraints on an address-register destination are
6970: less strict, so it is best if register allocation makes an address
6971: register its goal. Therefore, @samp{*} is used so that the @samp{d}
6972: constraint letter (for data register) is ignored when computing
6973: register preferences.
6974:
6975: @example
6976: (define_insn "extendhisi2"
6977: [(set (match_operand:SI 0 "general_operand" "=*d,a")
6978: (sign_extend:SI
6979: (match_operand:HI 1 "general_operand" "0,g")))]
6980: @dots{})
6981: @end example
6982: @end table
6983:
6984: @node No Constraints,, Modifiers, Constraints
6985: @subsection Not Using Constraints
6986:
6987: Some machines are so clean that operand constraints are not required. For
6988: example, on the Vax, an operand valid in one context is valid in any other
6989: context. On such a machine, every operand constraint would be @samp{g},
6990: excepting only operands of ``load address'' instructions which are
6991: written as if they referred to a memory location's contents but actual
6992: refer to its address. They would have constraint @samp{p}.
6993:
6994: For such machines, instead of writing @samp{g} and @samp{p} for all
6995: the constraints, you can choose to write a description with empty constraints.
1.1.1.8 root 6996: Then you write @samp{""} for the constraint in every @code{match_operand}.
6997: Address operands are identified by writing an @code{address} expression
6998: around the @code{match_operand}, not by their constraints.
1.1 root 6999:
7000: When the machine description has just empty constraints, certain parts
1.1.1.6 root 7001: of compilation are skipped, making the compiler faster. However,
7002: few machines actually do not need constraints; all machine descriptions
7003: now in existence use constraints.
1.1 root 7004:
7005: @node Standard Names, Pattern Ordering, Constraints, Machine Desc
7006: @section Standard Names for Patterns Used in Generation
7007:
7008: Here is a table of the instruction names that are meaningful in the RTL
7009: generation pass of the compiler. Giving one of these names to an
7010: instruction pattern tells the RTL generation pass that it can use the
7011: pattern in to accomplish a certain task.
7012:
7013: @table @asis
7014: @item @samp{mov@var{m}}
1.1.1.8 root 7015: Here @var{m} stands for a two-letter machine mode name, in lower case.
7016: This instruction pattern moves data with that machine mode from operand
7017: 1 to operand 0. For example, @samp{movsi} moves full-word data.
1.1 root 7018:
1.1.1.8 root 7019: If operand 0 is a @code{subreg} with mode @var{m} of a register whose
7020: own mode is wider than @var{m}, the effect of this instruction is
1.1 root 7021: to store the specified value in the part of the register that corresponds
7022: to mode @var{m}. The effect on the rest of the register is undefined.
7023:
7024: This class of patterns is special in several ways. First of all, each
7025: of these names @emph{must} be defined, because there is no other way
7026: to copy a datum from one place to another.
7027:
7028: Second, these patterns are not used solely in the RTL generation pass.
7029: Even the reload pass can generate move insns to copy values from stack
1.1.1.8 root 7030: slots into temporary registers. When it does so, one of the operands is
7031: a hard register and the other is an operand that can need to be reloaded
7032: into a register.
7033:
7034: Therefore, when given such a pair of operands, the pattern must generate
7035: RTL which needs no reloading and needs no temporary registers---no
7036: registers other than the operands. For example, if you support the
7037: pattern with a @code{define_expand}, then in such a case the
7038: @code{define_expand} mustn't call @code{force_reg} or any other such
7039: function which might generate new pseudo registers.
1.1 root 7040:
7041: This requirement exists even for subword modes on a RISC machine where
7042: fetching those modes from memory normally requires several insns and
7043: some temporary registers. Look in @file{spur.md} to see how the
1.1.1.8 root 7044: requirement can be satisfied.
1.1 root 7045:
7046: The variety of operands that have reloads depends on the rest of the
7047: machine description, but typically on a RISC machine these can only be
7048: pseudo registers that did not get hard registers, while on other
7049: machines explicit memory references will get optional reloads.
7050:
1.1.1.9 root 7051: The constraints on a @samp{move@var{m}} must allow any hard register to
7052: be moved to any other hard register (provided that
7053: @code{HARD_REGNO_MODE_OK} permits mode @var{m} in both registers).
7054:
7055: It is obligatory to support floating point @samp{move@var{m}}
7056: instructions into and out of any registers that can hold fixed point
7057: values, because unions and structures (which have modes @code{SImode} or
7058: @code{DImode}) can be in those registers and they may have floating
7059: point members.
7060:
7061: There may also be a need to support fixed point @samp{move@var{m}}
7062: instructions in and out of floating point registers. Unfortunately, I
7063: have forgotten why this was so, and I don't know whether it is still
7064: true. If @code{HARD_REGNO_MODE_OK} rejects fixed point values in
7065: floating point registers, then the constraints of the fixed point
7066: @samp{move@var{m}} instructions must be designed to avoid ever trying to
7067: reload into a floating point register.
1.1 root 7068:
7069: @item @samp{movstrict@var{m}}
1.1.1.8 root 7070: Like @samp{mov@var{m}} except that if operand 0 is a @code{subreg}
1.1 root 7071: with mode @var{m} of a register whose natural mode is wider,
7072: the @samp{movstrict@var{m}} instruction is guaranteed not to alter
7073: any of the register except the part which belongs to mode @var{m}.
7074:
7075: @item @samp{add@var{m}3}
7076: Add operand 2 and operand 1, storing the result in operand 0. All operands
7077: must have mode @var{m}. This can be used even on two-address machines, by
7078: means of constraints requiring operands 1 and 0 to be the same location.
7079:
7080: @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}
7081: Similar, for other arithmetic operations.
7082:
7083: There are special considerations for register classes for logical-and
7084: instructions, affecting also the macro @code{PREFERRED_RELOAD_CLASS}.
7085: They apply not only to the patterns with these standard names, but to
7086: any patterns that will match such an instruction. @xref{Register
7087: Classes}.
7088:
7089: @item @samp{mulhisi3}
7090: Multiply operands 1 and 2, which have mode @code{HImode}, and store
7091: a @code{SImode} product in operand 0.
7092:
7093: @item @samp{mulqihi3}, @samp{mulsidi3}
7094: Similar widening-multiplication instructions of other widths.
7095:
7096: @item @samp{umulqihi3}, @samp{umulhisi3}, @samp{umulsidi3}
7097: Similar widening-multiplication instructions that do unsigned
7098: multiplication.
7099:
7100: @item @samp{divmod@var{m}4}
7101: Signed division that produces both a quotient and a remainder.
7102: Operand 1 is divided by operand 2 to produce a quotient stored
7103: in operand 0 and a remainder stored in operand 3.
7104:
7105: @item @samp{udivmod@var{m}4}
7106: Similar, but does unsigned division.
7107:
7108: @item @samp{ashl@var{m}3}
7109: Arithmetic-shift operand 1 left by a number of bits specified by
7110: operand 2, and store the result in operand 0. Operand 2 has
7111: mode @code{SImode}, not mode @var{m}.
7112:
7113: @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}
7114: Other shift and rotate instructions.
7115:
7116: Logical and arithmetic left shift are the same. Machines that do not
7117: allow negative shift counts often have only one instruction for
7118: shifting left. On such machines, you should define a pattern named
7119: @samp{ashl@var{m}3} and leave @samp{lshl@var{m}3} undefined.
7120:
7121: There are special considerations for register classes for shift
7122: instructions, affecting also the macro @code{PREFERRED_RELOAD_CLASS}.
7123: They apply not only to the patterns with these standard names, but to
7124: any patterns that will match such an instruction. @xref{Register
7125: Classes}.
7126:
7127: @item @samp{neg@var{m}2}
7128: Negate operand 1 and store the result in operand 0.
7129:
7130: @item @samp{abs@var{m}2}
7131: Store the absolute value of operand 1 into operand 0.
7132:
7133: @item @samp{sqrt@var{m}2}
7134: Store the square root of operand 1 into operand 0.
7135:
7136: @item @samp{ffs@var{m}2}
7137: Store into operand 0 one plus the index of the least significant 1-bit
7138: of operand 1. If operand 1 is zero, store zero. @var{m} is the mode
7139: of operand 0; operand 1's mode is specified by the instruction
7140: pattern, and the compiler will convert the operand to that mode before
7141: generating the instruction.
7142:
7143: @item @samp{one_cmpl@var{m}2}
7144: Store the bitwise-complement of operand 1 into operand 0.
7145:
7146: @item @samp{cmp@var{m}}
7147: Compare operand 0 and operand 1, and set the condition codes.
7148: The RTL pattern should look like this:
7149:
7150: @example
1.1.1.6 root 7151: (set (cc0) (compare (match_operand:@var{m} 0 @dots{})
7152: (match_operand:@var{m} 1 @dots{})))
1.1 root 7153: @end example
7154:
7155: Each such definition in the machine description, for integer mode
7156: @var{m}, must have a corresponding @samp{tst@var{m}} pattern, because
7157: optimization can simplify the compare into a test when operand 1 is
7158: zero.
7159:
7160: @item @samp{tst@var{m}}
7161: Compare operand 0 against zero, and set the condition codes.
7162: The RTL pattern should look like this:
7163:
7164: @example
7165: (set (cc0) (match_operand:@var{m} 0 @dots{}))
7166: @end example
7167:
7168: @item @samp{movstr@var{m}}
7169: Block move instruction. The addresses of the destination and source
7170: strings are the first two operands, and both are in mode @code{Pmode}.
7171: The number of bytes to move is the third operand, in mode @var{m}.
1.1.1.5 root 7172: The fourth operand is the known shared alignment of the source and
7173: destination, in the form of a @code{const_int} rtx.
1.1 root 7174:
7175: @item @samp{cmpstr@var{m}}
7176: Block compare instruction, with operands like @samp{movstr@var{m}}
7177: except that the two memory blocks are compared byte by byte
7178: in lexicographic order. The effect of the instruction is to set
7179: the condition codes.
7180:
7181: @item @samp{float@var{m}@var{n}2}
1.1.1.9 root 7182: Convert signed integer operand 1 (valid for fixed point mode @var{m}) to
7183: floating point mode @var{n} and store in operand 0 (which has mode
7184: @var{n}).
7185:
7186: @item @samp{floatuns@var{m}@var{n}2}
7187: Convert unsigned integer operand 1 (valid for fixed point mode @var{m})
7188: to floating point mode @var{n} and store in operand 0 (which has mode
7189: @var{n}).
1.1 root 7190:
7191: @item @samp{fix@var{m}@var{n}2}
7192: Convert operand 1 (valid for floating point mode @var{m}) to fixed
7193: point mode @var{n} as a signed number and store in operand 0 (which
7194: has mode @var{n}). This instruction's result is defined only when
7195: the value of operand 1 is an integer.
7196:
7197: @item @samp{fixuns@var{m}@var{n}2}
7198: Convert operand 1 (valid for floating point mode @var{m}) to fixed
7199: point mode @var{n} as an unsigned number and store in operand 0 (which
7200: has mode @var{n}). This instruction's result is defined only when the
7201: value of operand 1 is an integer.
7202:
7203: @item @samp{ftrunc@var{m}2}
7204: Convert operand 1 (valid for floating point mode @var{m}) to an
7205: integer value, still represented in floating point mode @var{m}, and
7206: store it in operand 0 (valid for floating point mode @var{m}).
7207:
7208: @item @samp{fix_trunc@var{m}@var{n}2}
7209: Like @samp{fix@var{m}@var{n}2} but works for any floating point value
7210: of mode @var{m} by converting the value to an integer.
7211:
7212: @item @samp{fixuns_trunc@var{m}@var{n}2}
7213: Like @samp{fixuns@var{m}@var{n}2} but works for any floating point
7214: value of mode @var{m} by converting the value to an integer.
7215:
7216: @item @samp{trunc@var{m}@var{n}}
7217: Truncate operand 1 (valid for mode @var{m}) to mode @var{n} and
7218: store in operand 0 (which has mode @var{n}). Both modes must be fixed
7219: point or both floating point.
7220:
7221: @item @samp{extend@var{m}@var{n}}
7222: Sign-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
7223: store in operand 0 (which has mode @var{n}). Both modes must be fixed
7224: point or both floating point.
7225:
7226: @item @samp{zero_extend@var{m}@var{n}}
7227: Zero-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
7228: store in operand 0 (which has mode @var{n}). Both modes must be fixed
7229: point.
7230:
7231: @item @samp{extv}
7232: Extract a bit-field from operand 1 (a register or memory operand),
7233: where operand 2 specifies the width in bits and operand 3 the starting
1.1.1.10 root 7234: bit, and store it in operand 0. Operand 0 must have @code{SImode}.
1.1 root 7235: Operand 1 may have mode @code{QImode} or @code{SImode}; often
7236: @code{SImode} is allowed only for registers. Operands 2 and 3 must be
7237: valid for @code{SImode}.
7238:
7239: The RTL generation pass generates this instruction only with constants
7240: for operands 2 and 3.
7241:
7242: The bit-field value is sign-extended to a full word integer
7243: before it is stored in operand 0.
7244:
7245: @item @samp{extzv}
7246: Like @samp{extv} except that the bit-field value is zero-extended.
7247:
7248: @item @samp{insv}
7249: Store operand 3 (which must be valid for @code{SImode}) into a
7250: bit-field in operand 0, where operand 1 specifies the width in bits
7251: and operand 2 the starting bit. Operand 0 may have mode @code{QImode}
7252: or @code{SImode}; often @code{SImode} is allowed only for registers.
7253: Operands 1 and 2 must be valid for @code{SImode}.
7254:
7255: The RTL generation pass generates this instruction only with constants
7256: for operands 1 and 2.
7257:
7258: @item @samp{s@var{cond}}
7259: Store zero or nonzero in the operand according to the condition codes.
7260: Value stored is nonzero iff the condition @var{cond} is true.
7261: @var{cond} is the name of a comparison operation expression code, such
1.1.1.8 root 7262: as @code{eq}, @code{lt} or @code{leu}.
1.1 root 7263:
7264: You specify the mode that the operand must have when you write the
7265: @code{match_operand} expression. The compiler automatically sees
7266: which mode you have used and supplies an operand of that mode.
7267:
1.1.1.8 root 7268: The value stored for a true condition must have 1 as its low bit, or
7269: else must be negative. Otherwise the instruction is not suitable and
7270: must be omitted from the machine description. You must tell the
7271: compiler exactly which value is stored by defining the macro
7272: @code{STORE_FLAG_VALUE}.
1.1 root 7273:
7274: @item @samp{b@var{cond}}
1.1.1.8 root 7275: Conditional branch instruction. Operand 0 is a @code{label_ref}
1.1 root 7276: that refers to the label to jump to. Jump if the condition codes
7277: meet condition @var{cond}.
7278:
7279: @item @samp{call}
7280: Subroutine call instruction returning no value. Operand 0 is the
7281: function to call; operand 1 is the number of bytes of arguments pushed
1.1.1.8 root 7282: (in mode @code{SImode}, except it is normally a @code{const_int});
1.1 root 7283: operand 2 is the number of registers used as operands.
7284:
7285: On most machines, operand 2 is not actually stored into the RTL
7286: pattern. It is supplied for the sake of some RISC machines which need
7287: to put this information into the assembler code; they can put it in
7288: the RTL instead of operand 1.
7289:
1.1.1.8 root 7290: Operand 0 should be a @code{mem} RTX whose address is the address of
1.1 root 7291: the function.
7292:
7293: @item @samp{call_value}
7294: Subroutine call instruction returning a value. Operand 0 is the hard
7295: register in which the value is returned. There are three more
7296: operands, the same as the three operands of the @samp{call}
7297: instruction (but with numbers increased by one).
7298:
7299: Subroutines that return @code{BLKmode} objects use the @samp{call}
7300: insn.
7301:
7302: @item @samp{return}
7303: Subroutine return instruction. This instruction pattern name should be
7304: defined only if a single instruction can do all the work of returning
7305: from a function.
7306:
1.1.1.8 root 7307: @item @samp{nop}
7308: No-op instruction. This instruction pattern name should always be defined
7309: to output a no-op in assembler code. @code{(const_int 0)} will do as an
7310: RTL pattern.
7311:
1.1 root 7312: @item @samp{casesi}
7313: Instruction to jump through a dispatch table, including bounds checking.
7314: This instruction takes five operands:
7315:
7316: @enumerate
7317: @item
7318: The index to dispatch on, which has mode @code{SImode}.
7319:
7320: @item
7321: The lower bound for indices in the table, an integer constant.
7322:
7323: @item
1.1.1.6 root 7324: The total range of indices in the table---the largest index
7325: minus the smallest one (both inclusive).
1.1 root 7326:
7327: @item
7328: A label to jump to if the index has a value outside the bounds.
7329: (If the machine-description macro @code{CASE_DROPS_THROUGH} is defined,
7330: then an out-of-bounds index drops through to the code following
7331: the jump table instead of jumping to this label. In that case,
7332: this label is not actually used by the @samp{casesi} instruction,
7333: but it is always provided as an operand.)
7334:
7335: @item
7336: A label that precedes the table itself.
7337: @end enumerate
7338:
1.1.1.8 root 7339: The table is a @code{addr_vec} or @code{addr_diff_vec} inside of a
7340: @code{jump_insn}. The number of elements in the table is one plus the
1.1 root 7341: difference between the upper bound and the lower bound.
7342:
7343: @item @samp{tablejump}
7344: Instruction to jump to a variable address. This is a low-level
7345: capability which can be used to implement a dispatch table when there
7346: is no @samp{casesi} pattern.
7347:
7348: This pattern requires two operands: the address or offset, and a label
7349: which should immediately precede the jump table. If the macro
7350: @code{CASE_VECTOR_PC_RELATIVE} is defined then the first operand is an
1.1.1.10 root 7351: offset that counts from the address of the table; otherwise, it is an
7352: absolute address to jump to.
1.1 root 7353:
7354: The @samp{tablejump} insn is always the last insn before the jump
7355: table it uses. Its assembler code normally has no need to use the
7356: second operand, but you should incorporate it in the RTL pattern so
7357: that the jump optimizer will not delete the table as unreachable code.
7358: @end table
7359:
7360: @node Pattern Ordering, Dependent Patterns, Standard Names, Machine Desc
7361: @section When the Order of Patterns Matters
7362:
7363: Sometimes an insn can match more than one instruction pattern. Then the
7364: pattern that appears first in the machine description is the one used.
7365: Therefore, more specific patterns (patterns that will match fewer things)
7366: and faster instructions (those that will produce better code when they
7367: do match) should usually go first in the description.
7368:
7369: In some cases the effect of ordering the patterns can be used to hide
7370: a pattern when it is not valid. For example, the 68000 has an
7371: instruction for converting a fullword to floating point and another
7372: for converting a byte to floating point. An instruction converting
7373: an integer to floating point could match either one. We put the
7374: pattern to convert the fullword first to make sure that one will
7375: be used rather than the other. (Otherwise a large integer might
7376: be generated as a single-byte immediate quantity, which would not work.)
7377: Instead of using this pattern ordering it would be possible to make the
7378: pattern for convert-a-byte smart enough to deal properly with any
7379: constant value.
7380:
7381: @node Dependent Patterns, Jump Patterns, Pattern Ordering, Machine Desc
7382: @section Interdependence of Patterns
7383:
7384: Every machine description must have a named pattern for each of the
7385: conditional branch names @samp{b@var{cond}}. The recognition template
7386: must always have the form
7387:
7388: @example
7389: (set (pc)
7390: (if_then_else (@var{cond} (cc0) (const_int 0))
7391: (label_ref (match_operand 0 "" ""))
7392: (pc)))
7393: @end example
7394:
7395: @noindent
7396: In addition, every machine description must have an anonymous pattern
7397: for each of the possible reverse-conditional branches. These patterns
7398: look like
7399:
7400: @example
7401: (set (pc)
7402: (if_then_else (@var{cond} (cc0) (const_int 0))
7403: (pc)
7404: (label_ref (match_operand 0 "" ""))))
7405: @end example
7406:
7407: @noindent
7408: They are necessary because jump optimization can turn direct-conditional
7409: branches into reverse-conditional branches.
7410:
7411: The compiler does more with RTL than just create it from patterns
7412: and recognize the patterns: it can perform arithmetic expression codes
7413: when constant values for their operands can be determined. As a result,
7414: sometimes having one pattern can require other patterns. For example, the
7415: Vax has no `and' instruction, but it has `and not' instructions. Here
7416: is the definition of one of them:
7417:
7418: @example
7419: (define_insn "andcbsi2"
7420: [(set (match_operand:SI 0 "general_operand" "")
7421: (and:SI (match_dup 0)
7422: (not:SI (match_operand:SI
7423: 1 "general_operand" ""))))]
7424: ""
7425: "bicl2 %1,%0")
7426: @end example
7427:
7428: @noindent
7429: If operand 1 is an explicit integer constant, an instruction constructed
7430: using that pattern can be simplified into an `and' like this:
7431:
7432: @example
7433: (set (reg:SI 41)
7434: (and:SI (reg:SI 41)
7435: (const_int 0xffff7fff)))
7436: @end example
7437:
7438: @noindent
7439: (where the integer constant is the one's complement of what
7440: appeared in the original instruction).
7441:
7442: To avoid a fatal error, the compiler must have a pattern that recognizes
7443: such an instruction. Here is what is used:
7444:
7445: @example
7446: (define_insn ""
7447: [(set (match_operand:SI 0 "general_operand" "")
7448: (and:SI (match_dup 0)
7449: (match_operand:SI 1 "general_operand" "")))]
7450: "GET_CODE (operands[1]) == CONST_INT"
7451: "*
7452: @{ operands[1]
7453: = gen_rtx (CONST_INT, VOIDmode, ~INTVAL (operands[1]));
7454: return \"bicl2 %1,%0\";
7455: @}")
7456: @end example
7457:
7458: @noindent
7459: Whereas a pattern to match a general `and' instruction is impossible to
7460: support on the Vax, this pattern is possible because it matches only a
7461: constant second argument: a special case that can be output as an `and not'
7462: instruction.
7463:
7464: A ``compare'' instruction whose RTL looks like this:
7465:
7466: @example
1.1.1.6 root 7467: (set (cc0) (compare @var{operand} (const_int 0)))
1.1 root 7468: @end example
7469:
7470: @noindent
7471: may be simplified by optimization into a ``test'' like this:
7472:
7473: @example
7474: (set (cc0) @var{operand})
7475: @end example
7476:
7477: @noindent
7478: So in the machine description, each ``compare'' pattern for an integer
7479: mode must have a corresponding ``test'' pattern that will match the
7480: result of such simplification.
7481:
7482: In some cases machines support instructions identical except for the
7483: machine mode of one or more operands. For example, there may be
7484: ``sign-extend halfword'' and ``sign-extend byte'' instructions whose
7485: patterns are
7486:
7487: @example
7488: (set (match_operand:SI 0 @dots{})
7489: (extend:SI (match_operand:HI 1 @dots{})))
7490:
7491: (set (match_operand:SI 0 @dots{})
7492: (extend:SI (match_operand:QI 1 @dots{})))
7493: @end example
7494:
7495: @noindent
7496: Constant integers do not specify a machine mode, so an instruction to
7497: extend a constant value could match either pattern. The pattern it
7498: actually will match is the one that appears first in the file. For correct
7499: results, this must be the one for the widest possible mode (@code{HImode},
7500: here). If the pattern matches the @code{QImode} instruction, the results
7501: will be incorrect if the constant value does not actually fit that mode.
7502:
7503: Such instructions to extend constants are rarely generated because they are
7504: optimized away, but they do occasionally happen in nonoptimized
7505: compilations.
7506:
7507: When an instruction has the constraint letter @samp{o}, the reload
1.1.1.8 root 7508: pass may generate instructions which copy a nonoffsettable address into
1.1 root 7509: an index register. The idea is that the register can be used as a
1.1.1.8 root 7510: replacement offsettable address. In order for these generated
1.1 root 7511: instructions to work, there must be patterns to copy any kind of valid
7512: address into a register.
7513:
7514: Most older machine designs have ``load address'' instructions which do
7515: just what is needed here. Some RISC machines do not advertise such
7516: instructions, but the possible addresses on these machines are very
7517: limited, so it is easy to fake them.
7518:
7519: Auto-increment and auto-decrement addresses are an exception; there
7520: need not be an instruction that can copy such an address into a
7521: register, because reload handles these cases in a different manner.
7522:
7523: @node Jump Patterns, Peephole Definitions, Dependent Patterns, Machine Desc
7524: @section Defining Jump Instruction Patterns
7525:
7526: GNU CC assumes that the machine has a condition code. A comparison insn
7527: sets the condition code, recording the results of both signed and unsigned
7528: comparison of the given operands. A separate branch insn tests the
7529: condition code and branches or not according its value. The branch insns
7530: come in distinct signed and unsigned flavors. Many common machines, such
7531: as the Vax, the 68000 and the 32000, work this way.
7532:
7533: Some machines have distinct signed and unsigned compare instructions, and
7534: only one set of conditional branch instructions. The easiest way to handle
7535: these machines is to treat them just like the others until the final stage
7536: where assembly code is written. At this time, when outputting code for the
7537: compare instruction, peek ahead at the following branch using
7538: @code{NEXT_INSN (insn)}. (The variable @code{insn} refers to the insn
7539: being output, in the output-writing code in an instruction pattern.) If
7540: the RTL says that is an unsigned branch, output an unsigned compare;
7541: otherwise output a signed compare. When the branch itself is output, you
7542: can treat signed and unsigned branches identically.
7543:
7544: The reason you can do this is that GNU CC always generates a pair of
7545: consecutive RTL insns, one to set the condition code and one to test it,
7546: and keeps the pair inviolate until the end.
7547:
7548: To go with this technique, you must define the machine-description macro
7549: @code{NOTICE_UPDATE_CC} to do @code{CC_STATUS_INIT}; in other words, no
7550: compare instruction is superfluous.
7551:
7552: Some machines have compare-and-branch instructions and no condition code.
7553: A similar technique works for them. When it is time to ``output'' a
7554: compare instruction, record its operands in two static variables. When
7555: outputting the branch-on-condition-code instruction that follows, actually
7556: output a compare-and-branch instruction that uses the remembered operands.
7557:
7558: It also works to define patterns for compare-and-branch instructions.
7559: In optimizing compilation, the pair of compare and branch instructions
1.1.1.5 root 7560: will be combined according to these patterns. But this does not happen
1.1 root 7561: if optimization is not requested. So you must use one of the solutions
7562: above in addition to any special patterns you define.
7563:
7564: @node Peephole Definitions, Expander Definitions, Jump Patterns, Machine Desc
7565: @section Defining Machine-Specific Peephole Optimizers
7566:
7567: In addition to instruction patterns the @file{md} file may contain
7568: definitions of machine-specific peephole optimizations.
7569:
7570: The combiner does not notice certain peephole optimizations when the data
7571: flow in the program does not suggest that it should try them. For example,
7572: sometimes two consecutive insns related in purpose can be combined even
7573: though the second one does not appear to use a register computed in the
7574: first one. A machine-specific peephole optimizer can detect such
7575: opportunities.
7576:
7577: A definition looks like this:
7578:
7579: @example
7580: (define_peephole
7581: [@var{insn-pattern-1}
7582: @var{insn-pattern-2}
7583: @dots{}]
7584: "@var{condition}"
7585: "@var{template}"
7586: "@var{machine-specific info}")
7587: @end example
7588:
7589: @noindent
7590: The last string operand may be omitted if you are not using any
7591: machine-specific information in this machine description. If present,
1.1.1.8 root 7592: it must obey the same rules as in a @code{define_insn}.
1.1 root 7593:
7594: In this skeleton, @var{insn-pattern-1} and so on are patterns to match
1.1.1.5 root 7595: consecutive insns. The optimization applies to a sequence of insns when
7596: @var{insn-pattern-1} matches the first one, @var{insn-pattern-2} matches
7597: the next, and so on.@refill
1.1 root 7598:
1.1.1.8 root 7599: Each of the insns matched by a peephole must also match a
7600: @code{define_insn}. Peepholes are checked only at the last stage just
7601: before code generation, and only optionally. Therefore, any insn which
7602: would match a peephole but no @code{define_insn} will cause a crash in code
7603: generation in an unoptimized compilation, or at various optimization
7604: stages.
1.1 root 7605:
1.1.1.5 root 7606: The operands of the insns are matched with @code{match_operands} and
7607: @code{match_dup}, as usual. What is not usual is that the operand numbers
7608: apply to all the insn patterns in the definition. So, you can check for
7609: identical operands in two insns by using @code{match_operand} in one insn
7610: and @code{match_dup} in the other.
1.1 root 7611:
7612: The operand constraints used in @code{match_operand} patterns do not have
1.1.1.8 root 7613: any direct effect on the applicability of the peephole, but they will
7614: be validated afterward, so make sure your constraints are general enough
7615: to apply whenever the peephole matches. If the peephole matches
7616: but the constraints are not satisfied, the compiler will crash.
7617:
7618: It is safe to omit constraints in all the operands of the peephole; or
7619: you can write constraints which serve as a double-check on the criteria
7620: previously tested.
1.1 root 7621:
1.1.1.5 root 7622: Once a sequence of insns matches the patterns, the @var{condition} is
7623: checked. This is a C expression which makes the final decision whether to
7624: perform the optimization (we do so if the expression is nonzero). If
1.1 root 7625: @var{condition} is omitted (in other words, the string is empty) then the
1.1.1.5 root 7626: optimization is applied to every sequence of insns that matches the
1.1 root 7627: patterns.
7628:
1.1.1.5 root 7629: The defined peephole optimizations are applied after register allocation
7630: is complete. Therefore, the peephole definition can check which
7631: operands have ended up in which kinds of registers, just by looking at
7632: the operands.
1.1 root 7633:
7634: The way to refer to the operands in @var{condition} is to write
7635: @code{operands[@var{i}]} for operand number @var{i} (as matched by
7636: @code{(match_operand @var{i} @dots{})}). Use the variable @code{insn} to
7637: refer to the last of the insns being matched; use @code{PREV_INSN} to find
1.1.1.8 root 7638: the preceding insns (but be careful to skip over any @code{note} insns that
1.1 root 7639: intervene).@refill
7640:
7641: When optimizing computations with intermediate results, you can use
7642: @var{condition} to match only when the intermediate results are not used
7643: elsewhere. Use the C expression @code{dead_or_set_p (@var{insn},
7644: @var{op})}, where @var{insn} is the insn in which you expect the value to
7645: be used for the last time (from the value of @code{insn}, together with use
7646: of @code{PREV_INSN}), and @var{op} is the intermediate value (from
7647: @code{operands[@var{i}]}).@refill
7648:
1.1.1.5 root 7649: Applying the optimization means replacing the sequence of insns with one
7650: new insn. The @var{template} controls ultimate output of assembler code
7651: for this combined insn. It works exactly like the template of a
7652: @code{define_insn}. Operand numbers in this template are the same ones
7653: used in matching the original sequence of insns.
1.1 root 7654:
7655: The result of a defined peephole optimizer does not need to match any of
1.1.1.5 root 7656: the insn patterns in the machine description; it does not even have an
7657: opportunity to match them. The peephole optimizer definition itself serves
7658: as the insn pattern to control how the insn is output.
7659:
7660: Defined peephole optimizers are run as assembler code is being output,
7661: so the insns they produce are never combined or rearranged in any way.
1.1 root 7662:
7663: Here is an example, taken from the 68000 machine description:
7664:
7665: @example
7666: (define_peephole
7667: [(set (reg:SI 15) (plus:SI (reg:SI 15) (const_int 4)))
7668: (set (match_operand:DF 0 "register_operand" "f")
7669: (match_operand:DF 1 "register_operand" "ad"))]
7670: "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
7671: "*
7672: @{
7673: rtx xoperands[2];
7674: xoperands[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
7675: #ifdef MOTOROLA
7676: output_asm_insn (\"move.l %1,(sp)\", xoperands);
7677: output_asm_insn (\"move.l %1,-(sp)\", operands);
7678: return \"fmove.d (sp)+,%0\";
7679: #else
7680: output_asm_insn (\"movel %1,sp@@\", xoperands);
7681: output_asm_insn (\"movel %1,sp@@-\", operands);
7682: return \"fmoved sp@@+,%0\";
7683: #endif
7684: @}
7685: ")
7686: @end example
7687:
7688: The effect of this optimization is to change
7689:
7690: @example
7691: jbsr _foobar
7692: addql #4,sp
7693: movel d1,sp@@-
7694: movel d0,sp@@-
7695: fmoved sp@@+,fp0
7696: @end example
7697:
7698: @noindent
7699: into
7700:
7701: @example
7702: jbsr _foobar
7703: movel d1,sp@@
7704: movel d0,sp@@-
7705: fmoved sp@@+,fp0
7706: @end example
7707:
1.1.1.5 root 7708: @ignore
7709: If a peephole matches a sequence including one or more jump insns, you must
7710: take account of the flags such as @code{CC_REVERSED} which specify that the
7711: condition codes are represented in an unusual manner. The compiler
7712: automatically alters any ordinary conditional jumps which occur in such
7713: situations, but the compiler cannot alter jumps which have been replaced by
7714: peephole optimizations. So it is up to you to alter the assembler code
7715: that the peephole produces. Supply C code to write the assembler output,
7716: and in this C code check the condition code status flags and change the
7717: assembler code as appropriate.
7718: @end ignore
7719:
1.1.1.8 root 7720: @var{insn-pattern-1} and so on look @emph{almost} like the second
7721: operand of @code{define_insn}. There is one important difference: the
7722: second operand of @code{define_insn} consists of one or more RTX's
7723: enclosed in square brackets. Usually, there is only one: then the same
7724: action can be written as an element of a @code{define_peephole}. But
7725: when there are multiple actions in a @code{define_insn}, they are
7726: implicitly enclosed in a @code{parallel}. Then you must explicitly
7727: write the @code{parallel}, and the square brackets within it, in the
7728: @code{define_peephole}. Thus, if an insn pattern looks like this,
7729:
7730: @example
7731: (define_insn "divmodsi4"
7732: [(set (match_operand:SI 0 "general_operand" "=d")
7733: (div:SI (match_operand:SI 1 "general_operand" "0")
7734: (match_operand:SI 2 "general_operand" "dmsK")))
7735: (set (match_operand:SI 3 "general_operand" "=d")
7736: (mod:SI (match_dup 1) (match_dup 2)))]
7737: "TARGET_68020"
7738: "divsl%.l %2,%3:%0")
7739: @end example
7740:
7741: @noindent
7742: then the way to mention this insn in a peephole is as follows:
7743:
7744: @example
7745: (define_peephole
7746: [@dots{}
7747: (parallel
7748: [(set (match_operand:SI 0 "general_operand" "=d")
7749: (div:SI (match_operand:SI 1 "general_operand" "0")
7750: (match_operand:SI 2 "general_operand" "dmsK")))
7751: (set (match_operand:SI 3 "general_operand" "=d")
7752: (mod:SI (match_dup 1) (match_dup 2)))])
7753: @dots{}]
7754: @dots{})
7755: @end example
7756:
1.1 root 7757: @node Expander Definitions,, Peephole Definitions, Machine Desc
7758: @section Defining RTL Sequences for Code Generation
7759:
7760: On some target machines, some standard pattern names for RTL generation
7761: cannot be handled with single insn, but a sequence of RTL insns can
7762: represent them. For these target machines, you can write a
1.1.1.8 root 7763: @code{define_expand} to specify how to generate the sequence of RTL.
1.1 root 7764:
1.1.1.8 root 7765: A @code{define_expand} is an RTL expression that looks almost like a
7766: @code{define_insn}; but, unlike the latter, a @code{define_expand} is used
1.1 root 7767: only for RTL generation and it can produce more than one RTL insn.
7768:
1.1.1.8 root 7769: A @code{define_expand} RTX has four operands:
1.1 root 7770:
7771: @itemize @bullet
7772: @item
1.1.1.8 root 7773: The name. Each @code{define_expand} must have a name, since the only
1.1 root 7774: use for it is to refer to it by name.
7775:
7776: @item
7777: The RTL template. This is just like the RTL template for a
1.1.1.8 root 7778: @code{define_peephole} in that it is a vector of RTL expressions
1.1 root 7779: each being one insn.
7780:
7781: @item
7782: The condition, a string containing a C expression. This expression is
7783: used to express how the availability of this pattern depends on
7784: subclasses of target machine, selected by command-line options when
7785: GNU CC is run. This is just like the condition of a
1.1.1.8 root 7786: @code{define_insn} that has a standard name.
1.1 root 7787:
7788: @item
7789: The preparation statements, a string containing zero or more C
7790: statements which are to be executed before RTL code is generated from
7791: the RTL template.
7792:
7793: Usually these statements prepare temporary registers for use as
7794: internal operands in the RTL template, but they can also generate RTL
1.1.1.8 root 7795: insns directly by calling routines such as @code{emit_insn}, etc.
1.1 root 7796: Any such insns precede the ones that come from the RTL template.
7797: @end itemize
7798:
1.1.1.8 root 7799: Every RTL insn emitted by a @code{define_expand} must match some
7800: @code{define_insn} in the machine description. Otherwise, the compiler
7801: will crash when trying to generate code for the insn or trying to optimize
7802: it.
7803:
1.1 root 7804: The RTL template, in addition to controlling generation of RTL insns,
7805: also describes the operands that need to be specified when this pattern
7806: is used. In particular, it gives a predicate for each operand.
7807:
7808: A true operand, which need to be specified in order to generate RTL from
1.1.1.8 root 7809: the pattern, should be described with a @code{match_operand} in its first
1.1 root 7810: occurrence in the RTL template. This enters information on the operand's
7811: predicate into the tables that record such things. GNU CC uses the
7812: information to preload the operand into a register if that is required for
7813: valid RTL code. If the operand is referred to more than once, subsequent
1.1.1.8 root 7814: references should use @code{match_dup}.
1.1 root 7815:
7816: The RTL template may also refer to internal ``operands'' which are
7817: temporary registers or labels used only within the sequence made by the
1.1.1.8 root 7818: @code{define_expand}. Internal operands are substituted into the RTL
7819: template with @code{match_dup}, never with @code{match_operand}. The
1.1 root 7820: values of the internal operands are not passed in as arguments by the
7821: compiler when it requests use of this pattern. Instead, they are computed
7822: within the pattern, in the preparation statements. These statements
7823: compute the values and store them into the appropriate elements of
1.1.1.8 root 7824: @code{operands} so that @code{match_dup} can find them.
1.1 root 7825:
7826: There are two special macros defined for use in the preparation statements:
7827: @code{DONE} and @code{FAIL}. Use them with a following semicolon,
7828: as a statement.
7829:
7830: @table @code
7831: @item DONE
7832: Use the @code{DONE} macro to end RTL generation for the pattern. The
7833: only RTL insns resulting from the pattern on this occasion will be
7834: those already emitted by explicit calls to @code{emit_insn} within the
7835: preparation statements; the RTL template will not be generated.
7836:
7837: @item FAIL
7838: Make the pattern fail on this occasion. When a pattern fails, it means
7839: that the pattern was not truly available. The calling routines in the
7840: compiler will try other strategies for code generation using other patterns.
7841:
7842: Failure is currently supported only for binary operations (addition,
7843: multiplication, shifting, etc.).
7844:
7845: Do not emit any insns explicitly with @code{emit_insn} before failing.
7846: @end table
7847:
7848: Here is an example, the definition of left-shift for the SPUR chip:
7849:
7850: @example
7851: (define_expand "ashlsi3"
7852: [(set (match_operand:SI 0 "register_operand" "")
7853: (ashift:SI
7854: (match_operand:SI 1 "register_operand" "")
7855: (match_operand:SI 2 "nonmemory_operand" "")))]
7856: ""
7857: "
7858: @{
7859: if (GET_CODE (operands[2]) != CONST_INT
7860: || (unsigned) INTVAL (operands[2]) > 3)
7861: FAIL;
7862: @}")
7863: @end example
7864:
7865: @noindent
1.1.1.8 root 7866: This example uses @code{define_expand} so that it can generate an RTL insn
1.1 root 7867: for shifting when the shift-count is in the supported range of 0 to 3 but
7868: fail in other cases where machine insns aren't available. When it fails,
7869: the compiler tries another strategy using different patterns (such as, a
7870: library call).
7871:
7872: If the compiler were able to handle nontrivial condition-strings in
1.1.1.8 root 7873: patterns with names, then it would be possible to use a
7874: @code{define_insn} in that case. Here is another case (zero-extension
7875: on the 68000) which makes more use of the power of @code{define_expand}:
1.1 root 7876:
7877: @example
7878: (define_expand "zero_extendhisi2"
7879: [(set (match_operand:SI 0 "general_operand" "")
7880: (const_int 0))
7881: (set (strict_low_part
7882: (subreg:HI
1.1.1.8 root 7883: (match_dup 0)
1.1 root 7884: 0))
7885: (match_operand:HI 1 "general_operand" ""))]
7886: ""
7887: "operands[1] = make_safe_from (operands[1], operands[0]);")
7888: @end example
7889:
7890: @noindent
7891: Here two RTL insns are generated, one to clear the entire output operand
7892: and the other to copy the input operand into its low half. This sequence
7893: is incorrect if the input operand refers to [the old value of] the output
7894: operand, so the preparation statement makes sure this isn't so. The
7895: function @code{make_safe_from} copies the @code{operands[1]} into a
7896: temporary register if it refers to @code{operands[0]}. It does this
7897: by emitting another RTL insn.
7898:
7899: Finally, a third example shows the use of an internal operand.
1.1.1.8 root 7900: Zero-extension on the SPUR chip is done by @code{and}-ing the result
1.1 root 7901: against a halfword mask. But this mask cannot be represented by a
1.1.1.8 root 7902: @code{const_int} because the constant value is too large to be legitimate
1.1 root 7903: on this machine. So it must be copied into a register with
1.1.1.8 root 7904: @code{force_reg} and then the register used in the @code{and}.
1.1 root 7905:
7906: @example
7907: (define_expand "zero_extendhisi2"
7908: [(set (match_operand:SI 0 "register_operand" "")
7909: (and:SI (subreg:SI
7910: (match_operand:HI 1 "register_operand" "")
7911: 0)
7912: (match_dup 2)))]
7913: ""
7914: "operands[2]
7915: = force_reg (SImode, gen_rtx (CONST_INT,
7916: VOIDmode, 65535)); ")
7917: @end example
7918:
1.1.1.8 root 7919: @strong{Note:} If the @code{define_expand} is used to serve a standard
7920: binary or unary arithmetic operation, then the last insn it generates
7921: must not be a @code{code_label}, @code{barrier} or @code{note}. It must
7922: be an @code{insn}, @code{jump_insn} or @code{call_insn}.
7923:
1.1 root 7924: @node Machine Macros, Config, Machine Desc, Top
7925: @chapter Machine Description Macros
7926:
7927: The other half of the machine description is a C header file conventionally
7928: given the name @file{tm-@var{machine}.h}. The file @file{tm.h} should be a
7929: link to it. The header file @file{config.h} includes @file{tm.h} and most
7930: compiler source files include @file{config.h}.
7931:
7932: @menu
1.1.1.9 root 7933: * Run-time Target:: Defining @samp{-m} options like @samp{-m68000} and @samp{-m68020}.
1.1 root 7934: * Storage Layout:: Defining sizes and alignments of data types.
7935: * Registers:: Naming and describing the hardware registers.
7936: * Register Classes:: Defining the classes of hardware registers.
7937: * Stack Layout:: Defining which way the stack grows and by how much.
1.1.1.12! root 7938: * Library Calls:: Specifying how to call certain library routines.
1.1 root 7939: * Addressing Modes:: Defining addressing modes valid for memory operands.
1.1.1.8 root 7940: * Delayed Branch:: Do branches execute the following instruction?
1.1 root 7941: * Condition Code:: Defining how insns update the condition code.
1.1.1.5 root 7942: * Cross-compilation:: Handling floating point for cross-compilers.
1.1 root 7943: * Misc:: Everything else.
1.1.1.11 root 7944: * Assembler Format:: Defining how to write insns and pseudo-ops to output.
1.1 root 7945: @end menu
7946:
7947: @node Run-time Target, Storage Layout, Machine Macros, Machine Macros
7948: @section Run-time Target Specification
7949:
7950: @table @code
7951: @item CPP_PREDEFINES
7952: Define this to be a string constant containing @samp{-D} options to
7953: define the predefined macros that identify this machine and system.
7954: These macros will be predefined unless the @samp{-ansi} option is
7955: specified.
7956:
1.1.1.4 root 7957: In addition, a parallel set of macros are predefined, whose names are
7958: made by appending @samp{__} at the beginning and at the end. These
7959: @samp{__} macros are permitted by the ANSI standard, so they are
7960: predefined regardless of whether @samp{-ansi} is specified.
7961:
7962: For example, on the Sun, one can use the following value:
1.1 root 7963:
7964: @example
7965: "-Dmc68000 -Dsun -Dunix"
7966: @end example
7967:
1.1.1.8 root 7968: The result is to define the macros @code{__mc68000__}, @code{__sun__}
7969: and @code{__unix__} unconditionally, and the macros @code{mc68000},
7970: @code{sun} and @code{unix} provided @samp{-ansi} is not specified.
1.1.1.4 root 7971:
1.1 root 7972: @item CPP_SPEC
7973: A C string constant that tells the GNU CC driver program options to
7974: pass to CPP. It can also specify how to translate options you
7975: give to GNU CC into options for GNU CC to pass to the CPP.
7976:
7977: Do not define this macro if it does not need to do anything.
7978:
7979: @item CC1_SPEC
7980: A C string constant that tells the GNU CC driver program options to
7981: pass to CC1. It can also specify how to translate options you
7982: give to GNU CC into options for GNU CC to pass to the CC1.
7983:
7984: Do not define this macro if it does not need to do anything.
7985:
7986: @item extern int target_flags;
7987: This declaration should be present.
7988:
7989: @item TARGET_@dots{}
7990: This series of macros is to allow compiler command arguments to
7991: enable or disable the use of optional features of the target machine.
7992: For example, one machine description serves both the 68000 and
7993: the 68020; a command argument tells the compiler whether it should
7994: use 68020-only instructions or not. This command argument works
7995: by means of a macro @code{TARGET_68020} that tests a bit in
7996: @code{target_flags}.
7997:
7998: Define a macro @code{TARGET_@var{featurename}} for each such option.
7999: Its definition should test a bit in @code{target_flags}; for example:
8000:
8001: @example
8002: #define TARGET_68020 (target_flags & 1)
8003: @end example
8004:
8005: One place where these macros are used is in the condition-expressions
8006: of instruction patterns. Note how @code{TARGET_68020} appears
8007: frequently in the 68000 machine description file, @file{m68k.md}.
8008: Another place they are used is in the definitions of the other
8009: macros in the @file{tm-@var{machine}.h} file.
8010:
8011: @item TARGET_SWITCHES
8012: This macro defines names of command options to set and clear
8013: bits in @code{target_flags}. Its definition is an initializer
8014: with a subgrouping for each command option.
8015:
8016: Each subgrouping contains a string constant, that defines the option
8017: name, and a number, which contains the bits to set in
8018: @code{target_flags}. A negative number says to clear bits instead;
8019: the negative of the number is which bits to clear. The actual option
8020: name is made by appending @samp{-m} to the specified name.
8021:
8022: One of the subgroupings should have a null string. The number in
8023: this grouping is the default value for @code{target_flags}. Any
8024: target options act starting with that value.
8025:
8026: Here is an example which defines @samp{-m68000} and @samp{-m68020}
8027: with opposite meanings, and picks the latter as the default:
8028:
8029: @example
8030: #define TARGET_SWITCHES \
8031: @{ @{ "68020", 1@}, \
8032: @{ "68000", -1@}, \
8033: @{ "", 1@}@}
8034: @end example
8035:
8036: @item OVERRIDE_OPTIONS
8037: Sometimes certain combinations of command options do not make sense on
8038: a particular target machine. You can define a macro
8039: @code{OVERRIDE_OPTIONS} to take account of this. This macro, if
8040: defined, is executed once just after all the command options have been
8041: parsed.
8042: @end table
8043:
8044: @node Storage Layout, Registers, Run-time Target, Machine Macros
8045: @section Storage Layout
8046:
8047: Note that the definitions of the macros in this table which are sizes or
8048: alignments measured in bits do not need to be constant. They can be C
8049: expressions that refer to static variables, such as the @code{target_flags}.
8050: @xref{Run-time Target}.
8051:
8052: @table @code
8053: @item BITS_BIG_ENDIAN
8054: Define this macro if the most significant bit in a byte has the lowest
8055: number. This means that bit-field instructions count from the most
8056: significant bit. If the machine has no bit-field instructions, this
8057: macro is irrelevant.
8058:
1.1.1.8 root 8059: This macro does not affect the way structure fields are packed into
8060: bytes or words; that is controlled by @code{BYTES_BIG_ENDIAN}.
8061:
1.1 root 8062: @item BYTES_BIG_ENDIAN
8063: Define this macro if the most significant byte in a word has the
8064: lowest number.
8065:
8066: @item WORDS_BIG_ENDIAN
8067: Define this macro if, in a multiword object, the most significant
8068: word has the lowest number.
8069:
8070: @item BITS_PER_UNIT
8071: Number of bits in an addressable storage unit (byte); normally 8.
8072:
8073: @item BITS_PER_WORD
8074: Number of bits in a word; normally 32.
8075:
8076: @item UNITS_PER_WORD
8077: Number of storage units in a word; normally 4.
8078:
8079: @item POINTER_SIZE
8080: Width of a pointer, in bits.
8081:
8082: @item POINTER_BOUNDARY
8083: Alignment required for pointers stored in memory, in bits.
8084:
8085: @item PARM_BOUNDARY
1.1.1.7 root 8086: Normal alignment required for function parameters on the stack, in
8087: bits. All stack parameters receive least this much alignment
8088: regardless of data type. On most machines, this is the same as the
8089: size of an integer.
8090:
8091: @item MAX_PARM_BOUNDARY
8092: Largest alignment required for any stack parameters, in bits. If the
8093: data type of the parameter calls for more alignment than
8094: @code{PARM_BOUNDARY}, then it is given extra padding up to this limit.
8095:
8096: Don't define this macro if it would be equal to @code{PARM_BOUNDARY};
8097: in other words, if the alignment of a stack parameter should not
8098: depend on its data type (as is the case on most machines).
1.1 root 8099:
8100: @item STACK_BOUNDARY
8101: Define this macro if you wish to preserve a certain alignment for
8102: the stack pointer at all times. The definition is a C expression
8103: for the desired alignment (measured in bits).
8104:
8105: @item FUNCTION_BOUNDARY
8106: Alignment required for a function entry point, in bits.
8107:
8108: @item BIGGEST_ALIGNMENT
8109: Biggest alignment that any data type can require on this machine, in bits.
8110:
1.1.1.8 root 8111: @item CONSTANT_ALIGNMENT (@var{code}, @var{typealign})
8112: A C expression to compute the alignment for a constant. The argument
8113: @var{typealign} is the alignment required for the constant's data type.
8114: @var{code} is the tree code of the constant itself.
8115:
8116: If this macro is not defined, the default is to use @var{typealign}. If
8117: you do define this macro, the value must be a multiple of
8118: @var{typealign}.
8119:
8120: The purpose of defining this macro is usually to cause string constants
8121: to be word aligned so that @file{dhrystone} can be made to run faster.
8122:
1.1 root 8123: @item EMPTY_FIELD_BOUNDARY
8124: Alignment in bits to be given to a structure bit field that follows an
8125: empty field such as @code{int : 0;}.
8126:
8127: @item STRUCTURE_SIZE_BOUNDARY
8128: Number of bits which any structure or union's size must be a multiple of.
8129: Each structure or union's size is rounded up to a multiple of this.
8130:
8131: If you do not define this macro, the default is the same as
8132: @code{BITS_PER_UNIT}.
8133:
8134: @item STRICT_ALIGNMENT
8135: Define this if instructions will fail to work if given data not
8136: on the nominal alignment. If instructions will merely go slower
8137: in that case, do not define this macro.
8138:
8139: @item PCC_BITFIELD_TYPE_MATTERS
8140: Define this if you wish to imitate a certain bizarre behavior pattern
8141: of some instances of PCC: a bit field whose declared type is
8142: @code{int} has the same effect on the size and alignment of a
8143: structure as an actual @code{int} would have.
8144:
1.1.1.10 root 8145: If the macro is defined, then its definition should be a C expression;
8146: a nonzero value for the expression enables PCC-compatible behavior.
8147:
1.1 root 8148: Just what effect that is in GNU CC depends on other parameters, but on
8149: most machines it would force the structure's alignment and size to a
8150: multiple of 32 or @code{BIGGEST_ALIGNMENT} bits.
8151:
1.1.1.7 root 8152: @item MAX_FIXED_MODE_SIZE
8153: An integer expression for the largest integer machine mode that should
8154: actually be used. All integer machine modes of this size or smaller
8155: can be used for structures and unions with the appropriate sizes.
8156:
1.1 root 8157: @item CHECK_FLOAT_VALUE (@var{mode}, @var{value})
8158: A C statement to validate the value @var{value} (or type
8159: @code{double}) for mode @var{mode}. This means that you check whether
8160: @var{value} fits within the possible range of values for mode
8161: @var{mode} on this target machine. The mode @var{mode} is always
8162: @code{SFmode} or @code{DFmode}.
8163:
8164: If @var{value} is not valid, you should call @code{error} to print an
8165: error message and then assign some valid value to @var{value}.
8166: Allowing an invalid value to go through the compiler can produce
8167: incorrect assembler code which may even cause Unix assemblers to
8168: crash.
8169:
8170: This macro need not be defined if there is no work for it to do.
8171: @end table
8172:
8173: @node Registers, Register Classes, Storage Layout, Machine Macros
8174: @section Register Usage
8175:
8176: @table @code
8177: @item FIRST_PSEUDO_REGISTER
8178: Number of hardware registers known to the compiler. They receive
8179: numbers 0 through @code{FIRST_PSEUDO_REGISTER-1}; thus, the first
8180: pseudo register's number really is assigned the number
8181: @code{FIRST_PSEUDO_REGISTER}.
8182:
8183: @item FIXED_REGISTERS
8184: An initializer that says which registers are used for fixed purposes
8185: all throughout the compiled code and are therefore not available for
8186: general allocation. These would include the stack pointer, the frame
8187: pointer (except on machines where that can be used as a general
8188: register when no frame pointer is needed), the program counter on
8189: machines where that is considered one of the addressable registers,
8190: and any other numbered register with a standard use.
8191:
8192: This information is expressed as a sequence of numbers, separated by
8193: commas and surrounded by braces. The @var{n}th number is 1 if
8194: register @var{n} is fixed, 0 otherwise.
8195:
8196: The table initialized from this macro, and the table initialized by
8197: the following one, may be overridden at run time either automatically,
8198: by the actions of the macro @code{CONDITIONAL_REGISTER_USAGE}, or by
8199: the user with the command options @samp{-ffixed-@var{reg}},
8200: @samp{-fcall-used-@var{reg}} and @samp{-fcall-saved-@var{reg}}.
8201:
8202: @item CALL_USED_REGISTERS
8203: Like @code{FIXED_REGISTERS} but has 1 for each register that is
8204: clobbered (in general) by function calls as well as for fixed
8205: registers. This macro therefore identifies the registers that are not
8206: available for general allocation of values that must live across
8207: function calls.
8208:
8209: If a register has 0 in @code{CALL_USED_REGISTERS}, the compiler
8210: automatically saves it on function entry and restores it on function
8211: exit, if the register is used within the function.
8212:
1.1.1.6 root 8213: @item DEFAULT_CALLER_SAVES
1.1.1.8 root 8214: Define this macro if function calls on the target machine do not preserve
1.1.1.6 root 8215: any registers; in other words, if @code{CALL_USED_REGISTERS} has 1
8216: for all registers. This macro enables @samp{-fcaller-saves} by default.
8217: Eventually that option will be enabled by default on all machines and both
8218: the option and this macro will be eliminated.
8219:
1.1 root 8220: @item CONDITIONAL_REGISTER_USAGE
8221: Zero or more C statements that may conditionally modify two variables
8222: @code{fixed_regs} and @code{call_used_regs} (both of type @code{char
8223: []}) after they have been initialized from the two preceding macros.
8224:
8225: This is necessary in case the fixed or call-clobbered registers depend
8226: on target flags.
8227:
8228: You need not define this macro if it has no work to do.
8229:
8230: If the usage of an entire class of registers depends on the target
1.1.1.5 root 8231: flags, you may indicate this to GCC by using this macro to modify
1.1 root 8232: @code{fixed_regs} and @code{call_used_regs} to 1 for each of the
1.1.1.5 root 8233: registers in the classes which should not be used by GCC. Also define
1.1 root 8234: the macro @code{REG_CLASS_FROM_LETTER} to return @code{NO_REGS} if it
8235: is called with a letter for a class that shouldn't be used.
8236:
8237: (However, if this class is not included in @code{GENERAL_REGS} and all
8238: of the insn patterns whose constraints permit this class are
8239: controlled by target switches, then GCC will automatically avoid using
8240: these registers when the target switches are opposed to them.)
8241:
8242: @item OVERLAPPING_REGNO_P (@var{regno})
1.1.1.5 root 8243: If defined, this is a C expression whose value is nonzero if hard
8244: register number @var{regno} is an overlapping register. This means a
8245: hard register which overlaps a hard register with a different number.
8246: (Such overlap is undesirable, but occasionally it allows a machine to
8247: be supported which otherwise could not be.) This macro must return
8248: nonzero for @emph{all} the registers which overlap each other. GNU CC
8249: can use an overlapping register only in certain limited ways. It can
8250: be used for allocation within a basic block, and may be spilled for
8251: reloading; that is all.
1.1 root 8252:
8253: If this macro is not defined, it means that none of the hard registers
8254: overlap each other. This is the usual situation.
8255:
8256: @item INSN_CLOBBERS_REGNO_P (@var{insn}, @var{regno})
8257: If defined, this is a C expression whose value should be nonzero if
8258: the insn @var{insn} has the effect of mysteriously clobbering the
8259: contents of hard register number @var{regno}. By ``mysterious'' we
8260: mean that the insn's RTL expression doesn't describe such an effect.
8261:
8262: If this macro is not defined, it means that no insn clobbers registers
8263: mysteriously. This is the usual situation; all else being equal,
8264: it is best for the RTL expression to show all the activity.
8265:
8266: @item PRESERVE_DEATH_INFO_REGNO_P (@var{regno})
8267: If defined, this is a C expression whose value is nonzero if accurate
8268: @code{REG_DEAD} notes are needed for hard register number @var{regno}
8269: at the time of outputting the assembler code. When this is so, a few
8270: optimizations that take place after register allocation and could
8271: invalidate the death notes are not done when this register is
8272: involved.
8273:
1.1.1.8 root 8274: You would arrange to preserve death info for a register when some of the
8275: code in the machine description which is executed to write the assembler
8276: code looks at the death notes. This is necessary only when the actual
8277: hardware feature which GNU CC thinks of as a register is not actually a
8278: register of the usual sort. (It might, for example, be a hardware
8279: stack.)
1.1 root 8280:
8281: If this macro is not defined, it means that no death notes need to be
8282: preserved. This is the usual situation.
8283:
1.1.1.10 root 8284: @item HARD_REGNO_NREGS (@var{regno}, @var{mode})
1.1 root 8285: A C expression for the number of consecutive hard registers, starting
8286: at register number @var{regno}, required to hold a value of mode
8287: @var{mode}.
8288:
8289: On a machine where all registers are exactly one word, a suitable
8290: definition of this macro is
8291:
8292: @example
8293: #define HARD_REGNO_NREGS(REGNO, MODE) \
8294: ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
8295: / UNITS_PER_WORD))
8296: @end example
8297:
8298: @item HARD_REGNO_MODE_OK (@var{regno}, @var{mode})
8299: A C expression that is nonzero if it is permissible to store a value
8300: of mode @var{mode} in hard register number @var{regno} (or in several
8301: registers starting with that one). For a machine where all registers
8302: are equivalent, a suitable definition is
8303:
8304: @example
8305: #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
8306: @end example
8307:
1.1.1.8 root 8308: It is not necessary for this macro to check for the numbers of fixed
8309: registers, because the allocation mechanism considers them to be always
8310: occupied.
8311:
8312: On some machines, double-precision values must be kept in even/odd
8313: register pairs. The way to implement that is to define this macro
8314: to reject odd register numbers for such modes.
8315:
8316: GNU CC assumes that it can always move values between registers and
8317: (suitably addressed) memory locations. If it is impossible to move a
8318: value of a certain mode between memory and certain registers, then
8319: @code{HARD_REGNO_MODE_OK} must not allow this mode in those registers.
1.1 root 8320:
8321: Many machines have special registers for floating point arithmetic.
8322: Often people assume that floating point machine modes are allowed only
8323: in floating point registers. This is not true. Any registers that
8324: can hold integers can safely @emph{hold} a floating point machine
8325: mode, whether or not floating arithmetic can be done on it in those
8326: registers.
8327:
1.1.1.9 root 8328: On some machines, though, the converse is true: fixed-point machine
8329: modes may not go in floating registers. This is true if the floating
8330: registers normalize any value stored in them, because storing a
8331: non-floating value there would garble it. In this case,
8332: @code{HARD_REGNO_MODE_OK} should reject fixed-point machine modes in
8333: floating registers. But if the floating registers do not automatically
8334: normalize, if you can store any bit pattern in one and retrieve it
8335: unchanged without a trap, then any machine mode may go in a floating
8336: register and this macro should say so.
8337:
8338: The primary significance of special floating registers is rather that
8339: they are the registers acceptable in floating point arithmetic
8340: instructions. However, this is of no concern to
8341: @code{HARD_REGNO_MODE_OK}. You handle it by writing the proper
8342: constraints for those instructions.
8343:
8344: On some machines, the floating registers are especially slow to access,
8345: so that it is better to store a value in a stack frame than in such a
8346: register if floating point arithmetic is not being done. As long as the
8347: floating registers are not in class @code{GENERAL_REGS}, they will not
8348: be used unless some insn's constraint asks for one.
1.1 root 8349:
8350: @item MODES_TIEABLE_P (@var{mode1}, @var{mode2})
8351: A C expression that is nonzero if it is desirable to choose register
8352: allocation so as to avoid move instructions between a value of mode
8353: @var{mode1} and a value of mode @var{mode2}.
8354:
8355: If @code{HARD_REGNO_MODE_OK (@var{r}, @var{mode1})} and
8356: @code{HARD_REGNO_MODE_OK (@var{r}, @var{mode2})} are ever different
8357: for any @var{r}, then @code{MODES_TIEABLE_P (@var{mode1},
8358: @var{mode2})} must be zero.
8359:
8360: @item PC_REGNUM
8361: If the program counter has a register number, define this as that
8362: register number. Otherwise, do not define it.
8363:
8364: @item STACK_POINTER_REGNUM
8365: The register number of the stack pointer register, which must also be
8366: a fixed register according to @code{FIXED_REGISTERS}. On many
8367: machines, the hardware determines which register this is.
8368:
8369: @item FRAME_POINTER_REGNUM
8370: The register number of the frame pointer register, which is used to
8371: access automatic variables in the stack frame. On some machines, the
8372: hardware determines which register this is. On other machines, you
8373: can choose any register you wish for this purpose.
8374:
8375: @item FRAME_POINTER_REQUIRED
1.1.1.9 root 8376: A C expression which is nonzero if a function must have and use a frame
8377: pointer. This expression is evaluated twice: at the beginning of
8378: generating RTL, and in the reload pass. If its value is nonzero at
8379: either time, then the function will have a frame pointer.
8380:
8381: The expression can in principle examine the current function and decide
8382: according to the facts, but on most machines the constant 0 or the
8383: constant 1 suffices. Use 0 when the machine allows code to be generated
8384: with no frame pointer, and doing so saves some time or space. Use 1
8385: when there is no possible advantage to avoiding a frame pointer.
1.1 root 8386:
1.1.1.5 root 8387: In certain cases, the compiler does not know how to produce valid code
8388: without a frame pointer. The compiler recognizes those cases and
8389: automatically gives the function a frame pointer regardless of what
1.1 root 8390: @code{FRAME_POINTER_REQUIRED} says. You don't need to worry about
8391: them.@refill
8392:
8393: In a function that does not require a frame pointer, the frame pointer
8394: register can be allocated for ordinary usage, unless you mark it as a
8395: fixed register. See @code{FIXED_REGISTERS} for more information.
8396:
8397: @item ARG_POINTER_REGNUM
8398: The register number of the arg pointer register, which is used to
8399: access the function's argument list. On some machines, this is the
8400: same as the frame pointer register. On some machines, the hardware
8401: determines which register this is. On other machines, you can choose
8402: any register you wish for this purpose. If this is not the same
8403: register as the frame pointer register, then you must mark it as a
8404: fixed register according to @code{FIXED_REGISTERS}.
8405:
8406: @item STATIC_CHAIN_REGNUM
8407: The register number used for passing a function's static chain
8408: pointer. This is needed for languages such as Pascal and Algol where
8409: functions defined within other functions can access the local
8410: variables of the outer functions; it is not currently used because C
8411: does not provide this feature, but you must define the macro.
8412:
8413: The static chain register need not be a fixed register.
8414:
8415: @item STRUCT_VALUE_REGNUM
8416: When a function's value's mode is @code{BLKmode}, the value is not
8417: returned according to @code{FUNCTION_VALUE}. Instead, the caller
8418: passes the address of a block of memory in which the value should be
8419: stored.
8420:
8421: If this value is passed in a register, then @code{STRUCT_VALUE_REGNUM}
8422: should be the number of that register.
8423:
8424: @item STRUCT_VALUE
8425: If the structure value address is not passed in a register, define
8426: @code{STRUCT_VALUE} as an expression returning an RTX for the place
1.1.1.8 root 8427: where the address is passed. If it returns a @code{mem} RTX, the
1.1 root 8428: address is passed as an ``invisible'' first argument.
8429:
8430: @item STRUCT_VALUE_INCOMING_REGNUM
8431: On some architectures the place where the structure value address
8432: is found by the called function is not the same place that the
8433: caller put it. This can be due to register windows, or it could
8434: be because the function prologue moves it to a different place.
8435:
8436: If the incoming location of the structure value address is in a
8437: register, define this macro as the register number.
8438:
8439: @item STRUCT_VALUE_INCOMING
8440: If the incoming location is not a register, define
8441: @code{STRUCT_VALUE_INCOMING} as an expression for an RTX for where the
8442: called function should find the value. If it should find the value on
1.1.1.8 root 8443: the stack, define this to create a @code{mem} which refers to the
8444: frame pointer. If the value is a @code{mem}, the compiler assumes it
1.1 root 8445: is for an invisible first argument, and leaves space for it when
8446: finding the first real argument.
8447:
8448: @item REG_ALLOC_ORDER
8449: If defined, an initializer for a vector of integers, containing the
8450: numbers of hard registers in the order in which the GNU CC should
8451: prefer to use them (from most preferred to least).
8452:
8453: If this macro is not defined, registers are used lowest numbered first
8454: (all else being equal).
8455:
8456: One use of this macro is on the 360, where the highest numbered
8457: registers must always be saved and the save-multiple-registers
8458: instruction supports only sequences of consecutive registers. This
8459: macro is defined to cause the highest numbered allocatable registers
8460: to be used first.
8461: @end table
8462:
8463: @node Register Classes, Stack Layout, Registers, Machine Macros
8464: @section Register Classes
8465:
8466: On many machines, the numbered registers are not all equivalent.
8467: For example, certain registers may not be allowed for indexed addressing;
8468: certain registers may not be allowed in some instructions. These machine
8469: restrictions are described to the compiler using @dfn{register classes}.
8470:
8471: You define a number of register classes, giving each one a name and saying
8472: which of the registers belong to it. Then you can specify register classes
8473: that are allowed as operands to particular instruction patterns.
8474:
8475: In general, each register will belong to several classes. In fact, one
8476: class must be named @code{ALL_REGS} and contain all the registers. Another
8477: class must be named @code{NO_REGS} and contain no registers. Often the
8478: union of two classes will be another class; however, this is not required.
8479:
8480: One of the classes must be named @code{GENERAL_REGS}. There is nothing
8481: terribly special about the name, but the operand constraint letters
8482: @samp{r} and @samp{g} specify this class. If @code{GENERAL_REGS} is
8483: the same as @code{ALL_REGS}, just define it as a macro which expands
8484: to @code{ALL_REGS}.
8485:
8486: The way classes other than @code{GENERAL_REGS} are specified in operand
8487: constraints is through machine-dependent operand constraint letters.
8488: You can define such letters to correspond to various classes, then use
8489: them in operand constraints.
8490:
8491: You should define a class for the union of two classes whenever some
8492: instruction allows both classes. For example, if an instruction allows
8493: either a floating-point (coprocessor) register or a general register for a
8494: certain operand, you should define a class @code{FLOAT_OR_GENERAL_REGS}
8495: which includes both of them. Otherwise you will get suboptimal code.
8496:
8497: You must also specify certain redundant information about the register
8498: classes: for each class, which classes contain it and which ones are
8499: contained in it; for each pair of classes, the largest class contained
8500: in their union.
8501:
1.1.1.8 root 8502: When a value occupying several consecutive registers is expected in a
8503: certain class, all the registers used must belong to that class.
8504: Therefore, register classes cannot be used to enforce a requirement for
8505: a register pair to start with an even-numbered register. The way to
8506: specify this requirement is with @code{HARD_REGNO_MODE_OK}.
8507:
1.1 root 8508: Register classes used for input-operands of bitwise-and or shift
8509: instructions have a special requirement: each such class must have, for
8510: each fixed-point machine mode, a subclass whose registers can transfer that
8511: mode to or from memory. For example, on some machines, the operations for
8512: single-byte values (@code{QImode}) are limited to certain registers. When
8513: this is so, each register class that is used in a bitwise-and or shift
8514: instruction must have a subclass consisting of registers from which
8515: single-byte values can be loaded or stored. This is so that
8516: @code{PREFERRED_RELOAD_CLASS} can always have a possible value to return.
8517:
8518: @table @code
8519: @item enum reg_class
8520: An enumeral type that must be defined with all the register class names
8521: as enumeral values. @code{NO_REGS} must be first. @code{ALL_REGS}
8522: must be the last register class, followed by one more enumeral value,
8523: @code{LIM_REG_CLASSES}, which is not a register class but rather
8524: tells how many classes there are.
8525:
8526: Each register class has a number, which is the value of casting
8527: the class name to type @code{int}. The number serves as an index
8528: in many of the tables described below.
8529:
8530: @item N_REG_CLASSES
8531: The number of distinct register classes, defined as follows:
8532:
8533: @example
8534: #define N_REG_CLASSES (int) LIM_REG_CLASSES
8535: @end example
8536:
8537: @item REG_CLASS_NAMES
8538: An initializer containing the names of the register classes as C string
8539: constants. These names are used in writing some of the debugging dumps.
8540:
8541: @item REG_CLASS_CONTENTS
8542: An initializer containing the contents of the register classes, as integers
8543: which are bit masks. The @var{n}th integer specifies the contents of class
8544: @var{n}. The way the integer @var{mask} is interpreted is that
8545: register @var{r} is in the class if @code{@var{mask} & (1 << @var{r})} is 1.
8546:
8547: When the machine has more than 32 registers, an integer does not suffice.
8548: Then the integers are replaced by sub-initializers, braced groupings containing
8549: several integers. Each sub-initializer must be suitable as an initializer
8550: for the type @code{HARD_REG_SET} which is defined in @file{hard-reg-set.h}.
8551:
8552: @item REGNO_REG_CLASS (@var{regno})
8553: A C expression whose value is a register class containing hard register
8554: @var{regno}. In general there is more that one such class; choose a class
8555: which is @dfn{minimal}, meaning that no smaller class also contains the
8556: register.
8557:
8558: @item BASE_REG_CLASS
8559: A macro whose definition is the name of the class to which a valid
8560: base register must belong. A base register is one used in an address
8561: which is the register value plus a displacement.
8562:
8563: @item INDEX_REG_CLASS
8564: A macro whose definition is the name of the class to which a valid
8565: index register must belong. An index register is one used in an
8566: address where its value is either multiplied by a scale factor or
8567: added to another register (as well as added to a displacement).
8568:
8569: @item REG_CLASS_FROM_LETTER (@var{char})
8570: A C expression which defines the machine-dependent operand constraint
8571: letters for register classes. If @var{char} is such a letter, the
8572: value should be the register class corresponding to it. Otherwise,
8573: the value should be @code{NO_REGS}.
8574:
8575: @item REGNO_OK_FOR_BASE_P (@var{num})
8576: A C expression which is nonzero if register number @var{num} is
8577: suitable for use as a base register in operand addresses. It may be
8578: either a suitable hard register or a pseudo register that has been
8579: allocated such a hard register.
8580:
8581: @item REGNO_OK_FOR_INDEX_P (@var{num})
8582: A C expression which is nonzero if register number @var{num} is
8583: suitable for use as an index register in operand addresses. It may be
8584: either a suitable hard register or a pseudo register that has been
8585: allocated such a hard register.
8586:
8587: The difference between an index register and a base register is that
8588: the index register may be scaled. If an address involves the sum of
8589: two registers, neither one of them scaled, then either one may be
8590: labeled the ``base'' and the other the ``index''; but whichever
8591: labeling is used must fit the machine's constraints of which registers
8592: may serve in each capacity. The compiler will try both labelings,
8593: looking for one that is valid, and will reload one or both registers
8594: only if neither labeling works.
8595:
8596: @item PREFERRED_RELOAD_CLASS (@var{x}, @var{class})
8597: A C expression that places additional restrictions on the register class
8598: to use when it is necessary to copy value @var{x} into a register in class
8599: @var{class}. The value is a register class; perhaps @var{class}, or perhaps
8600: another, smaller class. On many machines, the definition
8601:
8602: @example
8603: #define PREFERRED_RELOAD_CLASS(X,CLASS) CLASS
8604: @end example
8605:
8606: @noindent
8607: is safe.
8608:
8609: Sometimes returning a more restrictive class makes better code. For
8610: example, on the 68000, when @var{x} is an integer constant that is in range
8611: for a @samp{moveq} instruction, the value of this macro is always
8612: @code{DATA_REGS} as long as @var{class} includes the data registers.
8613: Requiring a data register guarantees that a @samp{moveq} will be used.
8614:
1.1.1.8 root 8615: If @var{x} is a @code{const_double}, by returning @code{NO_REGS}
1.1 root 8616: you can force @var{x} into a memory constant. This is useful on
8617: certain machines where immediate floating values cannot be loaded into
8618: certain kinds of registers.
8619:
8620: In a shift instruction or a bitwise-and instruction, the mode of @var{x},
8621: the value being reloaded, may not be the same as the mode of the
8622: instruction's operand. (They will both be fixed-point modes, however.) In
8623: such a case, @var{class} may not be a safe value to return. @var{class} is
8624: certainly valid for the instruction, but it may not be valid for reloading
8625: @var{x}. This problem can occur on machines such as the 68000 and 80386
8626: where some registers can handle full-word values but cannot handle
8627: single-byte values.
8628:
8629: On such machines, this macro must examine the mode of @var{x} and return a
8630: subclass of @var{class} which can handle loads and stores of that mode. On
8631: the 68000, where address registers cannot handle @code{QImode}, if @var{x}
8632: has @code{QImode} then you must return @code{DATA_REGS}. If @var{class} is
8633: @code{ADDR_REGS}, then there is no correct value to return; but the shift
8634: and bitwise-and instructions don't use @code{ADDR_REGS}, so this fatal case
8635: never arises.
8636:
8637: @item CLASS_MAX_NREGS (@var{class}, @var{mode})
8638: A C expression for the maximum number of consecutive registers
8639: of class @var{class} needed to hold a value of mode @var{mode}.
8640:
8641: This is closely related to the macro @code{HARD_REGNO_NREGS}.
8642: In fact, the value of the macro @code{CLASS_MAX_NREGS (@var{class}, @var{mode})}
8643: should be the maximum value of @code{HARD_REGNO_NREGS (@var{regno}, @var{mode})}
8644: for all @var{regno} values in the class @var{class}.
8645:
8646: This macro helps control the handling of multiple-word values
8647: in the reload pass.
8648: @end table
8649:
8650: Two other special macros describe which constants fit which constraint
8651: letters.
8652:
8653: @table @code
8654: @item CONST_OK_FOR_LETTER_P (@var{value}, @var{c})
8655: A C expression that defines the machine-dependent operand constraint letters
8656: that specify particular ranges of integer values. If @var{c} is one
8657: of those letters, the expression should check that @var{value}, an integer,
8658: is in the appropriate range and return 1 if so, 0 otherwise. If @var{c} is
8659: not one of those letters, the value should be 0 regardless of @var{value}.
8660:
8661: @item CONST_DOUBLE_OK_FOR_LETTER_P (@var{value}, @var{c})
8662: A C expression that defines the machine-dependent operand constraint
8663: letters that specify particular ranges of floating values. If @var{c} is
8664: one of those letters, the expression should check that @var{value}, an RTX
1.1.1.8 root 8665: of code @code{const_double}, is in the appropriate range and return 1 if
1.1 root 8666: so, 0 otherwise. If @var{c} is not one of those letters, the value should
8667: be 0 regardless of @var{value}.
8668: @end table
8669:
1.1.1.12! root 8670: @node Stack Layout, Library Calls, Register Classes, Machine Macros
1.1 root 8671: @section Describing Stack Layout
8672:
8673: @table @code
8674: @item STACK_GROWS_DOWNWARD
8675: Define this macro if pushing a word onto the stack moves the stack
8676: pointer to a smaller address.
8677:
8678: When we say, ``define this macro if @dots{},'' it means that the
8679: compiler checks this macro only with @code{#ifdef} so the precise
8680: definition used does not matter.
8681:
8682: @item FRAME_GROWS_DOWNWARD
8683: Define this macro if the addresses of local variable slots are at negative
8684: offsets from the frame pointer.
8685:
8686: @item STARTING_FRAME_OFFSET
8687: Offset from the frame pointer to the first local variable slot to be allocated.
8688:
8689: If @code{FRAME_GROWS_DOWNWARD}, the next slot's offset is found by
8690: subtracting the length of the first slot from @code{STARTING_FRAME_OFFSET}.
8691: Otherwise, it is found by adding the length of the first slot to
8692: the value @code{STARTING_FRAME_OFFSET}.
8693:
8694: @item PUSH_ROUNDING (@var{npushed})
8695: A C expression that is the number of bytes actually pushed onto the
8696: stack when an instruction attempts to push @var{npushed} bytes.
8697:
8698: If the target machine does not have a push instruction, do not define
8699: this macro. That directs GNU CC to use an alternate strategy: to
8700: allocate the entire argument block and then store the arguments into
8701: it.
8702:
8703: On some machines, the definition
8704:
8705: @example
8706: #define PUSH_ROUNDING(BYTES) (BYTES)
8707: @end example
8708:
8709: @noindent
8710: will suffice. But on other machines, instructions that appear
8711: to push one byte actually push two bytes in an attempt to maintain
8712: alignment. Then the definition should be
8713:
8714: @example
8715: #define PUSH_ROUNDING(BYTES) (((BYTES) + 1) & ~1)
8716: @end example
8717:
8718: @item FIRST_PARM_OFFSET (@var{fundecl})
8719: Offset from the argument pointer register to the first argument's
8720: address. On some machines it may depend on the data type of the
8721: function. (In the next version of GNU CC, the argument will be
8722: changed to the function data type rather than its declaration.)
8723:
8724: @item FIRST_PARM_CALLER_OFFSET (@var{fundecl})
8725: Define this macro on machines where register parameters have shadow
8726: locations on the stack, at addresses below the nominal parameter.
8727: This matters because certain arguments cannot be passed on the stack.
8728: On these machines, such arguments must be stored into the shadow
8729: locations.
8730:
8731: This macro should expand into a C expression whose value is the offset
8732: of the first parameter's shadow location from the nominal stack
8733: pointer value. (That value is itself computed by adding the value of
8734: @code{STACK_POINTER_OFFSET} to the stack pointer register.)
8735:
1.1.1.9 root 8736: @item REG_PARM_STACK_SPACE
8737: Define this macro if functions should assume that stack space has been
8738: allocated for arguments even when their values are passed in
8739: registers.
8740:
8741: The actual allocation of such space would be done either by
8742: the call instruction or by the function prologue, or by
1.1.1.10 root 8743: defining @code{FIRST_PARM_CALLER_OFFSET}.
1.1.1.9 root 8744:
1.1.1.6 root 8745: @item STACK_ARGS_ADJUST (@var{size})
8746: Define this macro if the machine requires padding on the stack for
8747: certain function calls. This is padding on a per-function-call basis,
8748: not padding for individual arguments.
8749:
1.1.1.7 root 8750: The argument @var{size} will be a C variable of type @code{struct
8751: arg_data} which contains two fields, an integer named @code{constant}
8752: and an RTX named @code{var}. These together represent a size measured
8753: in bytes which is the sum of the integer and the RTX. Most of the
8754: time @code{var} is 0, which means that the size is simply the integer.
8755:
8756: The definition should be a C statement or compound statement
8757: which alters the variable supplied in whatever way you wish.
8758:
8759: Note that the value you leave in the variable @code{size} will
8760: ultimately be rounded up to a multiple of @code{STACK_BOUNDARY} bits.
8761:
8762: This macro is not fully implemented for machines which have push
8763: instructions (i.e., on which @code{PUSH_ROUNDING} is defined).
1.1.1.6 root 8764:
1.1 root 8765: @item RETURN_POPS_ARGS (@var{funtype})
8766: A C expression that should be 1 if a function pops its own arguments
8767: on returning, or 0 if the function pops no arguments and the caller
8768: must therefore pop them all after the function returns.
8769:
8770: @var{funtype} is a C variable whose value is a tree node that
8771: describes the function in question. Normally it is a node of type
8772: @code{FUNCTION_TYPE} that describes the data type of the function.
8773: From this it is possible to obtain the data types of the value and
8774: arguments (if known).
8775:
8776: When a call to a library function is being considered, @var{funtype}
8777: will contain an identifier node for the library function. Thus, if
8778: you need to distinguish among various library functions, you can do so
8779: by their names. Note that ``library function'' in this context means
8780: a function used to perform arithmetic, whose name is known specially
8781: in the compiler and was not mentioned in the C code being compiled.
8782:
8783: On the Vax, all functions always pop their arguments, so the
8784: definition of this macro is 1. On the 68000, using the standard
8785: calling convention, no functions pop their arguments, so the value of
8786: the macro is always 0 in this case. But an alternative calling
8787: convention is available in which functions that take a fixed number of
8788: arguments pop them but other functions (such as @code{printf}) pop
8789: nothing (the caller pops all). When this convention is in use,
8790: @var{funtype} is examined to determine whether a function takes a
8791: fixed number of arguments.
8792:
1.1.1.10 root 8793: When this macro returns nonzero, the macro @code{FRAME_POINTER_REQUIRED}
8794: must also return nonzero for proper operation.
8795:
1.1 root 8796: @item FUNCTION_VALUE (@var{valtype}, @var{func})
8797: A C expression to create an RTX representing the place where a
8798: function returns a value of data type @var{valtype}. @var{valtype} is
8799: a tree node representing a data type. Write @code{TYPE_MODE
8800: (@var{valtype})} to get the machine mode used to represent that type.
8801: On many machines, only the mode is relevant. (Actually, on most
8802: machines, scalar values are returned in the same place regardless of
8803: mode).@refill
8804:
8805: If the precise function being called is known, @var{func} is a tree
8806: node (@code{FUNCTION_DECL}) for it; otherwise, @var{func} is a null
8807: pointer. This makes it possible to use a different value-returning
8808: convention for specific functions when all their calls are
8809: known.@refill
8810:
8811: @item FUNCTION_OUTGOING_VALUE (@var{valtype}, @var{func})
8812: Define this macro if the target machine has ``register windows''
8813: so that the register in which a function returns its value is not
8814: the same as the one in which the caller sees the value.
8815:
8816: For such machines, @code{FUNCTION_VALUE} computes the register in
8817: which the caller will see the value, and
8818: @code{FUNCTION_OUTGOING_VALUE} should be defined in a similar fashion
8819: to tell the function where to put the value.@refill
8820:
8821: If @code{FUNCTION_OUTGOING_VALUE} is not defined,
8822: @code{FUNCTION_VALUE} serves both purposes.@refill
8823:
1.1.1.7 root 8824: @item RETURN_IN_MEMORY (@var{type})
8825: A C expression which can inhibit the returning of certain function
8826: values in registers, based on the type of value. A nonzero value says
8827: to return the function value in memory, just as large structures are
8828: always returned. Here @var{type} will be a C expression of type
8829: @code{tree}, representing the data type of the value.
8830:
8831: Note that values of mode @code{BLKmode} are returned in memory
8832: regardless of this macro. Also, the option @samp{-fpcc-struct-return}
8833: takes effect regardless of this macro. On most systems, it is
8834: possible to leave the macro undefined; this causes a default
8835: definition to be used, whose value is the constant 0.
8836:
1.1 root 8837: @item LIBCALL_VALUE (@var{mode})
8838: A C expression to create an RTX representing the place where a library
8839: function returns a value of mode @var{mode}. If the precise function
8840: being called is known, @var{func} is a tree node
8841: (@code{FUNCTION_DECL}) for it; otherwise, @var{func} is a null
8842: pointer. This makes it possible to use a different value-returning
8843: convention for specific functions when all their calls are
8844: known.@refill
8845:
8846: Note that ``library function'' in this context means a compiler
8847: support routine, used to perform arithmetic, whose name is known
8848: specially by the compiler and was not mentioned in the C code being
8849: compiled.
8850:
8851: @item FUNCTION_VALUE_REGNO_P (@var{regno})
8852: A C expression that is nonzero if @var{regno} is the number of a hard
8853: register in which the values of called function may come back.
8854:
8855: A register whose use for returning values is limited to serving as the
8856: second of a pair (for a value of type @code{double}, say) need not be
8857: recognized by this macro. So for most machines, this definition
8858: suffices:
8859:
8860: @example
8861: #define FUNCTION_VALUE_REGNO_P(N) ((N) == 0)
8862: @end example
8863:
8864: If the machine has register windows, so that the caller and the called
8865: function use different registers for the return value, this macro
8866: should recognize only the caller's register numbers.
8867:
8868: @item FUNCTION_ARG (@var{cum}, @var{mode}, @var{type}, @var{named})
8869: A C expression that controls whether a function argument is passed
8870: in a register, and which register.
8871:
8872: The arguments are @var{cum}, which summarizes all the previous
8873: arguments; @var{mode}, the machine mode of the argument; @var{type},
8874: the data type of the argument as a tree node or 0 if that is not known
8875: (which happens for C support library functions); and @var{named},
8876: which is 1 for an ordinary argument and 0 for nameless arguments that
1.1.1.8 root 8877: correspond to @samp{@dots{}} in the called function's prototype.
1.1 root 8878:
1.1.1.8 root 8879: The value of the expression should either be a @code{reg} RTX for the
1.1 root 8880: hard register in which to pass the argument, or zero to pass the
8881: argument on the stack.
8882:
8883: For the Vax and 68000, where normally all arguments are pushed, zero
8884: suffices as a definition.
8885:
1.1.1.8 root 8886: The usual way to make the ANSI library @file{stdarg.h} work on a machine
8887: where some arguments are usually passed in registers, is to cause
8888: nameless arguments to be passed on the stack instead. This is done
8889: by making @code{FUNCTION_ARG} return 0 whenever @var{named} is 0.
8890:
1.1 root 8891: @item FUNCTION_INCOMING_ARG (@var{cum}, @var{mode}, @var{type}, @var{named})
8892: Define this macro if the target machine has ``register windows'', so
8893: that the register in which a function sees an arguments is not
8894: necessarily the same as the one in which the caller passed the
8895: argument.
8896:
8897: For such machines, @code{FUNCTION_ARG} computes the register in which
8898: the caller passes the value, and @code{FUNCTION_INCOMING_ARG} should
8899: be defined in a similar fashion to tell the function being called
8900: where the arguments will arrive.
8901:
8902: If @code{FUNCTION_INCOMING_ARG} is not defined, @code{FUNCTION_ARG}
8903: serves both purposes.@refill
8904:
8905: @item FUNCTION_ARG_PARTIAL_NREGS (@var{cum}, @var{mode}, @var{type}, @var{named})
8906: A C expression for the number of words, at the beginning of an
8907: argument, must be put in registers. The value must be zero for
8908: arguments that are passed entirely in registers or that are entirely
8909: pushed on the stack.
8910:
8911: On some machines, certain arguments must be passed partially in
8912: registers and partially in memory. On these machines, typically the
8913: first @var{n} words of arguments are passed in registers, and the rest
8914: on the stack. If a multi-word argument (a @code{double} or a
8915: structure) crosses that boundary, its first few words must be passed
8916: in registers and the rest must be pushed. This macro tells the
8917: compiler when this occurs, and how many of the words should go in
8918: registers.
8919:
8920: @code{FUNCTION_ARG} for these arguments should return the first
8921: register to be used by the caller for this argument; likewise
8922: @code{FUNCTION_INCOMING_ARG}, for the called function.
8923:
8924: @item CUMULATIVE_ARGS
8925: A C type for declaring a variable that is used as the first argument
8926: of @code{FUNCTION_ARG} and other related values. For some target
8927: machines, the type @code{int} suffices and can hold the number of
8928: bytes of argument so far.
8929:
8930: @item INIT_CUMULATIVE_ARGS (@var{cum}, @var{fntype})
8931: A C statement (sans semicolon) for initializing the variable @var{cum}
8932: for the state at the beginning of the argument list. The variable has
8933: type @code{CUMULATIVE_ARGS}. The value of @var{fntype} is the tree node
8934: for the data type of the function which will receive the args, or 0
8935: if the args are to a compiler support library function.
8936:
8937: @item FUNCTION_ARG_ADVANCE (@var{cum}, @var{mode}, @var{type}, @var{named})
1.1.1.7 root 8938: A C statement (sans semicolon) to update the summarizer variable
8939: @var{cum} to advance past an argument in the argument list. The
8940: values @var{mode}, @var{type} and @var{named} describe that argument.
8941: Once this is done, the variable @var{cum} is suitable for analyzing
8942: the @emph{following} argument with @code{FUNCTION_ARG}, etc.@refill
1.1 root 8943:
8944: @item FUNCTION_ARG_REGNO_P (@var{regno})
8945: A C expression that is nonzero if @var{regno} is the number of a hard
8946: register in which function arguments are sometimes passed. This does
8947: @emph{not} include implicit arguments such as the static chain and
8948: the structure-value address. On many machines, no registers can be
8949: used for this purpose since all function arguments are pushed on the
8950: stack.
8951:
8952: @item FUNCTION_ARG_PADDING (@var{mode}, @var{size})
8953: If defined, a C expression which determines whether, and in which direction,
8954: to pad out an argument with extra space. The value should be of type
8955: @code{enum direction}: either @code{upward} to pad above the argument,
8956: @code{downward} to pad below, or @code{none} to inhibit padding.
8957:
8958: The argument @var{size} is an RTX which describes the size of the
8959: argument, in bytes. It should be used only if @var{mode} is
8960: @code{BLKmode}. Otherwise, @var{size} is 0.
8961:
8962: This macro does not control the @emph{amount} of padding; that is
8963: always just enough to reach the next multiple of @code{PARM_BOUNDARY}.
8964:
8965: This macro has a default definition which is right for most systems.
8966: For little-endian machines, the default is to pad upward. For
8967: big-endian machines, the default is to pad downward for an argument of
8968: constant size shorter than an @code{int}, and upward otherwise.
8969:
8970: @item FUNCTION_PROLOGUE (@var{file}, @var{size})
8971: A C compound statement that outputs the assembler code for entry to a
8972: function. The prologue is responsible for setting up the stack frame,
8973: initializing the frame pointer register, saving registers that must be
8974: saved, and allocating @var{size} additional bytes of storage for the
8975: local variables. @var{size} is an integer. @var{file} is a stdio
8976: stream to which the assembler code should be output.
8977:
8978: The label for the beginning of the function need not be output by this
8979: macro. That has already been done when the macro is run.
8980:
8981: To determine which registers to save, the macro can refer to the array
8982: @code{regs_ever_live}: element @var{r} is nonzero if hard register
8983: @var{r} is used anywhere within the function. This implies the
8984: function prologue should save register @var{r}, but not if it is one
8985: of the call-used registers.
8986:
8987: On machines where functions may or may not have frame-pointers, the
8988: function entry code must vary accordingly; it must set up the frame
8989: pointer if one is wanted, and not otherwise. To determine whether a
8990: frame pointer is in wanted, the macro can refer to the variable
8991: @code{frame_pointer_needed}. The variable's value will be 1 at run
8992: time in a function that needs a frame pointer.
8993:
1.1.1.10 root 8994: On machines where an argument may be passed partly in registers and
8995: partly in memory, this macro must examine the variable
1.1.1.8 root 8996: @code{current_function_pretend_args_size}, and allocate that many bytes
8997: of uninitialized space on the stack just underneath the first argument
8998: arriving on the stack. (This may not be at the very end of the stack,
8999: if the calling sequence has pushed anything else since pushing the stack
9000: arguments. But usually, on such machines, nothing else has been pushed
9001: yet, because the function prologue itself does all the pushing.)
9002:
1.1 root 9003: @item FUNCTION_PROFILER (@var{file}, @var{labelno})
9004: A C statement or compound statement to output to @var{file} some
9005: assembler code to call the profiling subroutine @code{mcount}.
9006: Before calling, the assembler code must load the address of a
9007: counter variable into a register where @code{mcount} expects to
9008: find the address. The name of this variable is @samp{LP} followed
9009: by the number @var{labelno}, so you would generate the name using
9010: @samp{LP%d} in a @code{fprintf}.
9011:
9012: The details of how the address should be passed to @code{mcount} are
9013: determined by your operating system environment, not by GNU CC. To
9014: figure them out, compile a small program for profiling using the
9015: system's installed C compiler and look at the assembler code that
9016: results.
9017:
1.1.1.6 root 9018: @item FUNCTION_BLOCK_PROFILER (@var{file}, @var{labelno})
9019: A C statement or compound statement to output to @var{file} some
9020: assembler code to initialize basic-block profiling for the current
9021: object module. This code should call the subroutine
9022: @code{__bb_init_func} once per object module, passing it as its sole
9023: argument the address of a block allocated in the object module.
9024:
9025: The name of the block is a local symbol made with this statement:
9026:
9027: @example
9028: ASM_GENERATE_INTERNAL_LABEL (@var{buffer}, "LPBX", 0);
9029: @end example
9030:
9031: Of course, since you are writing the definition of
9032: @code{ASM_GENERATE_INTERNAL_LABEL} as well as that of this macro, you
9033: can take a short cut in the definition of this macro and use the name
9034: that you know will result.
9035:
9036: The first word of this block is a flag which will be nonzero if the
9037: object module has already been initialized. So test this word first,
9038: and do not call @code{__bb_init_func} if the flag is nonzero.
9039:
9040: @item BLOCK_PROFILER (@var{file}, @var{blockno})
9041: A C statement or compound statement to increment the count associated
9042: with the basic block number @var{blockno}. Basic blocks are numbered
9043: separately from zero within each compilation. The count associated
9044: with block number @var{blockno} is at index @var{blockno} in a vector
9045: of words; the name of this array is a local symbol made with this
9046: statement:
9047:
9048: @example
9049: ASM_GENERATE_INTERNAL_LABEL (@var{buffer}, "LPBX", 2);
9050: @end example
9051:
9052: Of course, since you are writing the definition of
9053: @code{ASM_GENERATE_INTERNAL_LABEL} as well as that of this macro, you
9054: can take a short cut in the definition of this macro and use the name
9055: that you know will result.
9056:
1.1.1.10 root 9057: @item EXIT_IGNORE_STACK
1.1 root 9058: Define this macro as a C expression that is nonzero if the return
9059: instruction or the function epilogue ignores the value of the stack
9060: pointer; in other words, if it is safe to delete an instruction to
9061: adjust the stack pointer before a return from the function.
9062:
1.1.1.8 root 9063: Note that this macro's value is relevant only for functions for which
9064: frame pointers are maintained. It is never safe to delete a final
9065: stack adjustment in a function that has no frame pointer, and the
1.1.1.10 root 9066: compiler knows this regardless of @code{EXIT_IGNORE_STACK}.
1.1 root 9067:
9068: @item FUNCTION_EPILOGUE (@var{file}, @var{size})
9069: A C compound statement that outputs the assembler code for exit from a
9070: function. The epilogue is responsible for restoring the saved
9071: registers and stack pointer to their values when the function was
9072: called, and returning control to the caller. This macro takes the
9073: same arguments as the macro @code{FUNCTION_PROLOGUE}, and the
9074: registers to restore are determined from @code{regs_ever_live} and
9075: @code{CALL_USED_REGISTERS} in the same way.
9076:
9077: On some machines, there is a single instruction that does all the work
9078: of returning from the function. On these machines, give that
9079: instruction the name @samp{return} and do not define the macro
9080: @code{FUNCTION_EPILOGUE} at all.
9081:
9082: Do not define a pattern named @samp{return} if you want the
9083: @code{FUNCTION_EPILOGUE} to be used. If you want the target switches
9084: to control whether return instructions or epilogues are used, define a
9085: @samp{return} pattern with a validity condition that tests the target
9086: switches appropriately. If the @samp{return} pattern's validity
9087: condition is false, epilogues will be used.
9088:
9089: On machines where functions may or may not have frame-pointers, the
9090: function exit code must vary accordingly. Sometimes the code for
9091: these two cases is completely different. To determine whether a frame
9092: pointer is in wanted, the macro can refer to the variable
9093: @code{frame_pointer_needed}. The variable's value will be 1 at run
9094: time in a function that needs a frame pointer.
9095:
9096: On some machines, some functions pop their arguments on exit while
9097: others leave that for the caller to do. For example, the 68020 when
9098: given @samp{-mrtd} pops arguments in functions that take a fixed
9099: number of arguments.
9100:
9101: Your definition of the macro @code{RETURN_POPS_ARGS} decides which
9102: functions pop their own arguments. @code{FUNCTION_EPILOGUE} needs to
9103: know what was decided. The variable @code{current_function_pops_args}
9104: is nonzero if the function should pop its own arguments. If so, use
9105: the variable @code{current_function_args_size} as the number of bytes
9106: to pop.
9107:
9108: @item FIX_FRAME_POINTER_ADDRESS (@var{addr}, @var{depth})
9109: A C compound statement to alter a memory address that uses the frame
9110: pointer register so that it uses the stack pointer register instead.
9111: This must be done in the instructions that load parameter values into
9112: registers, when the reload pass determines that a frame pointer is not
9113: necessary for the function. @var{addr} will be a C variable name, and
9114: the updated address should be stored in that variable. @var{depth}
9115: will be the current depth of stack temporaries (number of bytes of
9116: arguments currently pushed). The change in offset between a
9117: frame-pointer-relative address and a stack-pointer-relative address
9118: must include @var{depth}.
9119:
9120: Even if your machine description specifies there will always be a
9121: frame pointer in the frame pointer register, you must still define
9122: @code{FIX_FRAME_POINTER_ADDRESS}, but the definition will never be
9123: executed at run time, so it may be empty.
1.1.1.8 root 9124:
9125: @item LONGJMP_RESTORE_FROM_STACK
9126: Define this macro if the @code{longjmp} function restores registers
9127: from the stack frames, rather than from those saved specifically by
9128: @code{setjmp}. Certain quantities must not be kept in registers
9129: across a call to @code{setjmp} on such machines.
1.1 root 9130: @end table
9131:
1.1.1.12! root 9132: @node Library Calls, Addressing Modes, Stack Layout, Machine Macros
! 9133: @section Implicit Use of Library Routines
1.1 root 9134:
9135: @table @code
1.1.1.5 root 9136: @item MULSI3_LIBCALL
9137: A C string constant giving the name of the function to call for
9138: multiplication of one signed full-word by another. If you do not
9139: define this macro, the default name is used, which is @code{__mulsi3},
9140: a function defined in @file{gnulib}.
9141:
9142: @item UMULSI3_LIBCALL
9143: A C string constant giving the name of the function to call for
9144: multiplication of one unsigned full-word by another. If you do not
9145: define this macro, the default name is used, which is
9146: @code{__umulsi3}, a function defined in @file{gnulib}.
9147:
9148: @item DIVSI3_LIBCALL
9149: A C string constant giving the name of the function to call for
9150: division of one signed full-word by another. If you do not define
9151: this macro, the default name is used, which is @code{__divsi3}, a
9152: function defined in @file{gnulib}.
9153:
1.1 root 9154: @item UDIVSI3_LIBCALL
9155: A C string constant giving the name of the function to call for
1.1.1.5 root 9156: division of one unsigned full-word by another. If you do not define
9157: this macro, the default name is used, which is @code{__udivsi3}, a
9158: function defined in @file{gnulib}.
9159:
9160: @item MODSI3_LIBCALL
9161: A C string constant giving the name of the function to call for the
9162: remainder in division of one signed full-word by another. If you do
9163: not define this macro, the default name is used, which is
9164: @code{__modsi3}, a function defined in @file{gnulib}.
1.1 root 9165:
9166: @item UMODSI3_LIBCALL
9167: A C string constant giving the name of the function to call for the
1.1.1.5 root 9168: remainder in division of one unsigned full-word by another. If you do
9169: not define this macro, the default name is used, which is
9170: @code{__umodsi3}, a function defined in @file{gnulib}.
1.1 root 9171:
9172: @item TARGET_MEM_FUNCTIONS
9173: Define this macro if GNU CC should generate calls to the System V
9174: (and ANSI C) library functions @code{memcpy} and @code{memset}
9175: rather than the BSD functions @code{bcopy} and @code{bzero}.
1.1.1.12! root 9176:
! 9177: @item GNULIB_NEEDS_DOUBLE
! 9178: Define this macro if only @code{float} arguments cannot be passed to
! 9179: library routines (so they must be converted to @code{double}). This
! 9180: macro affects both how library calls are generated and how the library
! 9181: routines in @file{gnulib.c} accept their arguments. It is useful on
! 9182: machines where floating and fixed point arguments are passed
! 9183: differently, such as the i860.
1.1 root 9184: @end table
9185:
1.1.1.12! root 9186: @node Addressing Modes, Delayed Branch, Library Calls, Machine Macros
1.1 root 9187: @section Addressing Modes
9188:
9189: @table @code
9190: @item HAVE_POST_INCREMENT
9191: Define this macro if the machine supports post-increment addressing.
9192:
9193: @item HAVE_PRE_INCREMENT
9194: @itemx HAVE_POST_DECREMENT
9195: @itemx HAVE_PRE_DECREMENT
9196: Similar for other kinds of addressing.
9197:
9198: @item CONSTANT_ADDRESS_P (@var{x})
9199: A C expression that is 1 if the RTX @var{x} is a constant whose value
9200: is an integer. This includes integers whose values are not explicitly
1.1.1.8 root 9201: known, such as @code{symbol_ref} and @code{label_ref} expressions and
9202: @code{const} arithmetic expressions.
1.1 root 9203:
9204: On most machines, this can be defined as @code{CONSTANT_P (@var{x})},
9205: but a few machines are more restrictive in which constant addresses
9206: are supported.
9207:
9208: @item MAX_REGS_PER_ADDRESS
9209: A number, the maximum number of registers that can appear in a valid
1.1.1.10 root 9210: memory address. Note that it is up to you to specify a value equal to
9211: the maximum number that @code{go_if_legitimate_address} would ever
9212: accept.
1.1 root 9213:
9214: @item GO_IF_LEGITIMATE_ADDRESS (@var{mode}, @var{x}, @var{label})
9215: A C compound statement with a conditional @code{goto @var{label};}
9216: executed if @var{x} (an RTX) is a legitimate memory address on the
9217: target machine for a memory operand of mode @var{mode}.
9218:
9219: It usually pays to define several simpler macros to serve as
9220: subroutines for this one. Otherwise it may be too complicated to
9221: understand.
9222:
9223: This macro must exist in two variants: a strict variant and a
9224: non-strict one. The strict variant is used in the reload pass. It
9225: must be defined so that any pseudo-register that has not been
9226: allocated a hard register is considered a memory reference. In
9227: contexts where some kind of register is required, a pseudo-register
9228: with no hard register must be rejected.
9229:
9230: The non-strict variant is used in other passes. It must be defined to
9231: accept all pseudo-registers in every context where some kind of
9232: register is required.
9233:
9234: Compiler source files that want to use the strict variant of this
9235: macro define the macro @code{REG_OK_STRICT}. You should use an
9236: @code{#ifdef REG_OK_STRICT} conditional to define the strict variant
9237: in that case and the non-strict variant otherwise.
9238:
9239: Typically among the subroutines used to define
9240: @code{GO_IF_LEGITIMATE_ADDRESS} are subroutines to check for
9241: acceptable registers for various purposes (one for base registers, one
9242: for index registers, and so on). Then only these subroutine macros
9243: need have two variants; the higher levels of macros may be the same
9244: whether strict or not.@refill
9245:
1.1.1.8 root 9246: Normally, constant addresses which are the sum of a @code{symbol_ref}
9247: and an integer are stored inside a @code{const} RTX to mark them as
9248: constant. Therefore, there is no need to recognize such sums as
9249: legitimate addresses.
9250:
9251: Usually @code{PRINT_OPERAND_ADDRESS} is not prepared to handle constant
9252: sums that are not marked with @code{const}. It assumes that a naked
9253: @code{plus} indicates indexing. If so, then you @emph{must} reject such
9254: naked constant sums as illegitimate addresses, so that none of them will
9255: be given to @code{PRINT_OPERAND_ADDRESS}.@refill
9256:
1.1 root 9257: @item REG_OK_FOR_BASE_P (@var{x})
1.1.1.5 root 9258: A C expression that is nonzero if @var{x} (assumed to be a @code{reg}
1.1 root 9259: RTX) is valid for use as a base register. For hard registers, it
9260: should always accept those which the hardware permits and reject the
9261: others. Whether the macro accepts or rejects pseudo registers must be
9262: controlled by @code{REG_OK_STRICT} as described above. This usually
9263: requires two variant definitions, of which @code{REG_OK_STRICT}
9264: controls the one actually used.
9265:
9266: @item REG_OK_FOR_INDEX_P (@var{x})
1.1.1.5 root 9267: A C expression that is nonzero if @var{x} (assumed to be a @code{reg}
1.1 root 9268: RTX) is valid for use as an index register.
9269:
9270: The difference between an index register and a base register is that
9271: the index register may be scaled. If an address involves the sum of
9272: two registers, neither one of them scaled, then either one may be
9273: labeled the ``base'' and the other the ``index''; but whichever
9274: labeling is used must fit the machine's constraints of which registers
9275: may serve in each capacity. The compiler will try both labelings,
9276: looking for one that is valid, and will reload one or both registers
9277: only if neither labeling works.
9278:
9279: @item LEGITIMIZE_ADDRESS (@var{x}, @var{oldx}, @var{mode}, @var{win})
9280: A C compound statement that attempts to replace @var{x} with a valid
9281: memory address for an operand of mode @var{mode}. @var{win} will be a
9282: C statement label elsewhere in the code; the macro definition may use
9283:
9284: @example
9285: GO_IF_LEGITIMATE_ADDRESS (@var{mode}, @var{x}, @var{win});
9286: @end example
9287:
9288: @noindent
9289: to avoid further processing if the address has become legitimate.
9290:
9291: @var{x} will always be the result of a call to @code{break_out_memory_refs},
9292: and @var{oldx} will be the operand that was given to that function to produce
9293: @var{x}.
9294:
9295: The code generated by this macro should not alter the substructure of
9296: @var{x}. If it transforms @var{x} into a more legitimate form, it
9297: should assign @var{x} (which will always be a C variable) a new value.
9298:
9299: It is not necessary for this macro to come up with a legitimate
9300: address. The compiler has standard ways of doing so in all cases. In
9301: fact, it is safe for this macro to do nothing. But often a
9302: machine-dependent strategy can generate better code.
9303:
9304: @item GO_IF_MODE_DEPENDENT_ADDRESS (@var{addr}, @var{label})
9305: A C statement or compound statement with a conditional @code{goto
9306: @var{label};} executed if memory address @var{x} (an RTX) can have
9307: different meanings depending on the machine mode of the memory
9308: reference it is used for.
9309:
9310: Autoincrement and autodecrement addresses typically have mode-dependent
9311: effects because the amount of the increment or decrement is the size
9312: of the operand being addressed. Some machines have other mode-dependent
9313: addresses. Many RISC machines have no mode-dependent addresses.
9314:
9315: You may assume that @var{addr} is a valid address for the machine.
9316:
9317: @item LEGITIMATE_CONSTANT_P (@var{x})
9318: A C expression that is nonzero if @var{x} is a legitimate constant for
9319: an immediate operand on the target machine. You can assume that
1.1.1.8 root 9320: either @var{x} is a @code{const_double} or it satisfies
1.1 root 9321: @code{CONSTANT_P}, so you need not check these things. In fact,
9322: @samp{1} is a suitable definition for this macro on machines where any
1.1.1.8 root 9323: @code{const_double} is valid and anything @code{CONSTANT_P} is valid.@refill
9324: @end table
9325:
9326: @node Delayed Branch, Condition Code, Addressing Modes, Machine Macros
9327: @section Parameters for Delayed Branch Optimization
9328:
9329: @table @code
9330: @item HAVE_DELAYED_BRANCH
9331: Define this macro if the target machine has delayed branches, that is,
9332: a branch does not take effect immediately, and the actual branch
9333: instruction may be followed by one or more instructions that will be
9334: issued before the PC is actually changed.
9335:
9336: If defined, this allows a special scheduling pass to be run after the
9337: second jump optimization to attempt to reorder instructions to exploit
9338: this. Defining this macro also requires the definition of certain
9339: other macros described below.
9340:
9341: @item DBR_SLOTS_AFTER (@var{insn})
9342: This macro must be defined if @code{HAVE_DELAYED_BRANCH} is defined.
9343: Its definition should be a C expression returning the number of
9344: available delay slots following the instruction(s) output by the
9345: pattern for @var{insn}. The definition of ``slot'' is
9346: machine-dependent, and may denote instructions, bytes, or whatever.
9347:
9348: @item DBR_INSN_SLOTS (@var{insn})
9349: This macro must be defined if @code{HAVE_DELAYED_BRANCH} is defined.
9350: It should be a C expression returning the number of slots (typically
9351: the number of machine instructions) consumed by @var{insn}.
9352:
9353: You may assume that @var{insn} is truly an insn, not a note, label,
9354: barrier, dispatch table, @code{use}, or @code{clobber}.
9355:
9356: @item DBR_INSN_ELIGIBLE_P (@var{insn}, @var{dinsn})
9357: A C expression whose value is non-zero if it is legitimate to put
9358: @var{insn} in the delay slot following @var{dinsn}.
9359:
9360: You do not need to take account of data flow considerations in the
9361: definition of this macro, because the delayed branch optimizer always
9362: does that. This macro is needed only when certain insns may not be
9363: placed in certain delay slots for reasons not evident from the RTL
9364: expressions themselves. If there are no such problems, you don't need
9365: to define this macro.
9366:
9367: You may assume that @var{insn} is truly an insn, not a note, label,
9368: barrier, dispatch table, @code{use}, or @code{clobber}. You may
9369: assume that @var{dinsn} is a jump insn with a delay slot.
9370:
9371: @item DBR_OUTPUT_SEQEND(@var{file})
9372: A C statement, to be executed after all slot-filler instructions have
9373: been output. If necessary, call @code{dbr_sequence_length} to
9374: determine the number of slots filled in a sequence (zero if not
9375: currently outputting a sequence), to decide how many no-ops to output,
9376: or whatever.
9377:
9378: Don't define this macro if it has nothing to do, but it is helpful in
9379: reading assembly output if the extent of the delay sequence is made
9380: explicit (e.g. with white space).
9381:
9382: Note that output routines for instructions with delay slots must be
9383: prepared to deal with not being output as part of a sequence (i.e.
9384: when the scheduling pass is not run, or when no slot fillers could be
9385: found.) The variable @code{final_sequence} is null when not
9386: processing a sequence, otherwise it contains the @code{sequence} rtx
9387: being output.
1.1 root 9388: @end table
9389:
1.1.1.9 root 9390: @node Condition Code, Cross-compilation, Delayed Branch, Machine Macros
1.1.1.8 root 9391: @section Condition Code Information
9392:
9393: The file @file{conditions.h} defines a variable @code{cc_status} to
9394: describe how the condition code was computed (in case the interpretation of
9395: the condition code depends on the instruction that it was set by). This
9396: variable contains the RTL expressions on which the condition code is
9397: currently based, and several standard flags.
9398:
9399: Sometimes additional machine-specific flags must be defined in the machine
9400: description header file. It can also add additional machine-specific
9401: information by defining @code{CC_STATUS_MDEP}.
9402:
9403: @table @code
9404: @item CC_STATUS_MDEP
9405: C code for a data type which is used for declaring the @code{mdep}
9406: component of @code{cc_status}. It defaults to @code{int}.
9407:
9408: @item CC_STATUS_MDEP_INIT
1.1.1.9 root 9409: A C expression to initialize the @code{mdep} field to ``empty''.
9410: The default definition does nothing, since most machines don't use
9411: the field anyway. If you want to use the field, you should probably
9412: define this macro to initialize it.
1.1.1.8 root 9413:
9414: @item NOTICE_UPDATE_CC (@var{exp}, @var{insn})
9415: A C compound statement to set the components of @code{cc_status}
9416: appropriately for an insn @var{insn} whose body is @var{exp}. It is
9417: this macro's responsibility to recognize insns that set the condition
9418: code as a byproduct of other activity as well as those that explicitly
9419: set @code{(cc0)}.
9420:
9421: If there are insn that do not set the condition code but do alter
9422: other machine registers, this macro must check to see whether they
9423: invalidate the expressions that the condition code is recorded as
9424: reflecting. For example, on the 68000, insns that store in address
9425: registers do not set the condition code, which means that usually
9426: @code{NOTICE_UPDATE_CC} can leave @code{cc_status} unaltered for such
9427: insns. But suppose that the previous insn set the condition code
9428: based on location @samp{a4@@(102)} and the current insn stores a new
9429: value in @samp{a4}. Although the condition code is not changed by
9430: this, it will no longer be true that it reflects the contents of
9431: @samp{a4@@(102)}. Therefore, @code{NOTICE_UPDATE_CC} must alter
9432: @code{cc_status} in this case to say that nothing is known about the
9433: condition code value.
9434:
9435: The definition of @code{NOTICE_UPDATE_CC} must be prepared to deal
9436: with the results of peephole optimization: insns whose patterns are
9437: @code{parallel} RTXs containing various @code{reg}, @code{mem} or
9438: constants which are just the operands. The RTL structure of these
9439: insns is not sufficient to indicate what the insns actually do. What
9440: @code{NOTICE_UPDATE_CC} should do when it sees one is just to run
9441: @code{CC_STATUS_INIT}.
9442: @end table
9443:
9444: @node Cross-compilation, Misc, Condition Code, Machine Macros
1.1.1.5 root 9445: @section Cross Compilation and Floating-Point Format
9446:
1.1.1.9 root 9447: While all modern machines use 2's complement representation for integers,
1.1.1.5 root 9448: there are a variety of representations for floating point numbers. This
9449: means that in a cross-compiler the representation of floating point numbers
9450: in the compiled program may be different from that used in the machine
9451: doing the compilation.
9452:
9453: Because different representation systems may offer different amounts of
9454: range and precision, the cross compiler cannot safely use the host
9455: machine's floating point arithmetic. Therefore, floating point constants
9456: must be represented in the target machine's format. This means that the
9457: cross compiler cannot use @code{atof} to parse a floating point constant;
9458: it must have its own special routine to use instead. Also, constant
9459: folding must emulate the target machine's arithmetic (or must not be done
9460: at all).
9461:
9462: The macros in the following table should be defined only if you are cross
9463: compiling between different floating point formats.
9464:
9465: Otherwise, don't define them. Then default definitions will be set up which
9466: use @code{double} as the data type, @code{==} to test for equality, etc.
9467:
9468: You don't need to worry about how many times you use an operand of any
9469: of these macros. The compiler never uses operands which have side effects.
9470:
9471: @table @code
9472: @item REAL_VALUE_TYPE
9473: A macro for the C data type to be used to hold a floating point value
9474: in the target machine's format. Typically this would be a
9475: @code{struct} containing an array of @code{int}.
9476:
9477: @item REAL_VALUES_EQUAL (@var{x}, @var{y})
9478: A macro for a C expression which compares for equality the two values,
9479: @var{x} and @var{y}, both of type @code{REAL_VALUE_TYPE}.
9480:
9481: @item REAL_VALUES_LESS (@var{x}, @var{y})
9482: A macro for a C expression which tests whether @var{x} is less than
9483: @var{y}, both values being of type @code{REAL_VALUE_TYPE} and
9484: interpreted as floating point numbers in the target machine's
9485: representation.
9486:
9487: @item REAL_VALUE_LDEXP (@var{x}, @var{scale})
9488: A macro for a C expression which performs the standard library
9489: function @code{ldexp}, but using the target machine's floating point
9490: representation. Both @var{x} and the value of the expression have
9491: type @code{REAL_VALUE_TYPE}. The second argument, @var{scale}, is an
9492: integer.
9493:
9494: @item REAL_VALUE_ATOF (@var{string})
9495: A macro for a C expression which converts @var{string}, an expression
9496: of type @code{char *}, into a floating point number in the target
9497: machine's representation. The value has type @code{REAL_VALUE_TYPE}.
9498: @end table
9499:
9500: Define the following additional macros if you want to make floating
9501: point constant folding work while cross compiling. If you don't
9502: define them, cross compilation is still possible, but constant folding
9503: will not happen for floating point values.
9504:
9505: @table @code
9506: @item REAL_ARITHMETIC (@var{output}, @var{code}, @var{x}, @var{y})
9507: A macro for a C statement which calculates an arithmetic operation of
9508: the two floating point values @var{x} and @var{y}, both of type
9509: @code{REAL_VALUE_TYPE} in the target machine's representation, to
9510: produce a result of the same type and representation which is stored
9511: in @var{output} (which will be a variable).
9512:
9513: The operation to be performed is specified by @var{code}, a tree code
9514: which will always be one of the following: @code{PLUS_EXPR},
9515: @code{MINUS_EXPR}, @code{MULT_EXPR}, @code{RDIV_EXPR},
9516: @code{MAX_EXPR}, @code{MIN_EXPR}.@refill
9517:
9518: The expansion of this macro is responsible for checking for overflow.
9519: If overflow happens, the macro expansion should execute the statement
9520: @code{return 0;}, which indicates the inability to perform the
9521: arithmetic operation requested.
9522:
9523: @item REAL_VALUE_NEGATE (@var{x})
9524: A macro for a C expression which returns the negative of the floating
9525: point value @var{x}. Both @var{x} and the value of the expression
9526: have type @code{REAL_VALUE_TYPE} and are in the target machine's
9527: floating point representation.
9528:
9529: There is no way for this macro to report overflow, since overflow
9530: can't happen in the negation operation.
9531:
9532: @item REAL_VALUE_TO_INT (@var{low}, @var{high}, @var{x})
9533: A macro for a C expression which converts a floating point value
9534: @var{x} into a double-precision integer which is then stored into
9535: @var{low} and @var{high}, two variables of type @var{int}.
9536:
9537: @item REAL_VALUE_FROM_INT (@var{x}, @var{low}, @var{high})
9538: A macro for a C expression which converts a double-precision integer
9539: found in @var{low} and @var{high}, two variables of type @var{int},
9540: into a floating point value which is then stored into @var{x}.
9541: @end table
9542:
1.1.1.8 root 9543: @node Misc, Assembler Format, Cross-compilation, Machine Macros
1.1 root 9544: @section Miscellaneous Parameters
9545:
9546: @table @code
9547: @item CASE_VECTOR_MODE
9548: An alias for a machine mode name. This is the machine mode that
9549: elements of a jump-table should have.
9550:
9551: @item CASE_VECTOR_PC_RELATIVE
9552: Define this macro if jump-tables should contain relative addresses.
9553:
9554: @item CASE_DROPS_THROUGH
9555: Define this if control falls through a @code{case} insn when the index
9556: value is out of range. This means the specified default-label is
9557: actually ignored by the @code{case} insn proper.
9558:
9559: @item IMPLICIT_FIX_EXPR
9560: An alias for a tree code that should be used by default for conversion
9561: of floating point values to fixed point. Normally,
9562: @code{FIX_ROUND_EXPR} is used.@refill
9563:
9564: @item FIXUNS_TRUNC_LIKE_FIX_TRUNC
9565: Define this macro if the same instructions that convert a floating
9566: point number to a signed fixed point number also convert validly to an
9567: unsigned one.
9568:
9569: @item EASY_DIV_EXPR
9570: An alias for a tree code that is the easiest kind of division to
9571: compile code for in the general case. It may be
9572: @code{TRUNC_DIV_EXPR}, @code{FLOOR_DIV_EXPR}, @code{CEIL_DIV_EXPR} or
9573: @code{ROUND_DIV_EXPR}. These four division operators differ in how
9574: they round the result to an integer. @code{EASY_DIV_EXPR} is used
9575: when it is permissible to use any of those kinds of division and the
9576: choice should be made on the basis of efficiency.@refill
9577:
9578: @item DEFAULT_SIGNED_CHAR
9579: An expression whose value is 1 or 0, according to whether the type
9580: @code{char} should be signed or unsigned by default. The user can
9581: always override this default with the options @samp{-fsigned-char}
9582: and @samp{-funsigned-char}.
9583:
9584: @item SCCS_DIRECTIVE
9585: Define this if the preprocessor should ignore @code{#sccs} directives
9586: and print no error message.
9587:
1.1.1.7 root 9588: @item HAVE_VPRINTF
9589: Define this if the library function @code{vprintf} is available on your
9590: system.
1.1 root 9591:
9592: @item MOVE_MAX
9593: The maximum number of bytes that a single instruction can move quickly
9594: from memory to memory.
9595:
9596: @item INT_TYPE_SIZE
9597: A C expression for the size in bits of the type @code{int} on the
1.1.1.8 root 9598: target machine. If you don't define this, the default is one word.
9599:
9600: @item SHORT_TYPE_SIZE
9601: A C expression for the size in bits of the type @code{short} on the
9602: target machine. If you don't define this, the default is half a word.
9603: (If this would be less than one storage unit, it is rounded up to one
9604: unit.)
9605:
9606: @item LONG_TYPE_SIZE
9607: A C expression for the size in bits of the type @code{long} on the
9608: target machine. If you don't define this, the default is one word.
9609:
9610: @item LONG_LONG_TYPE_SIZE
9611: A C expression for the size in bits of the type @code{long long} on the
9612: target machine. If you don't define this, the default is two
9613: words.
9614:
9615: @item CHAR_TYPE_SIZE
9616: A C expression for the size in bits of the type @code{char} on the
9617: target machine. If you don't define this, the default is one quarter
9618: of a word. (If this would be less than one storage unit, it is rounded up
9619: to one unit.)
9620:
9621: @item FLOAT_TYPE_SIZE
9622: A C expression for the size in bits of the type @code{float} on the
9623: target machine. If you don't define this, the default is one word.
9624:
9625: @item DOUBLE_TYPE_SIZE
9626: A C expression for the size in bits of the type @code{double} on the
9627: target machine. If you don't define this, the default is two
9628: words.
9629:
9630: @item LONG_DOUBLE_TYPE_SIZE
9631: A C expression for the size in bits of the type @code{long double} on
9632: the target machine. If you don't define this, the default is two
9633: words.
1.1 root 9634:
9635: @item SLOW_BYTE_ACCESS
9636: Define this macro as a C expression which is nonzero if accessing less
9637: than a word of memory (i.e. a @code{char} or a @code{short}) is slow
9638: (requires more than one instruction).
9639:
9640: @item SLOW_ZERO_EXTEND
9641: Define this macro if zero-extension (of a @code{char} or @code{short}
9642: to an @code{int}) can be done faster if the destination is a register
9643: that is known to be zero.
9644:
9645: If you define this macro, you must have instruction patterns that
9646: recognize RTL structures like this:
9647:
9648: @example
9649: (set (strict-low-part (subreg:QI (reg:SI @dots{}) 0)) @dots{})
9650: @end example
9651:
9652: @noindent
9653: and likewise for @code{HImode}.
9654:
9655: @item SHIFT_COUNT_TRUNCATED
9656: Define this macro if shift instructions ignore all but the lowest few
9657: bits of the shift count. It implies that a sign-extend or zero-extend
9658: instruction for the shift count can be omitted.
9659:
9660: @item TRULY_NOOP_TRUNCATION (@var{outprec}, @var{inprec})
9661: A C expression which is nonzero if on this machine it is safe to
9662: ``convert'' an integer of @var{inprec} bits to one of @var{outprec}
9663: bits (where @var{outprec} is smaller than @var{inprec}) by merely
9664: operating on it as if it had only @var{outprec} bits.
9665:
9666: On many machines, this expression can be 1.
9667:
9668: @item NO_FUNCTION_CSE
9669: Define this macro if it is as good or better to call a constant
9670: function address than to call an address kept in a register.
9671:
9672: @item PROMOTE_PROTOTYPES
9673: Define this macro if an argument declared as @code{char} or
9674: @code{short} in a prototype should actually be passed as an
9675: @code{int}. In addition to avoiding errors in certain cases of
9676: mismatch, it also makes for better code on certain machines.
9677:
9678: @item STORE_FLAG_VALUE
9679: A C expression for the value stored by a store-flag instruction
9680: (@code{s@var{cond}}) when the condition is true. This is usually 1 or
1.1.1.9 root 9681: -1; it is required to be an odd number or a negative number.
1.1 root 9682:
9683: Do not define @code{STORE_FLAG_VALUE} if the machine has no store-flag
9684: instructions.
9685:
9686: @item Pmode
9687: An alias for the machine mode for pointers. Normally the definition
9688: can be
9689:
9690: @example
9691: #define Pmode SImode
9692: @end example
9693:
9694: @item FUNCTION_MODE
9695: An alias for the machine mode used for memory references to functions
1.1.1.8 root 9696: being called, in @code{call} RTL expressions. On most machines this
1.1 root 9697: should be @code{QImode}.
9698:
9699: @item INSN_MACHINE_INFO
9700: This macro should expand into a C structure type to use for the
9701: machine-dependent info field specified with the optional last argument
1.1.1.8 root 9702: in @code{define_insn} and @code{define_peephole} patterns. For example,
9703: it might expand into @code{struct machine_info}; then it would be up
1.1 root 9704: to you to define this structure in the @file{tm.h} file.
9705:
9706: You do not need to define this macro if you do not write the optional
9707: last argument in any of the patterns in the machine description.
9708:
1.1.1.8 root 9709: @item DEFAULT_MACHINE_INFO
9710: This macro should expand into a C initializer to use to initialize
9711: the machine-dependent info for one insn pattern. It is used for patterns
9712: that do not specify the machine-dependent info.
9713:
9714: If you do not define this macro, zero is used.
9715:
1.1 root 9716: @item CONST_COSTS (@var{x}, @var{code})
9717: A part of a C @code{switch} statement that describes the relative
9718: costs of constant RTL expressions. It must contain @code{case} labels
1.1.1.8 root 9719: for expression codes @code{const_int}, @code{const}, @code{symbol_ref}, @code{label_ref}
9720: and @code{const_double}. Each case must ultimately reach a
1.1 root 9721: @code{return} statement to return the relative cost of the use of that
9722: kind of constant value in an expression. The cost may depend on the
9723: precise value of the constant, which is available for examination in
9724: @var{x}.
9725:
9726: @var{code} is the expression code---redundant, since it can be
9727: obtained with @code{GET_CODE (@var{x})}.
9728:
9729: @item DOLLARS_IN_IDENTIFIERS
9730: Define this to be nonzero if the character @samp{$} should be allowed
9731: by default in identifier names.
9732: @end table
9733:
1.1.1.8 root 9734: @node Assembler Format,, Misc, Machine Macros
1.1 root 9735: @section Output of Assembler Code
9736:
9737: @table @code
9738: @item ASM_SPEC
9739: A C string constant that tells the GNU CC driver program options to
9740: pass to the assembler. It can also specify how to translate options
9741: you give to GNU CC into options for GNU CC to pass to the assembler.
9742: See the file @file{tm-sun3.h} for an example of this.
9743:
9744: Do not define this macro if it does not need to do anything.
9745:
9746: @item LINK_SPEC
9747: A C string constant that tells the GNU CC driver program options to
9748: pass to the linker. It can also specify how to translate options you
9749: give to GNU CC into options for GNU CC to pass to the linker.
9750:
9751: Do not define this macro if it does not need to do anything.
9752:
9753: @item LIB_SPEC
9754: Another C string constant used much like @code{LINK_SPEC}. The difference
9755: between the two is that @code{LIBS_SPEC} is used at the end of the
9756: command given to the linker.
9757:
9758: If this macro is not defined, a default is provided that
9759: loads the standard C library from the usual place. See @file{gcc.c}.
9760:
1.1.1.12! root 9761: @item LIBG_SPEC
! 9762: Another C string constant used much like @code{LINK_SPEC}.
! 9763: This controls whether to link @file{libg.a} when debugging.
! 9764: Some systems expect this; others do not have any @file{libg.a}.
! 9765:
! 9766: If this macro is not defined, a default is provided that loads the
! 9767: @file{libg.a} provided @samp{-g} is specified. See @file{gcc.c}.
! 9768:
1.1 root 9769: @item STARTFILE_SPEC
9770: Another C string constant used much like @code{LINK_SPEC}. The
9771: difference between the two is that @code{STARTFILE_SPEC} is used at
9772: the very beginning of the command given to the linker.
9773:
9774: If this macro is not defined, a default is provided that loads the
9775: standard C startup file from the usual place. See @file{gcc.c}.
9776:
1.1.1.7 root 9777: @item STANDARD_EXEC_PREFIX
9778: Define this macro as a C string constant if you wish to override the
9779: standard choice of @file{/usr/local/lib/gcc-} as the default prefix to
9780: try when searching for the executable files of the compiler.
9781:
9782: The prefix specified by the @samp{-B} option, if any, is tried before
9783: the default prefix. After the default prefix, if the executable is
9784: not found that way, @file{/usr/lib/gcc-} is tried next; then the
9785: directories in your search path for shell commands are searched.
9786:
1.1.1.4 root 9787: @item STANDARD_STARTFILE_PREFIX
9788: Define this macro as a C string constant if you wish to override the
1.1.1.7 root 9789: standard choice of @file{/usr/local/lib/} as the default prefix to try
9790: when searching for startup files such as @file{crt0.o}.
9791:
9792: In this search, all the prefixes tried for executable files are tried
9793: first. Then comes the default startfile prefix specified by this
9794: macro, followed by the prefixes @file{/lib/} and @file{/usr/lib/} as
9795: last resorts.
1.1.1.4 root 9796:
1.1 root 9797: @item ASM_FILE_START (@var{stream})
9798: A C expression which outputs to the stdio stream @var{stream}
9799: some appropriate text to go at the start of an assembler file.
9800:
9801: Normally this macro is defined to output a line containing
9802: @samp{#NO_APP}, which is a comment that has no effect on most
9803: assemblers but tells the GNU assembler that it can save time by not
9804: checking for certain assembler constructs.
9805:
9806: On systems that use SDB, it is necessary to output certain commands;
9807: see @file{tm-attasm.h}.
9808:
1.1.1.8 root 9809: @item ASM_FILE_END (@var{stream})
9810: A C expression which outputs to the stdio stream @var{stream}
9811: some appropriate text to go at the end of an assembler file.
9812:
9813: If this macro is not defined, the default is to output nothing
9814: special at the end of the file. Most systems don't require any
9815: definition.
9816:
9817: On systems that use SDB, it is necessary to output certain commands;
9818: see @file{tm-attasm.h}.
9819:
9820: @item ASM_IDENTIFY_GCC (@var{file})
9821: A C statement to output assembler commands which will identify
9822: the object file as having been compiled with GNU CC (or another
9823: GNU compiler).
9824:
9825: If you don't define this macro, the string @samp{gcc_compiled.:}
9826: is output. This string is calculated to define a symbol which,
9827: on BSD systems, will never be defined for any other reason.
9828: GDB checks for the presence of this symbol when reading the
9829: symbol table of an executable.
9830:
9831: On non-BSD systems, you must arrange communication with GDB in
9832: some other fashion. If GDB is not used on your system, you can
9833: define this macro with an empty body.
9834:
1.1 root 9835: @item ASM_APP_ON
9836: A C string constant for text to be output before each @code{asm}
9837: statement or group of consecutive ones. Normally this is
9838: @code{"#APP"}, which is a comment that has no effect on most
9839: assemblers but tells the GNU assembler that it must check the lines
9840: that follow for all valid assembler constructs.
9841:
9842: @item ASM_APP_OFF
9843: A C string constant for text to be output after each @code{asm}
9844: statement or group of consecutive ones. Normally this is
9845: @code{"#NO_APP"}, which tells the GNU assembler to resume making the
9846: time-saving assumptions that are valid for ordinary compiler output.
9847:
9848: @item TEXT_SECTION_ASM_OP
9849: A C string constant for the assembler operation that should precede
9850: instructions and read-only data. Normally @code{".text"} is right.
9851:
9852: @item DATA_SECTION_ASM_OP
9853: A C string constant for the assembler operation to identify the
9854: following data as writable initialized data. Normally @code{".data"}
9855: is right.
9856:
1.1.1.8 root 9857: @item EXTRA_SECTIONS
9858: A list of names for sections other than the standard two, which are
9859: @code{in_text} and @code{in_data}. You need not define this macro
9860: on a system with no other sections (that GCC needs to use).
9861:
9862: @item EXTRA_SECTION_FUNCTIONS
9863: One or more functions to be defined in @file{varasm.c}. These
9864: functions should do jobs analogous to those of @code{text_section} and
9865: @code{data_section}, for your additional sections. Do not define this
9866: macro if you do not define @code{EXTRA_SECTIONS}.
9867:
9868: @item SELECT_SECTION (@var{exp})
9869: A C statement or statements to switch to the appropriate section for
9870: output of @var{exp}. You can assume that @var{exp} is either a
9871: @code{VAR_DECL} node or a constant of some sort. Select the section
9872: by calling @code{text_section} or one of the alternatives for other
9873: sections.
9874:
9875: Do not define this macro if you use only the standard two sections
9876: and put all read-only variables and constants in the text section.
9877:
9878: @item SELECT_RTX_SECTION (@var{mode}, @var{rtx})
9879: A C statement or statements to switch to the appropriate section for
9880: output of @var{rtx} in mode @var{mode}. You can assume that @var{rtx}
9881: is some kind of constant in RTL. The argument @var{mode} is redundant
9882: except in the case of a @code{const_int} rtx. Select the section by
9883: calling @code{text_section} or one of the alternatives for other
9884: sections.
9885:
9886: Do not define this macro if you use only the standard two sections and
9887: put all constants in the text section.
9888:
1.1 root 9889: @item REGISTER_NAMES
9890: A C initializer containing the assembler's names for the machine
9891: registers, each one as a C string constant. This is what translates
9892: register numbers in the compiler into assembler language.
9893:
9894: @item DBX_REGISTER_NUMBER (@var{regno})
9895: A C expression that returns the DBX register number for the compiler
9896: register number @var{regno}. In simple cases, the value of this
9897: expression may be @var{regno} itself. But sometimes there are some
9898: registers that the compiler knows about and DBX does not, or vice
9899: versa. In such cases, some register may need to have one number in
9900: the compiler and another for DBX.
9901:
9902: @item DBX_DEBUGGING_INFO
9903: Define this macro if GNU CC should produce debugging output for DBX
9904: in response to the @samp{-g} option.
9905:
9906: @item SDB_DEBUGGING_INFO
9907: Define this macro if GNU CC should produce debugging output for SDB
9908: in response to the @samp{-g} option.
9909:
9910: @item PUT_SDB_@var{op}
9911: Define these macros to override the assembler syntax for the special
9912: SDB assembler directives. See @file{sdbout.c} for a list of these
9913: macros and their arguments. If the standard syntax is used, you need
9914: not define them yourself.
9915:
9916: @item SDB_GENERATE_FAKE
9917: Define this macro to override the usual method of constructing a dummy
9918: name for anonymous structure and union types. See @file{sdbout.c} for
1.1.1.9 root 9919: more information.
1.1 root 9920:
9921: @item DBX_NO_XREFS
9922: Define this macro if DBX on your system does not support the construct
9923: @samp{xs@var{tagname}}. On some systems, this construct is used to
9924: describe a forward reference to a structure named @var{tagname}.
9925: On other systems, this construct is not supported at all.
9926:
9927: @item DBX_CONTIN_LENGTH
9928: A symbol name in DBX-format debugging information is normally
9929: continued (split into two separate @code{.stabs} directives) when it
9930: exceeds a certain length (by default, 80 characters). On some
9931: operating systems, DBX requires this splitting; on others, splitting
9932: must not be done. You can inhibit splitting by defining this macro
9933: with the value zero. You can override the default splitting-length by
9934: defining this macro as an expression for the length you desire.
9935:
9936: @item DBX_CONTIN_CHAR
9937: Normally continuation is indicated by adding a @samp{\} character to
9938: the end of a @code{.stabs} string when a continuation follows. To use
9939: a different character instead, define this macro as a character
9940: constant for the character you want to use. Do not define this macro
9941: if backslash is correct for your system.
9942:
1.1.1.8 root 9943: @item DBX_STATIC_STAB_DATA_SECTION
9944: Define this macro if it is necessary to go to the data section before
9945: outputting the @samp{.stabs} pseudo-op for a non-global static
9946: variable.
9947:
1.1 root 9948: @item ASM_OUTPUT_LABEL (@var{stream}, @var{name})
9949: A C statement (sans semicolon) to output to the stdio stream
1.1.1.8 root 9950: @var{stream} the assembler definition of a label named @var{name}.
9951: Use the expression @code{assemble_name (@var{stream}, @var{name})} to
9952: output the name itself; before and after that, output the additional
1.1 root 9953: assembler syntax for defining the name, and a newline.
9954:
9955: @item ASM_DECLARE_FUNCTION_NAME (@var{stream}, @var{name}, @var{decl})
9956: A C statement (sans semicolon) to output to the stdio stream
9957: @var{stream} any text necessary for declaring the name @var{name} of a
9958: function which is being defined. This macro is responsible for
9959: outputting the label definition (perhaps using
9960: @code{ASM_OUTPUT_LABEL}). The argument @var{decl} is the
9961: @code{FUNCTION_DECL} tree node representing the function.
9962:
9963: If this macro is not defined, then the function name is defined in the
9964: usual manner as a label (by means of @code{ASM_OUTPUT_LABEL}).
9965:
9966: @item ASM_GLOBALIZE_LABEL (@var{stream}, @var{name})
9967: A C statement (sans semicolon) to output to the stdio stream
9968: @var{stream} some commands that will make the label @var{name} global;
9969: that is, available for reference from other files. Use the expression
9970: @code{assemble_name (@var{stream}, @var{name})} to output the name
9971: itself; before and after that, output the additional assembler syntax
9972: for making that name global, and a newline.
9973:
1.1.1.8 root 9974: @item ASM_OUTPUT_EXTERNAL (@var{stream}, @var{decl}, @var{name})
1.1 root 9975: A C statement (sans semicolon) to output to the stdio stream
9976: @var{stream} any text necessary for declaring the name of an external
9977: symbol named @var{name} which is referenced in this compilation but
9978: not defined. The value of @var{decl} is the tree node for the
9979: declaration.
9980:
9981: This macro need not be defined if it does not need to output anything.
9982: The GNU assembler and most Unix assemblers don't require anything.
9983:
9984: @item ASM_OUTPUT_LABELREF (@var{stream}, @var{name})
1.1.1.8 root 9985: A C statement to output to the stdio stream @var{stream} a reference
9986: in assembler syntax to a label named @var{name}. The character
9987: @samp{_} should be added to the front of the name, if that is
9988: customary on your operating system, as it is in most Berkeley Unix
9989: systems. This macro is used in @code{assemble_name}.
1.1 root 9990:
9991: @item ASM_GENERATE_INTERNAL_LABEL (@var{string}, @var{prefix}, @var{num})
1.1.1.8 root 9992: A C statement to store into the string @var{string} a label whose name
9993: is made from the string @var{prefix} and the number @var{num}.
1.1 root 9994:
9995: This string, when output subsequently by @code{ASM_OUTPUT_LABELREF},
9996: should produce the same output that @code{ASM_OUTPUT_INTERNAL_LABEL}
9997: would produce with the same @var{prefix} and @var{num}.
9998:
9999: @item ASM_OUTPUT_INTERNAL_LABEL (@var{stream}, @var{prefix}, @var{num})
10000: A C statement to output to the stdio stream @var{stream} a label whose
10001: name is made from the string @var{prefix} and the number @var{num}.
10002: These labels are used for internal purposes, and there is no reason
10003: for them to appear in the symbol table of the object file. On many
10004: systems, the letter @samp{L} at the beginning of a label has this
10005: effect. The usual definition of this macro is as follows:
10006:
10007: @example
10008: fprintf (@var{stream}, "L%s%d:\n", @var{prefix}, @var{num})
10009: @end example
10010:
10011: @item ASM_OUTPUT_CASE_LABEL (@var{stream}, @var{prefix}, @var{num}, @var{table})
10012: Define this if the label before a jump-table needs to be output
10013: specially. The first three arguments are the same as for
10014: @code{ASM_OUTPUT_INTERNAL_LABEL}; the fourth argument is the
1.1.1.8 root 10015: jump-table which follows (a @code{jump_insn} containing an
10016: @code{addr_vec} or @code{addr_diff_vec}).
1.1 root 10017:
10018: This feature is used on system V to output a @code{swbeg} statement
10019: for the table.
10020:
10021: If this macro is not defined, these labels are output with
10022: @code{ASM_OUTPUT_INTERNAL_LABEL}.
10023:
10024: @item ASM_OUTPUT_CASE_END (@var{stream}, @var{num}, @var{table})
1.1.1.8 root 10025: Define this if something special must be output at the end of a
10026: jump-table. The definition should be a C statement to be executed
10027: after the assembler code for the table is written. It should write
10028: the appropriate code to stdio stream @var{stream}. The argument
10029: @var{table} is the jump-table insn, and @var{num} is the label-number
10030: of the preceding label.
1.1 root 10031:
10032: If this macro is not defined, nothing special is output at the end of
10033: the jump-table.
10034:
1.1.1.4 root 10035: @item ASM_OUTPUT_ALIGN_CODE (@var{file})
10036: A C expression to output text to align the location counter in the way
10037: that is desirable at a point in the code that is reached only by
10038: jumping.
10039:
10040: This macro need not be defined if you don't want any special alignment
10041: to be done at such a time. Most machine descriptions do not currently
10042: define the macro.
10043:
1.1 root 10044: @item ASM_FORMAT_PRIVATE_NAME (@var{outvar}, @var{name}, @var{number})
10045: A C expression to assign to @var{outvar} (which is a variable of type
10046: @code{char *}) a newly allocated string made from the string
10047: @var{name} and the number @var{number}, with some suitable punctuation
10048: added. Use @code{alloca} to get space for the string.
10049:
10050: This string will be used as the argument to @code{ASM_OUTPUT_LABELREF}
10051: to produce an assembler label for an internal static variable whose
10052: name is @var{name}. Therefore, the string must be such as to result
10053: in valid assembler code. The argument @var{number} is different each
10054: time this macro is executed; it prevents conflicts between
10055: similarly-named internal static variables in different scopes.
10056:
10057: Ideally this string should not be a valid C identifier, to prevent any
10058: conflict with the user's own symbols. Most assemblers allow periods
10059: or percent signs in assembler symbols; putting at least one of these
10060: between the name and the number will suffice.
10061:
10062: @item ASM_OUTPUT_REG_PUSH (@var{stream}, @var{regno})
10063: A C expression to output to @var{stream} some assembler code
10064: which will push hard register number @var{regno} onto the stack.
10065: The code need not be optimal, since this macro is used only when
10066: profiling.
10067:
10068: @item ASM_OUTPUT_REG_POP (@var{stream}, @var{regno})
10069: A C expression to output to @var{stream} some assembler code
10070: which will pop hard register number @var{regno} off of the stack.
10071: The code need not be optimal, since this macro is used only when
10072: profiling.
10073:
10074: @item ASM_OUTPUT_ADDR_DIFF_ELT (@var{stream}, @var{value}, @var{rel})
10075: This macro should be provided on machines where the addresses
10076: in a dispatch table are relative to the table's own address.
10077:
10078: The definition should be a C statement to output to the stdio stream
10079: @var{stream} an assembler pseudo-instruction to generate a difference
10080: between two labels. @var{value} and @var{rel} are the numbers of two
10081: internal labels. The definitions of these labels are output using
10082: @code{ASM_OUTPUT_INTERNAL_LABEL}, and they must be printed in the same
10083: way here. For example,
10084:
10085: @example
10086: fprintf (@var{stream}, "\t.word L%d-L%d\n",
10087: @var{value}, @var{rel})
10088: @end example
10089:
10090: @item ASM_OUTPUT_ADDR_VEC_ELT (@var{stream}, @var{value})
10091: This macro should be provided on machines where the addresses
10092: in a dispatch table are absolute.
10093:
10094: The definition should be a C statement to output to the stdio stream
10095: @var{stream} an assembler pseudo-instruction to generate a reference to
10096: a label. @var{value} is the number of an internal label whose
10097: definition is output using @code{ASM_OUTPUT_INTERNAL_LABEL}.
10098: For example,
10099:
10100: @example
10101: fprintf (@var{stream}, "\t.word L%d\n", @var{value})
10102: @end example
10103:
10104: @item ASM_OUTPUT_DOUBLE (@var{stream}, @var{value})
10105: A C statement to output to the stdio stream @var{stream} an assembler
10106: instruction to assemble a @code{double} constant whose value is
10107: @var{value}. @var{value} will be a C expression of type
10108: @code{double}.
10109:
10110: @item ASM_OUTPUT_FLOAT (@var{stream}, @var{value})
10111: A C statement to output to the stdio stream @var{stream} an assembler
10112: instruction to assemble a @code{float} constant whose value is
10113: @var{value}. @var{value} will be a C expression of type @code{float}.
10114:
10115: @item ASM_OUTPUT_INT (@var{stream}, @var{exp})
10116: @itemx ASM_OUTPUT_SHORT (@var{stream}, @var{exp})
10117: @itemx ASM_OUTPUT_CHAR (@var{stream}, @var{exp})
10118: A C statement to output to the stdio stream @var{stream} an assembler
10119: instruction to assemble a @code{int}, @code{short} or @code{char}
1.1.1.10 root 10120: constant whose value is @var{value}. The argument @var{exp} will be an
10121: RTL expression which represents a constant value. Use
10122: @samp{output_addr_const (@var{stream}, @var{exp})} to output this value
10123: as an assembler expression.@refill
1.1 root 10124:
1.1.1.8 root 10125: @item ASM_OUTPUT_DOUBLE_INT (@var{stream}, @var{exp})
10126: A C statement to output to the stdio stream @var{stream} an assembler
10127: instruction to assemble a @code{long long} constant whose value is
10128: @var{exp}. The argument @var{exp} will be an RTL expression which
10129: represents a constant value. It may be a @code{const_double} RTX,
10130: or it may be an ordinary single-precision constant. In the latter
10131: case, you should zero-extend it.
10132:
1.1 root 10133: @item ASM_OUTPUT_BYTE (@var{stream}, @var{value})
10134: A C statement to output to the stdio stream @var{stream} an assembler
10135: instruction to assemble a single byte containing the number @var{value}.
10136:
10137: @item ASM_OUTPUT_ASCII (@var{stream}, @var{ptr}, @var{len})
10138: A C statement to output to the stdio stream @var{stream} an assembler
10139: instruction to assemble a string constant containing the @var{len}
10140: bytes at @var{ptr}. @var{ptr} will be a C expression of type
10141: @code{char *} and @var{len} a C expression of type @code{int}.
10142:
10143: If the assembler has a @code{.ascii} pseudo-op as found in the
10144: Berkeley Unix assembler, do not define the macro
10145: @code{ASM_OUTPUT_ASCII}.
10146:
10147: @item ASM_OUTPUT_SKIP (@var{stream}, @var{nbytes})
10148: A C statement to output to the stdio stream @var{stream} an assembler
10149: instruction to advance the location counter by @var{nbytes} bytes.
10150: @var{nbytes} will be a C expression of type @code{int}.
10151:
10152: @item ASM_OUTPUT_ALIGN (@var{stream}, @var{power})
10153: A C statement to output to the stdio stream @var{stream} an assembler
10154: instruction to advance the location counter to a multiple of 2 to the
10155: @var{power} bytes. @var{power} will be a C expression of type @code{int}.
10156:
1.1.1.7 root 10157: @item ASM_OUTPUT_COMMON (@var{stream}, @var{name}, @var{size}, @var{rounded})
1.1 root 10158: A C statement (sans semicolon) to output to the stdio stream
1.1.1.7 root 10159: @var{stream} the assembler definition of a common-label named
10160: @var{name} whose size is @var{size} bytes. The variable @var{rounded}
10161: is the size rounded up to whatever alignment the caller wants.
10162:
10163: Use the expression @code{assemble_name (@var{stream}, @var{name})} to
10164: output the name itself; before and after that, output the additional
10165: assembler syntax for defining the name, and a newline.
1.1 root 10166:
10167: This macro controls how the assembler definitions of uninitialized
10168: global variables are output.
10169:
1.1.1.7 root 10170: @item ASM_OUTPUT_LOCAL (@var{stream}, @var{name}, @var{size}, @var{rounded})
1.1 root 10171: A C statement (sans semicolon) to output to the stdio stream
10172: @var{stream} the assembler definition of a local-common-label named
1.1.1.7 root 10173: @var{name} whose size is @var{size} bytes. The variable @var{rounded}
10174: is the size rounded up to whatever alignment the caller wants.
10175:
10176: Use the expression @code{assemble_name (@var{stream}, @var{name})} to
10177: output the name itself; before and after that, output the additional
10178: assembler syntax for defining the name, and a newline.
1.1 root 10179:
10180: This macro controls how the assembler definitions of uninitialized
10181: static variables are output.
10182:
1.1.1.8 root 10183: @item ASM_OUTPUT_SOURCE_FILENAME (@var{stream}, @var{name})
10184: A C statment to output DBX or SDB debugging information which indicates
10185: that filename @var{name} is the current source file to the stdio stream
10186: @var{stream}.
10187:
10188: This macro need not be defined if the standard form of debugging
10189: information for the debugger in use is appropriate.
10190:
1.1 root 10191: @item ASM_OUTPUT_SOURCE_LINE (@var{stream}, @var{line})
10192: A C statment to output DBX or SDB debugging information before code
10193: for line number @var{line} of the current source file to the
10194: stdio stream @var{stream}.
10195:
10196: This macro need not be defined if the standard form of debugging
10197: information for the debugger in use is appropriate.
10198:
10199: @item ASM_OUTPUT_IDENT (@var{stream}, @var{string})
10200: A C statement to output something to the assembler file to handle a
10201: @samp{#ident} directive containing the text @var{string}. If this
1.1.1.7 root 10202: macro is not defined, nothing is output for a @samp{#ident} directive.
1.1 root 10203:
10204: @item TARGET_BELL
10205: A C constant expression for the integer value for escape sequence
10206: @samp{\a}.
10207:
10208: @item TARGET_BS
10209: @itemx TARGET_TAB
10210: @itemx TARGET_NEWLINE
10211: C constant expressions for the integer values for escape sequences
10212: @samp{\b}, @samp{\t} and @samp{\n}.
10213:
10214: @item TARGET_VT
10215: @itemx TARGET_FF
10216: @itemx TARGET_CR
10217: C constant expressions for the integer values for escape sequences
10218: @samp{\v}, @samp{\f} and @samp{\r}.
10219:
10220: @item ASM_OUTPUT_OPCODE (@var{stream}, @var{ptr})
10221: Define this macro if you are using an unusual assembler that
10222: requires different names for the machine instructions.
10223:
10224: The definition is a C statement or statements which output an
10225: assembler instruction opcode to the stdio stream @var{stream}. The
10226: macro-operand @var{ptr} is a variable of type @code{char *} which
10227: points to the opcode name in its ``internal'' form---the form that is
10228: written in the machine description. The definition should output the
10229: opcode name to @var{stream}, performing any translation you desire, and
10230: increment the variable @var{ptr} to point at the end of the opcode
10231: so that it will not be output twice.
10232:
10233: In fact, your macro definition may process less than the entire opcode
10234: name, or more than the opcode name; but if you want to process text
10235: that includes @samp{%}-sequences to substitute operands, you must take
10236: care of the substitution yourself. Just be sure to increment
10237: @var{ptr} over whatever text should not be output normally.
10238:
1.1.1.8 root 10239: If you need to look at the operand values, they can be found as the
10240: elements of @code{recog_operand}.
10241:
1.1 root 10242: If the macro definition does nothing, the instruction is output
10243: in the usual way.
10244:
10245: @item FINAL_PRESCAN_INSN (@var{insn}, @var{opvec}, @var{noperands})
10246: If defined, a C statement to be executed just prior to the output of
10247: assembler code for @var{insn}, to modify the extracted operands so
10248: they will be output differently.
10249:
10250: Here the argument @var{opvec} is the vector containing the operands
10251: extracted from @var{insn}, and @var{noperands} is the number of
10252: elements of the vector which contain meaningful data for this insn.
10253: The contents of this vector are what will be used to convert the insn
10254: template into assembler code, so you can change the assembler output
10255: by changing the contents of the vector.
10256:
10257: This macro is useful when various assembler syntaxes share a single
10258: file of instruction patterns; by defining this macro differently, you
10259: can cause a large class of instructions to be output differently (such
10260: as with rearranged operands). Naturally, variations in assembler
10261: syntax affecting individual insn patterns ought to be handled by
10262: writing conditional output routines in those patterns.
10263:
10264: If this macro is not defined, it is equivalent to a null statement.
10265:
10266: @item PRINT_OPERAND (@var{stream}, @var{x}, @var{code})
10267: A C compound statement to output to stdio stream @var{stream} the
10268: assembler syntax for an instruction operand @var{x}. @var{x} is an
10269: RTL expression.
10270:
10271: @var{code} is a value that can be used to specify one of several ways
10272: of printing the operand. It is used when identical operands must be
10273: printed differently depending on the context. @var{code} comes from
10274: the @samp{%} specification that was used to request printing of the
10275: operand. If the specification was just @samp{%@var{digit}} then
10276: @var{code} is 0; if the specification was @samp{%@var{ltr}
10277: @var{digit}} then @var{code} is the ASCII code for @var{ltr}.
10278:
10279: If @var{x} is a register, this macro should print the register's name.
10280: The names can be found in an array @code{reg_names} whose type is
10281: @code{char *[]}. @code{reg_names} is initialized from
10282: @code{REGISTER_NAMES}.
10283:
10284: When the machine description has a specification @samp{%@var{punct}}
10285: (a @samp{%} followed by a punctuation character), this macro is called
10286: with a null pointer for @var{x} and the punctuation character for
10287: @var{code}.
10288:
1.1.1.8 root 10289: @item PRINT_OPERAND_PUNCT_VALID_P (@var{code})
10290: A C expression which evaluates to true if @var{code} is a valid
10291: punctuation character for use in the @code{PRINT_OPERAND} macro. If
10292: @code{PRINT_OPERAND_PUNCT_VALID_P} is not defined, it means that no
10293: punctuation characters (except for the standard one, @samp{%}) are used
10294: in this way.
10295:
1.1 root 10296: @item PRINT_OPERAND_ADDRESS (@var{stream}, @var{x})
10297: A C compound statement to output to stdio stream @var{stream} the
10298: assembler syntax for an instruction operand that is a memory reference
10299: whose address is @var{x}. @var{x} is an RTL expression.
10300:
10301: @item ASM_OPEN_PAREN
10302: @itemx ASM_CLOSE_PAREN
10303: These macros are defined as C string constant, describing the syntax
10304: in the assembler for grouping arithmetic expressions. The following
10305: definitions are correct for most assemblers:
10306:
10307: @example
10308: #define ASM_OPEN_PAREN "("
10309: #define ASM_CLOSE_PAREN ")"
10310: @end example
10311: @end table
10312:
10313: @node Config,, Machine Macros, Top
10314: @chapter The Configuration File
10315:
1.1.1.3 root 10316: The configuration file @file{xm-@var{machine}.h} contains macro definitions
10317: that describe the machine and system on which the compiler is running.
10318: Most of the values in it are actually the same on all machines that GNU CC
10319: runs on, so large parts of all configuration files are identical. But
1.1 root 10320: there are some macros that vary:
10321:
10322: @table @code
10323: @item FAILURE_EXIT_CODE
10324: A C expression for the status code to be returned when the compiler
10325: exits after serious errors.
10326:
10327: @item SUCCESS_EXIT_CODE
10328: A C expression for the status code to be returned when the compiler
10329: exits without serious errors.
1.1.1.10 root 10330:
10331: @item USE_C_ALLOCA
10332: Define this macro to indicate that the compiler is running with the
10333: @code{alloca} implemented in C. This version of @code{alloca} can be
10334: found in the file @file{alloca.c}; to use it, you must also alter the
10335: @file{Makefile} variable @code{ALLOCA}.
10336:
10337: This macro, unlike most, describes the machine that the compiler is
10338: running on, rather than the one the compiler is compiling for.
10339: Therefore, it should be set in the @file{xm-@var{machine}.h} file
10340: rather than in the @file{tm-@var{machine}.h} file.
10341:
10342: If you do define this macro, you should probably do it as follows:
10343:
10344: @example
10345: #ifndef __GNUC__
10346: #define USE_C_ALLOCA
10347: #else
10348: #define alloca __builtin_alloca
10349: #endif
10350: @end example
10351:
10352: @noindent
10353: so that when the compiler is compiled with GNU CC it uses the more
10354: efficient built-in @code{alloca} function.
1.1 root 10355: @end table
10356:
1.1.1.3 root 10357: In addition, configuration files for system V define @code{bcopy},
10358: @code{bzero} and @code{bcmp} as aliases. Some files define @code{alloca}
10359: as a macro when compiled with GNU CC, in order to take advantage of the
10360: benefit of GNU CC's built-in @code{alloca}.
10361:
1.1 root 10362: @contents
10363: @bye
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.