home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / msdos / djgpp / docs / gcc / gcc.i9 < prev    next >
Encoding:
GNU Info File  |  1993-05-29  |  46.6 KB  |  1,031 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.54 from the input
  2. file gcc.texi.
  3.  
  4.    This file documents the use and the internals of the GNU compiler.
  5.  
  6.    Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the sections entitled "GNU General Public License" and "Protect
  15. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  16. original, and provided that the entire resulting derived work is
  17. distributed under the terms of a permission notice identical to this
  18. one.
  19.  
  20.    Permission is granted to copy and distribute translations of this
  21. manual into another language, under the above conditions for modified
  22. versions, except that the sections entitled "GNU General Public
  23. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  24. permission notice, may be included in translations approved by the Free
  25. Software Foundation instead of in the original English.
  26.  
  27. 
  28. File: gcc.info,  Node: Include Files and VMS,  Next: Global Declarations,  Up: VMS
  29.  
  30. Include Files and VMS
  31. =====================
  32.  
  33.    Due to the differences between the filesystems of Unix and VMS, GNU
  34. CC attempts to translate file names in `#include' into names that VMS
  35. will understand.  The basic strategy is to prepend a prefix to the
  36. specification of the include file, convert the whole filename to a VMS
  37. filename, and then try to open the file.  GNU CC tries various prefixes
  38. one by one until one of them succeeds:
  39.  
  40.   1. The first prefix is the `GNU_CC_INCLUDE:' logical name: this is
  41.      where GNU C header files are traditionally stored.  If you wish to
  42.      store header files in non-standard locations, then you can assign
  43.      the logical `GNU_CC_INCLUDE' to be a search list, where each
  44.      element of the list is suitable for use with a rooted logical.
  45.  
  46.   2. The next prefix tried is `SYS$SYSROOT:[SYSLIB.]'.  This is where
  47.      VAX-C header files are traditionally stored.
  48.  
  49.   3. If the include file specification by itself is a valid VMS
  50.      filename, the preprocessor then uses this name with no prefix in
  51.      an attempt to open the include file.
  52.  
  53.   4. If the file specification is not a valid VMS filename (i.e. does
  54.      not contain a device or a directory specifier, and contains a `/'
  55.      character), the preprocessor tries to convert it from Unix syntax
  56.      to VMS syntax.
  57.  
  58.      Conversion works like this: the first directory name becomes a
  59.      device, and the rest of the directories are converted into
  60.      VMS-format directory names.  For example, the name `X11/foobar.h'
  61.      is translated to `X11:[000000]foobar.h' or `X11:foobar.h',
  62.      whichever one can be opened.  This strategy allows you to assign a
  63.      logical name to point to the actual location of the header files.
  64.  
  65.   5. If none of these strategies succeeds, the `#include' fails.
  66.  
  67.    Include directives of the form:
  68.  
  69.      #include foobar
  70.  
  71. are a common source of incompatibility between VAX-C and GNU CC.  VAX-C
  72. treats this much like a standard `#include <foobar.h>' directive.  That
  73. is incompatible with the ANSI C behavior implemented by GNU CC: to
  74. expand the name `foobar' as a macro.  Macro expansion should eventually
  75. yield one of the two standard formats for `#include':
  76.  
  77.      #include "FILE"
  78.      #include <FILE>
  79.  
  80.    If you have this problem, the best solution is to modify the source
  81. to convert the `#include' directives to one of the two standard forms.
  82. That will work with either compiler.  If you want a quick and dirty fix,
  83. define the file names as macros with the proper expansion, like this:
  84.  
  85.      #define stdio <stdio.h>
  86.  
  87. This will work, as long as the name doesn't conflict with anything else
  88. in the program.
  89.  
  90.    Another source of incompatibility is that VAX-C assumes that:
  91.  
  92.      #include "foobar"
  93.  
  94. is actually asking for the file `foobar.h'.  GNU CC does not make this
  95. assumption, and instead takes what you ask for literally; it tries to
  96. read the file `foobar'.  The best way to avoid this problem is to
  97. always specify the desired file extension in your include directives.
  98.  
  99.    GNU CC for VMS is distributed with a set of include files that is
  100. sufficient to compile most general purpose programs.  Even though the
  101. GNU CC distribution does not contain header files to define constants
  102. and structures for some VMS system-specific functions, there is no
  103. reason why you cannot use GNU CC with any of these functions.  You first
  104. may have to generate or create header files, either by using the public
  105. domain utility `UNSDL' (which can be found on a DECUS tape), or by
  106. extracting the relevant modules from one of the system macro libraries,
  107. and using an editor to construct a C header file.
  108.  
  109.    A `#include' file name cannot contain a DECNET node name.  The
  110. preprocessor reports an I/O error if you attempt to use a node name,
  111. whether explicitly, or implicitly via a logical name.
  112.  
  113. 
  114. File: gcc.info,  Node: Global Declarations,  Next: VMS Misc,  Prev: Include Files and VMS,  Up: VMS
  115.  
  116. Global Declarations and VMS
  117. ===========================
  118.  
  119.    GNU CC does not provide the `globalref', `globaldef' and
  120. `globalvalue' keywords of VAX-C.  You can get the same effect with an
  121. obscure feature of GAS, the GNU assembler.  (This requires GAS version
  122. 1.39 or later.)  The following macros allow you to use this feature in
  123. a fairly natural way:
  124.  
  125.      #ifdef __GNUC__
  126.      #define GLOBALREF(TYPE,NAME)                      \
  127.        TYPE NAME                                       \
  128.        asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME)
  129.      #define GLOBALDEF(TYPE,NAME,VALUE)                \
  130.        TYPE NAME                                       \
  131.        asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME) \
  132.          = VALUE
  133.      #define GLOBALVALUEREF(TYPE,NAME)                 \
  134.        const TYPE NAME[1]                              \
  135.        asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME)
  136.      #define GLOBALVALUEDEF(TYPE,NAME,VALUE)           \
  137.        const TYPE NAME[1]                              \
  138.        asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME)  \
  139.          = {VALUE}
  140.      #else
  141.      #define GLOBALREF(TYPE,NAME) \
  142.        globalref TYPE NAME
  143.      #define GLOBALDEF(TYPE,NAME,VALUE) \
  144.        globaldef TYPE NAME = VALUE
  145.      #define GLOBALVALUEDEF(TYPE,NAME,VALUE) \
  146.        globalvalue TYPE NAME = VALUE
  147.      #define GLOBALVALUEREF(TYPE,NAME) \
  148.        globalvalue TYPE NAME
  149.      #endif
  150.  
  151. (The `_$$PsectAttributes_GLOBALSYMBOL' prefix at the start of the name
  152. is removed by the assembler, after it has modified the attributes of
  153. the symbol).  These macros are provided in the VMS binaries
  154. distribution in a header file `GNU_HACKS.H'.  An example of the usage
  155. is:
  156.  
  157.      GLOBALREF (int, ijk);
  158.      GLOBALDEF (int, jkl, 0);
  159.  
  160.    The macros `GLOBALREF' and `GLOBALDEF' cannot be used
  161. straightforwardly for arrays, since there is no way to insert the array
  162. dimension into the declaration at the right place.  However, you can
  163. declare an array with these macros if you first define a typedef for the
  164. array type, like this:
  165.  
  166.      typedef int intvector[10];
  167.      GLOBALREF (intvector, foo);
  168.  
  169.    Array and structure initializers will also break the macros; you can
  170. define the initializer to be a macro of its own, or you can expand the
  171. `GLOBALDEF' macro by hand.  You may find a case where you wish to use
  172. the `GLOBALDEF' macro with a large array, but you are not interested in
  173. explicitly initializing each element of the array.  In such cases you
  174. can use an initializer like: `{0,}', which will initialize the entire
  175. array to `0'.
  176.  
  177.    A shortcoming of this implementation is that a variable declared with
  178. `GLOBALVALUEREF' or `GLOBALVALUEDEF' is always an array.  For example,
  179. the declaration:
  180.  
  181.      GLOBALVALUEREF(int, ijk);
  182.  
  183. declares the variable `ijk' as an array of type `int [1]'.  This is
  184. done because a globalvalue is actually a constant; its "value" is what
  185. the linker would normally consider an address.  That is not how an
  186. integer value works in C, but it is how an array works.  So treating
  187. the symbol as an array name gives consistent results--with the
  188. exception that the value seems to have the wrong type.  *Don't try to
  189. access an element of the array.*  It doesn't have any elements.  The
  190. array "address" may not be the address of actual storage.
  191.  
  192.    The fact that the symbol is an array may lead to warnings where the
  193. variable is used.  Insert type casts to avoid the warnings.  Here is an
  194. example; it takes advantage of the ANSI C feature allowing macros that
  195. expand to use the same name as the macro itself.
  196.  
  197.      GLOBALVALUEREF (int, ss$_normal);
  198.      GLOBALVALUEDEF (int, xyzzy,123);
  199.      #ifdef __GNUC__
  200.      #define ss$_normal ((int) ss$_normal)
  201.      #define xyzzy ((int) xyzzy)
  202.      #endif
  203.  
  204.    Don't use `globaldef' or `globalref' with a variable whose type is
  205. an enumeration type; this is not implemented.  Instead, make the
  206. variable an integer, and use a `globalvaluedef' for each of the
  207. enumeration values.  An example of this would be:
  208.  
  209.      #ifdef __GNUC__
  210.      GLOBALDEF (int, color, 0);
  211.      GLOBALVALUEDEF (int, RED, 0);
  212.      GLOBALVALUEDEF (int, BLUE, 1);
  213.      GLOBALVALUEDEF (int, GREEN, 3);
  214.      #else
  215.      enum globaldef color {RED, BLUE, GREEN = 3};
  216.      #endif
  217.  
  218. 
  219. File: gcc.info,  Node: VMS Misc,  Prev: Global Declarations,  Up: VMS
  220.  
  221. Other VMS Issues
  222. ================
  223.  
  224.    GNU CC automatically arranges for `main' to return 1 by default if
  225. you fail to specify an explicit return value.  This will be interpreted
  226. by VMS as a status code indicating a normal successful completion.
  227. Version 1 of GNU CC did not provide this default.
  228.  
  229.    GNU CC on VMS works only with the GNU assembler, GAS.  You need
  230. version 1.37 or later of GAS in order to produce value debugging
  231. information for the VMS debugger.  Use the ordinary VMS linker with the
  232. object files produced by GAS.
  233.  
  234.    Under previous versions of GNU CC, the generated code would
  235. occasionally give strange results when linked to the sharable `VAXCRTL'
  236. library.  Now this should work.
  237.  
  238.    A caveat for use of `const' global variables: the `const' modifier
  239. must be specified in every external declaration of the variable in all
  240. of the source files that use that variable.  Otherwise the linker will
  241. issue warnings about conflicting attributes for the variable.  Your
  242. program will still work despite the warnings, but the variable will be
  243. placed in writable storage.
  244.  
  245.    Although the VMS linker does distinguish between upper and lower case
  246. letters in global symbols, most VMS compilers convert all such symbols
  247. into upper case and most run-time library routines also have upper case
  248. names.  To be able to reliably call such routines, GNU CC (by means of
  249. the assembler GAS) converts global symbols into upper case like other
  250. VMS compilers.  However, since the usual practice in C is to distinguish
  251. case, GNU CC (via GAS) tries to preserve usual C behavior by augmenting
  252. each name that is not all lower case.  This means truncating the name
  253. to at most 23 characters and then adding more characters at the end
  254. which encode the case pattern of those 23.   Names which contain at
  255. least one dollar sign are an exception; they are converted directly into
  256. upper case without augmentation.
  257.  
  258.    Name augmentation yields bad results for programs that use
  259. precompiled libraries (such as Xlib) which were generated by another
  260. compiler.  You can use the compiler option `/NOCASE_HACK' to inhibit
  261. augmentation; it makes external C functions and variables
  262. case-independent as is usual on VMS.  Alternatively, you could write
  263. all references to the functions and variables in such libraries using
  264. lower case; this will work on VMS, but is not portable to other
  265. systems.  The compiler option `/NAMES' also provides control over
  266. global name handling.
  267.  
  268.    Function and variable names are handled somewhat differently with GNU
  269. C++.  The GNU C++ compiler performs "name mangling" on function names,
  270. which means that it adds information to the function name to describe
  271. the data types of the arguments that the function takes.  One result of
  272. this is that the name of a function can become very long.  Since the
  273. VMS linker only recognizes the first 31 characters in a name, special
  274. action is taken to ensure that each function and variable has a unique
  275. name that can be represented in 31 characters.
  276.  
  277.    If the name (plus a name augmentation, if required) is less than 32
  278. characters in length, then no special action is performed.  If the name
  279. is longer than 31 characters, the assembler (GAS) will generate a hash
  280. string based upon the function name, truncate the function name to 23
  281. characters, and append the hash string to the truncated name.  If the
  282. `/VERBOSE' compiler option is used, the assembler will print both the
  283. full and truncated names of each symbol that is truncated.
  284.  
  285.    The `/NOCASE_HACK' compiler option should not be used when you are
  286. compiling programs that use libg++.  libg++ has several instances of
  287. objects (i.e.  `Filebuf' and `filebuf') which become indistinguishable
  288. in a case-insensitive environment.  This leads to cases where you need
  289. to inhibit augmentation selectively (if you were using libg++ and Xlib
  290. in the same program, for example).  There is no special feature for
  291. doing this, but you can get the result by defining a macro for each
  292. mixed case symbol for which you wish to inhibit augmentation.  The
  293. macro should expand into the lower case equivalent of itself.  For
  294. example:
  295.  
  296.      #define StuDlyCapS studlycaps
  297.  
  298.    These macro definitions can be placed in a header file to minimize
  299. the number of changes to your source code.
  300.  
  301. 
  302. File: gcc.info,  Node: Portability,  Next: Interface,  Prev: VMS,  Up: Top
  303.  
  304. GNU CC and Portability
  305. **********************
  306.  
  307.    The main goal of GNU CC was to make a good, fast compiler for
  308. machines in the class that the GNU system aims to run on: 32-bit
  309. machines that address 8-bit bytes and have several general registers.
  310. Elegance, theoretical power and simplicity are only secondary.
  311.  
  312.    GNU CC gets most of the information about the target machine from a
  313. machine description which gives an algebraic formula for each of the
  314. machine's instructions.  This is a very clean way to describe the
  315. target.  But when the compiler needs information that is difficult to
  316. express in this fashion, I have not hesitated to define an ad-hoc
  317. parameter to the machine description.  The purpose of portability is to
  318. reduce the total work needed on the compiler; it was not of interest
  319. for its own sake.
  320.  
  321.    GNU CC does not contain machine dependent code, but it does contain
  322. code that depends on machine parameters such as endianness (whether the
  323. most significant byte has the highest or lowest address of the bytes in
  324. a word) and the availability of autoincrement addressing.  In the
  325. RTL-generation pass, it is often necessary to have multiple strategies
  326. for generating code for a particular kind of syntax tree, strategies
  327. that are usable for different combinations of parameters.  Often I have
  328. not tried to address all possible cases, but only the common ones or
  329. only the ones that I have encountered.  As a result, a new target may
  330. require additional strategies.  You will know if this happens because
  331. the compiler will call `abort'.  Fortunately, the new strategies can be
  332. added in a machine-independent fashion, and will affect only the target
  333. machines that need them.
  334.  
  335. 
  336. File: gcc.info,  Node: Interface,  Next: Passes,  Prev: Portability,  Up: Top
  337.  
  338. Interfacing to GNU CC Output
  339. ****************************
  340.  
  341.    GNU CC is normally configured to use the same function calling
  342. convention normally in use on the target system.  This is done with the
  343. machine-description macros described (*note Target Macros::.).
  344.  
  345.    However, returning of structure and union values is done differently
  346. on some target machines.  As a result, functions compiled with PCC
  347. returning such types cannot be called from code compiled with GNU CC,
  348. and vice versa.  This does not cause trouble often because few Unix
  349. library routines return structures or unions.
  350.  
  351.    GNU CC code returns structures and unions that are 1, 2, 4 or 8 bytes
  352. long in the same registers used for `int' or `double' return values.
  353. (GNU CC typically allocates variables of such types in registers also.)
  354. Structures and unions of other sizes are returned by storing them into
  355. an address passed by the caller (usually in a register).  The
  356. machine-description macros `STRUCT_VALUE' and `STRUCT_INCOMING_VALUE'
  357. tell GNU CC where to pass this address.
  358.  
  359.    By contrast, PCC on most target machines returns structures and
  360. unions of any size by copying the data into an area of static storage,
  361. and then returning the address of that storage as if it were a pointer
  362. value.  The caller must copy the data from that memory area to the
  363. place where the value is wanted.  This is slower than the method used
  364. by GNU CC, and fails to be reentrant.
  365.  
  366.    On some target machines, such as RISC machines and the 80386, the
  367. standard system convention is to pass to the subroutine the address of
  368. where to return the value.  On these machines, GNU CC has been
  369. configured to be compatible with the standard compiler, when this method
  370. is used.  It may not be compatible for structures of 1, 2, 4 or 8 bytes.
  371.  
  372.    GNU CC uses the system's standard convention for passing arguments.
  373. On some machines, the first few arguments are passed in registers; in
  374. others, all are passed on the stack.  It would be possible to use
  375. registers for argument passing on any machine, and this would probably
  376. result in a significant speedup.  But the result would be complete
  377. incompatibility with code that follows the standard convention.  So this
  378. change is practical only if you are switching to GNU CC as the sole C
  379. compiler for the system.  We may implement register argument passing on
  380. certain machines once we have a complete GNU system so that we can
  381. compile the libraries with GNU CC.
  382.  
  383.    On some machines (particularly the Sparc), certain types of arguments
  384. are passed "by invisible reference".  This means that the value is
  385. stored in memory, and the address of the memory location is passed to
  386. the subroutine.
  387.  
  388.    If you use `longjmp', beware of automatic variables.  ANSI C says
  389. that automatic variables that are not declared `volatile' have undefined
  390. values after a `longjmp'.  And this is all GNU CC promises to do,
  391. because it is very difficult to restore register variables correctly,
  392. and one of GNU CC's features is that it can put variables in registers
  393. without your asking it to.
  394.  
  395.    If you want a variable to be unaltered by `longjmp', and you don't
  396. want to write `volatile' because old C compilers don't accept it, just
  397. take the address of the variable.  If a variable's address is ever
  398. taken, even if just to compute it and ignore it, then the variable
  399. cannot go in a register:
  400.  
  401.      {
  402.        int careful;
  403.        &careful;
  404.        ...
  405.      }
  406.  
  407.    Code compiled with GNU CC may call certain library routines.  Most of
  408. them handle arithmetic for which there are no instructions.  This
  409. includes multiply and divide on some machines, and floating point
  410. operations on any machine for which floating point support is disabled
  411. with `-msoft-float'.  Some standard parts of the C library, such as
  412. `bcopy' or `memcpy', are also called automatically.  The usual function
  413. call interface is used for calling the library routines.
  414.  
  415.    These library routines should be defined in the library `libgcc.a',
  416. which GNU CC automatically searches whenever it links a program.  On
  417. machines that have multiply and divide instructions, if hardware
  418. floating point is in use, normally `libgcc.a' is not needed, but it is
  419. searched just in case.
  420.  
  421.    Each arithmetic function is defined in `libgcc1.c' to use the
  422. corresponding C arithmetic operator.  As long as the file is compiled
  423. with another C compiler, which supports all the C arithmetic operators,
  424. this file will work portably.  However, `libgcc1.c' does not work if
  425. compiled with GNU CC, because each arithmetic function would compile
  426. into a call to itself!
  427.  
  428. 
  429. File: gcc.info,  Node: Passes,  Next: RTL,  Prev: Interface,  Up: Top
  430.  
  431. Passes and Files of the Compiler
  432. ********************************
  433.  
  434.    The overall control structure of the compiler is in `toplev.c'.  This
  435. file is responsible for initialization, decoding arguments, opening and
  436. closing files, and sequencing the passes.
  437.  
  438.    The parsing pass is invoked only once, to parse the entire input.
  439. The RTL intermediate code for a function is generated as the function
  440. is parsed, a statement at a time.  Each statement is read in as a
  441. syntax tree and then converted to RTL; then the storage for the tree
  442. for the statement is reclaimed.  Storage for types (and the expressions
  443. for their sizes), declarations, and a representation of the binding
  444. contours and how they nest, remain until the function is finished being
  445. compiled; these are all needed to output the debugging information.
  446.  
  447.    Each time the parsing pass reads a complete function definition or
  448. top-level declaration, it calls either the function
  449. `rest_of_compilation', or the function `rest_of_decl_compilation' in
  450. `toplev.c', which are responsible for all further processing necessary,
  451. ending with output of the assembler language.  All other compiler
  452. passes run, in sequence, within `rest_of_compilation'.  When that
  453. function returns from compiling a function definition, the storage used
  454. for that function definition's compilation is entirely freed, unless it
  455. is an inline function (*note An Inline Function is As Fast As a Macro:
  456. Inline.).
  457.  
  458.    Here is a list of all the passes of the compiler and their source
  459. files.  Also included is a description of where debugging dumps can be
  460. requested with `-d' options.
  461.  
  462.    * Parsing.  This pass reads the entire text of a function definition,
  463.      constructing partial syntax trees.  This and RTL generation are no
  464.      longer truly separate passes (formerly they were), but it is
  465.      easier to think of them as separate.
  466.  
  467.      The tree representation does not entirely follow C syntax, because
  468.      it is intended to support other languages as well.
  469.  
  470.      Language-specific data type analysis is also done in this pass,
  471.      and every tree node that represents an expression has a data type
  472.      attached.  Variables are represented as declaration nodes.
  473.  
  474.      Constant folding and some arithmetic simplifications are also done
  475.      during this pass.
  476.  
  477.      The language-independent source files for parsing are
  478.      `stor-layout.c', `fold-const.c', and `tree.c'.  There are also
  479.      header files `tree.h' and `tree.def' which define the format of
  480.      the tree representation.
  481.  
  482.      The source files to parse C are `c-parse.y', `c-decl.c',
  483.      `c-typeck.c', `c-aux-info.c', `c-convert.c', and `c-lang.c' along
  484.      with header files `c-lex.h', and `c-tree.h'.
  485.  
  486.      The source files for parsing C++ are `cp-parse.y', `cp-class.c',
  487.      `cp-cvt.c', `cp-decl.c', `cp-decl2.c', `cp-dem.c', `cp-except.c',
  488.      `cp-expr.c', `cp-init.c', `cp-lex.c', `cp-method.c', `cp-ptree.c',
  489.      `cp-search.c', `cp-tree.c', `cp-type2.c', and `cp-typeck.c', along
  490.      with header files `cp-tree.def', `cp-tree.h', and `cp-decl.h'.
  491.  
  492.      The special source files for parsing Objective C are
  493.      `objc-parse.y', `objc-actions.c', `objc-tree.def', and
  494.      `objc-actions.h'.  Certain C-specific files are used for this as
  495.      well.
  496.  
  497.      The file `c-common.c' is also used for all of the above languages.
  498.  
  499.    * RTL generation.  This is the conversion of syntax tree into RTL
  500.      code.  It is actually done statement-by-statement during parsing,
  501.      but for most purposes it can be thought of as a separate pass.
  502.  
  503.      This is where the bulk of target-parameter-dependent code is found,
  504.      since often it is necessary for strategies to apply only when
  505.      certain standard kinds of instructions are available.  The purpose
  506.      of named instruction patterns is to provide this information to
  507.      the RTL generation pass.
  508.  
  509.      Optimization is done in this pass for `if'-conditions that are
  510.      comparisons, boolean operations or conditional expressions.  Tail
  511.      recursion is detected at this time also.  Decisions are made about
  512.      how best to arrange loops and how to output `switch' statements.
  513.  
  514.      The source files for RTL generation include `stmt.c', `calls.c',
  515.      `expr.c', `explow.c', `expmed.c', `function.c', `optabs.c' and
  516.      `emit-rtl.c'.  Also, the file `insn-emit.c', generated from the
  517.      machine description by the program `genemit', is used in this
  518.      pass.  The header file `expr.h' is used for communication within
  519.      this pass.
  520.  
  521.      The header files `insn-flags.h' and `insn-codes.h', generated from
  522.      the machine description by the programs `genflags' and `gencodes',
  523.      tell this pass which standard names are available for use and
  524.      which patterns correspond to them.
  525.  
  526.      Aside from debugging information output, none of the following
  527.      passes refers to the tree structure representation of the function
  528.      (only part of which is saved).
  529.  
  530.      The decision of whether the function can and should be expanded
  531.      inline in its subsequent callers is made at the end of rtl
  532.      generation.  The function must meet certain criteria, currently
  533.      related to the size of the function and the types and number of
  534.      parameters it has.  Note that this function may contain loops,
  535.      recursive calls to itself (tail-recursive functions can be
  536.      inlined!), gotos, in short, all constructs supported by GNU CC.
  537.      The file `integrate.c' contains the code to save a function's rtl
  538.      for later inlining and to inline that rtl when the function is
  539.      called.  The header file `integrate.h' is also used for this
  540.      purpose.
  541.  
  542.      The option `-dr' causes a debugging dump of the RTL code after
  543.      this pass.  This dump file's name is made by appending `.rtl' to
  544.      the input file name.
  545.  
  546.    * Jump optimization.  This pass simplifies jumps to the following
  547.      instruction, jumps across jumps, and jumps to jumps.  It deletes
  548.      unreferenced labels and unreachable code, except that unreachable
  549.      code that contains a loop is not recognized as unreachable in this
  550.      pass.  (Such loops are deleted later in the basic block analysis.)
  551.      It also converts some code originally written with jumps into
  552.      sequences of instructions that directly set values from the
  553.      results of comparisons, if the machine has such instructions.
  554.  
  555.      Jump optimization is performed two or three times.  The first time
  556.      is immediately following RTL generation.  The second time is after
  557.      CSE, but only if CSE says repeated jump optimization is needed.
  558.      The last time is right before the final pass.  That time,
  559.      cross-jumping and deletion of no-op move instructions are done
  560.      together with the optimizations described above.
  561.  
  562.      The source file of this pass is `jump.c'.
  563.  
  564.      The option `-dj' causes a debugging dump of the RTL code after
  565.      this pass is run for the first time.  This dump file's name is
  566.      made by appending `.jump' to the input file name.
  567.  
  568.    * Register scan.  This pass finds the first and last use of each
  569.      register, as a guide for common subexpression elimination.  Its
  570.      source is in `regclass.c'.
  571.  
  572.    * Jump threading.  This pass detects a condition jump that branches
  573.      to an identical or inverse test.  Such jumps can be `threaded'
  574.      through the second conditional test.  The source code for this
  575.      pass is in `jump.c'.  This optimization is only performed if
  576.      `-fthread-jumps' is enabled.
  577.  
  578.    * Common subexpression elimination.  This pass also does constant
  579.      propagation.  Its source file is `cse.c'.  If constant propagation
  580.      causes conditional jumps to become unconditional or to become
  581.      no-ops, jump optimization is run again when CSE is finished.
  582.  
  583.      The option `-ds' causes a debugging dump of the RTL code after
  584.      this pass.  This dump file's name is made by appending `.cse' to
  585.      the input file name.
  586.  
  587.    * Loop optimization.  This pass moves constant expressions out of
  588.      loops, and optionally does strength-reduction and loop unrolling
  589.      as well.  Its source files are `loop.c' and `unroll.c', plus the
  590.      header `loop.h' used for communication between them.  Loop
  591.      unrolling uses some functions in `integrate.c' and the header
  592.      `integrate.h'.
  593.  
  594.      The option `-dL' causes a debugging dump of the RTL code after
  595.      this pass.  This dump file's name is made by appending `.loop' to
  596.      the input file name.
  597.  
  598.    * If `-frerun-cse-after-loop' was enabled, a second common
  599.      subexpression elimination pass is performed after the loop
  600.      optimization pass.  Jump threading is also done again at this time
  601.      if it was specified.
  602.  
  603.      The option `-dt' causes a debugging dump of the RTL code after
  604.      this pass.  This dump file's name is made by appending `.cse2' to
  605.      the input file name.
  606.  
  607.    * Stupid register allocation is performed at this point in a
  608.      nonoptimizing compilation.  It does a little data flow analysis as
  609.      well.  When stupid register allocation is in use, the next pass
  610.      executed is the reloading pass; the others in between are skipped.
  611.      The source file is `stupid.c'.
  612.  
  613.    * Data flow analysis (`flow.c').  This pass divides the program into
  614.      basic blocks (and in the process deletes unreachable loops); then
  615.      it computes which pseudo-registers are live at each point in the
  616.      program, and makes the first instruction that uses a value point at
  617.      the instruction that computed the value.
  618.  
  619.      This pass also deletes computations whose results are never used,
  620.      and combines memory references with add or subtract instructions
  621.      to make autoincrement or autodecrement addressing.
  622.  
  623.      The option `-df' causes a debugging dump of the RTL code after
  624.      this pass.  This dump file's name is made by appending `.flow' to
  625.      the input file name.  If stupid register allocation is in use, this
  626.      dump file reflects the full results of such allocation.
  627.  
  628.    * Instruction combination (`combine.c').  This pass attempts to
  629.      combine groups of two or three instructions that are related by
  630.      data flow into single instructions.  It combines the RTL
  631.      expressions for the instructions by substitution, simplifies the
  632.      result using algebra, and then attempts to match the result
  633.      against the machine description.
  634.  
  635.      The option `-dc' causes a debugging dump of the RTL code after
  636.      this pass.  This dump file's name is made by appending `.combine'
  637.      to the input file name.
  638.  
  639.    * Instruction scheduling (`sched.c').  This pass looks for
  640.      instructions whose output will not be available by the time that
  641.      it is used in subsequent instructions.  (Memory loads and floating
  642.      point instructions often have this behavior on RISC machines).  It
  643.      re-orders instructions within a basic block to try to separate the
  644.      definition and use of items that otherwise would cause pipeline
  645.      stalls.
  646.  
  647.      Instruction scheduling is performed twice.  The first time is
  648.      immediately after instruction combination and the second is
  649.      immediately after reload.
  650.  
  651.      The option `-dS' causes a debugging dump of the RTL code after this
  652.      pass is run for the first time.  The dump file's name is made by
  653.      appending `.sched' to the input file name.
  654.  
  655.    * Register class preferencing.  The RTL code is scanned to find out
  656.      which register class is best for each pseudo register.  The source
  657.      file is `regclass.c'.
  658.  
  659.    * Local register allocation (`local-alloc.c').  This pass allocates
  660.      hard registers to pseudo registers that are used only within one
  661.      basic block.  Because the basic block is linear, it can use fast
  662.      and powerful techniques to do a very good job.
  663.  
  664.      The option `-dl' causes a debugging dump of the RTL code after
  665.      this pass.  This dump file's name is made by appending `.lreg' to
  666.      the input file name.
  667.  
  668.    * Global register allocation (`global.c').  This pass allocates hard
  669.      registers for the remaining pseudo registers (those whose life
  670.      spans are not contained in one basic block).
  671.  
  672.    * Reloading.  This pass renumbers pseudo registers with the hardware
  673.      registers numbers they were allocated.  Pseudo registers that did
  674.      not get hard registers are replaced with stack slots.  Then it
  675.      finds instructions that are invalid because a value has failed to
  676.      end up in a register, or has ended up in a register of the wrong
  677.      kind.  It fixes up these instructions by reloading the
  678.      problematical values temporarily into registers.  Additional
  679.      instructions are generated to do the copying.
  680.  
  681.      The reload pass also optionally eliminates the frame pointer and
  682.      inserts instructions to save and restore call-clobbered registers
  683.      around calls.
  684.  
  685.      Source files are `reload.c' and `reload1.c', plus the header
  686.      `reload.h' used for communication between them.
  687.  
  688.      The option `-dg' causes a debugging dump of the RTL code after
  689.      this pass.  This dump file's name is made by appending `.greg' to
  690.      the input file name.
  691.  
  692.    * Instruction scheduling is repeated here to try to avoid pipeline
  693.      stalls due to memory loads generated for spilled pseudo registers.
  694.  
  695.      The option `-dR' causes a debugging dump of the RTL code after
  696.      this pass.  This dump file's name is made by appending `.sched2'
  697.      to the input file name.
  698.  
  699.    * Jump optimization is repeated, this time including cross-jumping
  700.      and deletion of no-op move instructions.
  701.  
  702.      The option `-dJ' causes a debugging dump of the RTL code after
  703.      this pass.  This dump file's name is made by appending `.jump2' to
  704.      the input file name.
  705.  
  706.    * Delayed branch scheduling.  This optional pass attempts to find
  707.      instructions that can go into the delay slots of other
  708.      instructions, usually jumps and calls.  The source file name is
  709.      `reorg.c'.
  710.  
  711.      The option `-dd' causes a debugging dump of the RTL code after
  712.      this pass.  This dump file's name is made by appending `.dbr' to
  713.      the input file name.
  714.  
  715.    * Conversion from usage of some hard registers to usage of a register
  716.      stack may be done at this point.  Currently, this is supported only
  717.      for the floating-point registers of the Intel 80387 coprocessor.
  718.      The source file name is `reg-stack.c'.
  719.  
  720.      The options `-dk' causes a debugging dump of the RTL code after
  721.      this pass.  This dump file's name is made by appending `.stack' to
  722.      the input file name.
  723.  
  724.    * Final.  This pass outputs the assembler code for the function.  It
  725.      is also responsible for identifying spurious test and compare
  726.      instructions.  Machine-specific peephole optimizations are
  727.      performed at the same time.  The function entry and exit sequences
  728.      are generated directly as assembler code in this pass; they never
  729.      exist as RTL.
  730.  
  731.      The source files are `final.c' plus `insn-output.c'; the latter is
  732.      generated automatically from the machine description by the tool
  733.      `genoutput'.  The header file `conditions.h' is used for
  734.      communication between these files.
  735.  
  736.    * Debugging information output.  This is run after final because it
  737.      must output the stack slot offsets for pseudo registers that did
  738.      not get hard registers.  Source files are `dbxout.c' for DBX
  739.      symbol table format, `sdbout.c' for SDB symbol table format, and
  740.      `dwarfout.c' for DWARF symbol table format.
  741.  
  742.    Some additional files are used by all or many passes:
  743.  
  744.    * Every pass uses `machmode.def' and `machmode.h' which define the
  745.      machine modes.
  746.  
  747.    * Several passes use `real.h', which defines the default
  748.      representation of floating point constants and how to operate on
  749.      them.
  750.  
  751.    * All the passes that work with RTL use the header files `rtl.h' and
  752.      `rtl.def', and subroutines in file `rtl.c'.  The tools `gen*' also
  753.      use these files to read and work with the machine description RTL.
  754.  
  755.    * Several passes refer to the header file `insn-config.h' which
  756.      contains a few parameters (C macro definitions) generated
  757.      automatically from the machine description RTL by the tool
  758.      `genconfig'.
  759.  
  760.    * Several passes use the instruction recognizer, which consists of
  761.      `recog.c' and `recog.h', plus the files `insn-recog.c' and
  762.      `insn-extract.c' that are generated automatically from the machine
  763.      description by the tools `genrecog' and `genextract'.
  764.  
  765.    * Several passes use the header files `regs.h' which defines the
  766.      information recorded about pseudo register usage, and
  767.      `basic-block.h' which defines the information recorded about basic
  768.      blocks.
  769.  
  770.    * `hard-reg-set.h' defines the type `HARD_REG_SET', a bit-vector
  771.      with a bit for each hard register, and some macros to manipulate
  772.      it.  This type is just `int' if the machine has few enough hard
  773.      registers; otherwise it is an array of `int' and some of the
  774.      macros expand into loops.
  775.  
  776.    * Several passes use instruction attributes.  A definition of the
  777.      attributes defined for a particular machine is in file
  778.      `insn-attr.h', which is generated from the machine description by
  779.      the program `genattr'.  The file `insn-attrtab.c' contains
  780.      subroutines to obtain the attribute values for insns.  It is
  781.      generated from the machine description by the program `genattrtab'.
  782.  
  783. 
  784. File: gcc.info,  Node: RTL,  Next: Machine Desc,  Prev: Passes,  Up: Top
  785.  
  786. RTL Representation
  787. ******************
  788.  
  789.    Most of the work of the compiler is done on an intermediate
  790. representation called register transfer language.  In this language,
  791. the instructions to be output are described, pretty much one by one, in
  792. an algebraic form that describes what the instruction does.
  793.  
  794.    RTL is inspired by Lisp lists.  It has both an internal form, made
  795. up of structures that point at other structures, and a textual form
  796. that is used in the machine description and in printed debugging dumps.
  797. The textual form uses nested parentheses to indicate the pointers in
  798. the internal form.
  799.  
  800. * Menu:
  801.  
  802. * RTL Objects::       Expressions vs vectors vs strings vs integers.
  803. * Accessors::         Macros to access expression operands or vector elts.
  804. * Flags::             Other flags in an RTL expression.
  805. * Machine Modes::     Describing the size and format of a datum.
  806. * Constants::         Expressions with constant values.
  807. * Regs and Memory::   Expressions representing register contents or memory.
  808. * Arithmetic::        Expressions representing arithmetic on other expressions.
  809. * Comparisons::       Expressions representing comparison of expressions.
  810. * Bit Fields::        Expressions representing bit-fields in memory or reg.
  811. * Conversions::       Extending, truncating, floating or fixing.
  812. * RTL Declarations::  Declaring volatility, constancy, etc.
  813. * Side Effects::      Expressions for storing in registers, etc.
  814. * Incdec::            Embedded side-effects for autoincrement addressing.
  815. * Assembler::         Representing `asm' with operands.
  816. * Insns::             Expression types for entire insns.
  817. * Calls::             RTL representation of function call insns.
  818. * Sharing::           Some expressions are unique; others *must* be copied.
  819. * Reading RTL::       Reading textual RTL from a file.
  820.  
  821. 
  822. File: gcc.info,  Node: RTL Objects,  Next: Accessors,  Prev: RTL,  Up: RTL
  823.  
  824. RTL Object Types
  825. ================
  826.  
  827.    RTL uses five kinds of objects: expressions, integers, wide integers,
  828. strings and vectors.  Expressions are the most important ones.  An RTL
  829. expression ("RTX", for short) is a C structure, but it is usually
  830. referred to with a pointer; a type that is given the typedef name `rtx'.
  831.  
  832.    An integer is simply an `int'; their written form uses decimal
  833. digits.  A wide integer is an integral object whose type is
  834. `HOST_WIDE_INT' (*note Config::.); their written form uses decimal
  835. digits.
  836.  
  837.    A string is a sequence of characters.  In core it is represented as a
  838. `char *' in usual C fashion, and it is written in C syntax as well.
  839. However, strings in RTL may never be null.  If you write an empty
  840. string in a machine description, it is represented in core as a null
  841. pointer rather than as a pointer to a null character.  In certain
  842. contexts, these null pointers instead of strings are valid.  Within RTL
  843. code, strings are most commonly found inside `symbol_ref' expressions,
  844. but they appear in other contexts in the RTL expressions that make up
  845. machine descriptions.
  846.  
  847.    A vector contains an arbitrary number of pointers to expressions.
  848. The number of elements in the vector is explicitly present in the
  849. vector.  The written form of a vector consists of square brackets
  850. (`[...]') surrounding the elements, in sequence and with whitespace
  851. separating them.  Vectors of length zero are not created; null pointers
  852. are used instead.
  853.  
  854.    Expressions are classified by "expression codes" (also called RTX
  855. codes).  The expression code is a name defined in `rtl.def', which is
  856. also (in upper case) a C enumeration constant.  The possible expression
  857. codes and their meanings are machine-independent.  The code of an RTX
  858. can be extracted with the macro `GET_CODE (X)' and altered with
  859. `PUT_CODE (X, NEWCODE)'.
  860.  
  861.    The expression code determines how many operands the expression
  862. contains, and what kinds of objects they are.  In RTL, unlike Lisp, you
  863. cannot tell by looking at an operand what kind of object it is.
  864. Instead, you must know from its context--from the expression code of
  865. the containing expression.  For example, in an expression of code
  866. `subreg', the first operand is to be regarded as an expression and the
  867. second operand as an integer.  In an expression of code `plus', there
  868. are two operands, both of which are to be regarded as expressions.  In
  869. a `symbol_ref' expression, there is one operand, which is to be
  870. regarded as a string.
  871.  
  872.    Expressions are written as parentheses containing the name of the
  873. expression type, its flags and machine mode if any, and then the
  874. operands of the expression (separated by spaces).
  875.  
  876.    Expression code names in the `md' file are written in lower case,
  877. but when they appear in C code they are written in upper case.  In this
  878. manual, they are shown as follows: `const_int'.
  879.  
  880.    In a few contexts a null pointer is valid where an expression is
  881. normally wanted.  The written form of this is `(nil)'.
  882.  
  883. 
  884. File: gcc.info,  Node: Accessors,  Next: Flags,  Prev: RTL Objects,  Up: RTL
  885.  
  886. Access to Operands
  887. ==================
  888.  
  889.    For each expression type `rtl.def' specifies the number of contained
  890. objects and their kinds, with four possibilities: `e' for expression
  891. (actually a pointer to an expression), `i' for integer, `w' for wide
  892. integer, `s' for string, and `E' for vector of expressions.  The
  893. sequence of letters for an expression code is called its "format".
  894. Thus, the format of `subreg' is `ei'.
  895.  
  896.    A few other format characters are used occasionally:
  897.  
  898. `u'
  899.      `u' is equivalent to `e' except that it is printed differently in
  900.      debugging dumps.  It is used for pointers to insns.
  901.  
  902. `n'
  903.      `n' is equivalent to `i' except that it is printed differently in
  904.      debugging dumps.  It is used for the line number or code number of
  905.      a `note' insn.
  906.  
  907. `S'
  908.      `S' indicates a string which is optional.  In the RTL objects in
  909.      core, `S' is equivalent to `s', but when the object is read, from
  910.      an `md' file, the string value of this operand may be omitted.  An
  911.      omitted string is taken to be the null string.
  912.  
  913. `V'
  914.      `V' indicates a vector which is optional.  In the RTL objects in
  915.      core, `V' is equivalent to `E', but when the object is read from
  916.      an `md' file, the vector value of this operand may be omitted.  An
  917.      omitted vector is effectively the same as a vector of no elements.
  918.  
  919. `0'
  920.      `0' means a slot whose contents do not fit any normal category.
  921.      `0' slots are not printed at all in dumps, and are often used in
  922.      special ways by small parts of the compiler.
  923.  
  924.    There are macros to get the number of operands, the format, and the
  925. class of an expression code:
  926.  
  927. `GET_RTX_LENGTH (CODE)'
  928.      Number of operands of an RTX of code CODE.
  929.  
  930. `GET_RTX_FORMAT (CODE)'
  931.      The format of an RTX of code CODE, as a C string.
  932.  
  933. `GET_RTX_CLASS (CODE)'
  934.      A single character representing the type of RTX operation that code
  935.      CODE performs.
  936.  
  937.      The following classes are defined:
  938.  
  939.     `o'
  940.           An RTX code that represents an actual object, such as `reg' or
  941.           `mem'.  `subreg' is not in this class.
  942.  
  943.     `<'
  944.           An RTX code for a comparison.  The codes in this class are
  945.           `NE', `EQ', `LE', `LT', `GE', `GT', `LEU', `LTU', `GEU',
  946.           `GTU'.
  947.  
  948.     `1'
  949.           An RTX code for a unary arithmetic operation, such as `neg'.
  950.  
  951.     `c'
  952.           An RTX code for a commutative binary operation, other than
  953.           `NE' and `EQ' (which have class `<').
  954.  
  955.     `2'
  956.           An RTX code for a noncommutative binary operation, such as
  957.           `MINUS'.
  958.  
  959.     `b'
  960.           An RTX code for a bitfield operation (`ZERO_EXTRACT' and
  961.           `SIGN_EXTRACT').
  962.  
  963.     `3'
  964.           An RTX code for other three input operations, such as
  965.           `IF_THEN_ELSE'.
  966.  
  967.     `i'
  968.           An RTX code for a machine insn (`INSN', `JUMP_INSN', and
  969.           `CALL_INSN').
  970.  
  971.     `m'
  972.           An RTX code for something that matches in insns, such as
  973.           `MATCH_DUP'.
  974.  
  975.     `x'
  976.           All other RTX codes.
  977.  
  978.    Operands of expressions are accessed using the macros `XEXP',
  979. `XINT', `XWINT' and `XSTR'.  Each of these macros takes two arguments:
  980. an expression-pointer (RTX) and an operand number (counting from zero).
  981. Thus,
  982.  
  983.      XEXP (X, 2)
  984.  
  985. accesses operand 2 of expression X, as an expression.
  986.  
  987.      XINT (X, 2)
  988.  
  989. accesses the same operand as an integer.  `XSTR', used in the same
  990. fashion, would access it as a string.
  991.  
  992.    Any operand can be accessed as an integer, as an expression or as a
  993. string.  You must choose the correct method of access for the kind of
  994. value actually stored in the operand.  You would do this based on the
  995. expression code of the containing expression.  That is also how you
  996. would know how many operands there are.
  997.  
  998.    For example, if X is a `subreg' expression, you know that it has two
  999. operands which can be correctly accessed as `XEXP (X, 0)' and `XINT (X,
  1000. 1)'.  If you did `XINT (X, 0)', you would get the address of the
  1001. expression operand but cast as an integer; that might occasionally be
  1002. useful, but it would be cleaner to write `(int) XEXP (X, 0)'.  `XEXP
  1003. (X, 1)' would also compile without error, and would return the second,
  1004. integer operand cast as an expression pointer, which would probably
  1005. result in a crash when accessed.  Nothing stops you from writing `XEXP
  1006. (X, 28)' either, but this will access memory past the end of the
  1007. expression with unpredictable results.
  1008.  
  1009.    Access to operands which are vectors is more complicated.  You can
  1010. use the macro `XVEC' to get the vector-pointer itself, or the macros
  1011. `XVECEXP' and `XVECLEN' to access the elements and length of a vector.
  1012.  
  1013. `XVEC (EXP, IDX)'
  1014.      Access the vector-pointer which is operand number IDX in EXP.
  1015.  
  1016. `XVECLEN (EXP, IDX)'
  1017.      Access the length (number of elements) in the vector which is in
  1018.      operand number IDX in EXP.  This value is an `int'.
  1019.  
  1020. `XVECEXP (EXP, IDX, ELTNUM)'
  1021.      Access element number ELTNUM in the vector which is in operand
  1022.      number IDX in EXP.  This value is an RTX.
  1023.  
  1024.      It is up to you to make sure that ELTNUM is not negative and is
  1025.      less than `XVECLEN (EXP, IDX)'.
  1026.  
  1027.    All the macros defined in this section expand into lvalues and
  1028. therefore can be used to assign the operands, lengths and vector
  1029. elements as well as to access them.
  1030.  
  1031.