GCC Middle and Back End API Reference
genoutput.cc File Reference
#include "bconfig.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "errors.h"
#include "read-md.h"
#include "gensupport.h"
Include dependency graph for genoutput.cc:

Data Structures

struct  operand_data
 
class  data
 
class  constraint_data
 

Macros

#define MAX_MAX_OPERANDS   40
 
#define INSN_OUTPUT_FORMAT_NONE   0 /* abort @endverbatim */
 
#define INSN_OUTPUT_FORMAT_SINGLE   1 /* const char * @endverbatim */
 
#define INSN_OUTPUT_FORMAT_MULTI   2 /* const char * const * @endverbatim */
 
#define INSN_OUTPUT_FORMAT_FUNCTION   3 /* const char * (*)(...) @endverbatim */
 

Functions

static int n_occurrences (int, const char *)
 
static const charstrip_whitespace (const char *)
 
static void output_prologue (void)
 
static void output_operand_data (void)
 
static void output_insn_data (void)
 
static void output_get_insn_name (void)
 
static void scan_operands (class data *, rtx, int, int)
 
static int compare_operands (struct operand_data *, struct operand_data *)
 
static void place_operands (class data *)
 
static void process_template (class data *, const char *)
 
static void validate_insn_alternatives (class data *)
 
static void validate_insn_operands (class data *)
 
static int mdep_constraint_len (const char *, file_location, int)
 
static void note_constraint (md_rtx_info *)
 
static void validate_optab_operands (class data *d)
 
static void gen_insn (md_rtx_info *info)
 
static void gen_peephole (md_rtx_info *info)
 
static void gen_expand (md_rtx_info *info)
 
static void init_insn_for_nothing (void)
 
int main (int, const char **)
 

Variables

static char general_mem [] = { TARGET_MEM_CONSTRAINT, 0 }
 
static int next_operand_number = 1
 
static struct operand_data null_operand
 
static struct operand_dataodata = &null_operand
 
static struct operand_data ** odata_end = &null_operand.next
 
static class dataidata
 
static class data ** idata_end
 
static const char indep_constraints [] = ",=+%*?!^$#&g"
 
static class constraint_dataconstraints_by_letter_table [1<< CHAR_BIT]
 

Macro Definition Documentation

◆ INSN_OUTPUT_FORMAT_FUNCTION

#define INSN_OUTPUT_FORMAT_FUNCTION   3 /* const char * (*)(...) @endverbatim */

◆ INSN_OUTPUT_FORMAT_MULTI

#define INSN_OUTPUT_FORMAT_MULTI   2 /* const char * const * @endverbatim */

◆ INSN_OUTPUT_FORMAT_NONE

#define INSN_OUTPUT_FORMAT_NONE   0 /* abort @endverbatim */
Must match the constants in recog.h.   

Referenced by gen_expand(), and output_insn_data().

◆ INSN_OUTPUT_FORMAT_SINGLE

#define INSN_OUTPUT_FORMAT_SINGLE   1 /* const char * @endverbatim */

◆ MAX_MAX_OPERANDS

#define MAX_MAX_OPERANDS   40
Generate code from to output assembler insns as recognized from rtl.
   Copyright (C) 1987-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
This program reads the machine description for the compiler target machine
 and produces a file containing these things:

 1. An array of `struct insn_data_d', which is indexed by insn code number,
 which contains:

   a. `name' is the name for that pattern.  Nameless patterns are
   given a name.

   b. `output' hold either the output template, an array of output
   templates, or an output function.

   c. `genfun' is the function to generate a body for that pattern,
   given operands as arguments.

   d. `n_operands' is the number of distinct operands in the pattern
   for that insn,

   e. `n_dups' is the number of match_dup's that appear in the insn's
   pattern.  This says how many elements of `recog_data.dup_loc' are
   significant after an insn has been recognized.

   f. `n_alternatives' is the number of alternatives in the constraints
   of each pattern.

   g. `output_format' tells what type of thing `output' is.

   h. `operand' is the base of an array of operand data for the insn.

 2. An array of `struct insn_operand data', used by `operand' above.

   a. `predicate', an int-valued function, is the match_operand predicate
   for this operand.

   b. `constraint' is the constraint for this operand.

   c. `address_p' indicates that the operand appears within ADDRESS
   rtx's.

   d. `mode' is the machine mode that that operand is supposed to have.

   e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART.

   f. `eliminable', is nonzero for operands that are matched normally by
   MATCH_OPERAND; it is zero for operands that should not be changed during
   register elimination such as MATCH_OPERATORs.

   g. `allows_mem', is true for operands that accept MEM rtxes.

The code number of an insn is simply its position in the machine
description; code numbers are assigned sequentially to entries in
the description, starting with code number 0.

Thus, the following entry in the machine description

  (define_insn "clrdf"
    [(set (match_operand:DF 0 "general_operand" "")
          (const_int 0))]
    ""
    "clrd %0")

assuming it is the 25th entry present, would cause
insn_data[24].template to be "clrd %0", and
insn_data[24].n_operands to be 1.   
No instruction can have more operands than this.  Sorry for this
arbitrary limit, but what machine will have an instruction with
this many operands?   

Referenced by scan_operands().

Function Documentation

◆ compare_operands()

static int compare_operands ( struct operand_data * d0,
struct operand_data * d1 )
static
Compare two operands for content equality.   

References d1, and ggc_alloc().

Referenced by place_operands().

◆ gen_expand()

◆ gen_insn()

static void gen_insn ( md_rtx_info * info)
static
Look at a define_insn just read.  Assign its code number.  Record
on idata the template and the number of arguments.  If the insn has
a hairy output action, output a function for now.   

References data::code_number, compact_syntax, data::compact_syntax_p, md_rtx_info::def, get_pattern_stats(), ggc_alloc(), i, idata_end, md_rtx_info::index, data::loc, md_rtx_info::loc, data::n_dups, data::n_generator_args, data::n_operands, data::name, data::next, data::operand, place_operands(), process_template(), scan_operands(), validate_insn_alternatives(), validate_insn_operands(), validate_optab_operands(), XSTR, XTMPL, XVEC, XVECEXP, and XVECLEN.

Referenced by main().

◆ gen_peephole()

static void gen_peephole ( md_rtx_info * info)
static
Look at a define_peephole just read.  Assign its code number.
Record on idata the template and the number of arguments.
If the insn has a hairy output action, output it now.   

References data::code_number, md_rtx_info::def, get_pattern_stats(), ggc_alloc(), i, idata_end, md_rtx_info::index, md_rtx_info::loc, data::next, place_operands(), process_template(), scan_operands(), validate_insn_alternatives(), XTMPL, XVEC, XVECEXP, and XVECLEN.

Referenced by main().

◆ init_insn_for_nothing()

static void init_insn_for_nothing ( void )
static

References ggc_alloc(), idata, idata_end, data::loc, data::name, and data::next.

Referenced by main().

◆ main()

◆ mdep_constraint_len()

static int mdep_constraint_len ( const char * s,
file_location loc,
int opno )
static
Return the length of the constraint name beginning at position S
of an operand constraint string, or issue an error message if there
is no such constraint.  Does not expect to be called for generic
constraints.   

References constraints_by_letter_table, error_at(), ggc_alloc(), constraint_data::loc, message_at(), constraint_data::name, constraint_data::namelen, and constraint_data::next_this_letter.

Referenced by validate_insn_alternatives().

◆ n_occurrences()

static int n_occurrences ( int c,
const char * s )
static
Return the number of occurrences of character C in string S or
-1 if S is the null string.   

◆ note_constraint()

static void note_constraint ( md_rtx_info * info)
static
Record just enough information about the constraint in *INFO to allow
checking of operand constraint strings above, in validate_insn_alternatives.
Does not validate most properties of the constraint itself; does enforce
no duplicate names, no overlap with MI constraints, and no prefixes.   

References CONST_CAST, constraints_by_letter_table, md_rtx_info::def, error_at(), exp(), general_mem, ggc_alloc(), indep_constraints, md_rtx_info::loc, message_at(), constraint_data::name, constraint_data::namelen, constraint_data::next_this_letter, and XSTR.

Referenced by main().

◆ output_get_insn_name()

static void output_get_insn_name ( void )
static

References ggc_alloc().

Referenced by main().

◆ output_insn_data()

◆ output_operand_data()

◆ output_prologue()

static void output_prologue ( void )
static

References ggc_alloc().

Referenced by main().

◆ place_operands()

static void place_operands ( class data * d)
static
Scan the list of operands we've already committed to output and either
find a subsequence that is the same, or allocate a new one at the end.   

References compare_operands(), ggc_alloc(), i, data::n_operands, next_operand_number, NULL, odata, odata_end, data::operand, and data::operand_number.

Referenced by gen_expand(), gen_insn(), and gen_peephole().

◆ process_template()

static void process_template ( class data * d,
const char * template_code )
static
Process an assembler template from a define_insn or a define_peephole.
It is either the assembler code template, a list of assembler code
templates, or C code to generate the assembler code template.   

References data::code_number, data::compact_syntax_p, error_at(), fatal_at(), ggc_alloc(), i, INSN_OUTPUT_FORMAT_FUNCTION, INSN_OUTPUT_FORMAT_MULTI, INSN_OUTPUT_FORMAT_SINGLE, data::loc, message_at(), data::n_alternatives, data::output_format, md_reader::print_md_ptr_loc(), rtx_reader_ptr, and data::template_code.

Referenced by gen_insn(), and gen_peephole().

◆ scan_operands()

static void scan_operands ( class data * d,
rtx part,
int this_address_p,
int this_strict_low )
static
Stores the operand data into `d->operand[i]'.

THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS.
THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART.   

References operand_data::address_p, operand_data::constraint, operand_data::eliminable, error_at(), GET_CODE, GET_MODE, GET_RTX_FORMAT, GET_RTX_LENGTH, ggc_alloc(), i, data::loc, MAX_MAX_OPERANDS, operand_data::mode, operand_data::n_alternatives, n_occurrences, NULL, data::operand, operand_data::predicate, scan_operands(), operand_data::seen, operand_data::strict_low, strip_whitespace(), XEXP, XINT, XSTR, XVEC, XVECEXP, and XVECLEN.

Referenced by gen_expand(), gen_insn(), gen_peephole(), and scan_operands().

◆ strip_whitespace()

static const char * strip_whitespace ( const char * s)
static
Remove whitespace in `s' by moving up characters until the end.
Return a new string.   

References ggc_alloc().

Referenced by scan_operands().

◆ validate_insn_alternatives()

static void validate_insn_alternatives ( class data * d)
static

◆ validate_insn_operands()

static void validate_insn_operands ( class data * d)
static
Verify that there are no gaps in operand numbers for INSNs.   

References error_at(), i, data::loc, data::n_operands, data::operand, and operand_data::seen.

Referenced by gen_insn().

◆ validate_optab_operands()

static void validate_optab_operands ( class data * d)
static

Variable Documentation

◆ constraints_by_letter_table

class constraint_data* constraints_by_letter_table[1<< CHAR_BIT]
static

◆ general_mem

char general_mem[] = { TARGET_MEM_CONSTRAINT, 0 }
static

Referenced by note_constraint().

◆ idata

class data* idata
static
This variable points to the first link in the insn chain.   

Referenced by find_inv_vars_cb(), init_insn_for_nothing(), and output_insn_data().

◆ idata_end

class data** idata_end
static
This variable points to the end of the insn chain.  This is where
everything relevant from the machien description is appended to.   

Referenced by gen_expand(), gen_insn(), gen_peephole(), and init_insn_for_nothing().

◆ indep_constraints

const char indep_constraints[] = ",=+%*?!^$#&g"
static
All machine-independent constraint characters (except digits) that
are handled outside the define*_constraint mechanism.   

Referenced by note_constraint(), and validate_insn_alternatives().

◆ next_operand_number

int next_operand_number = 1
static
This counts all operands used in the md file.  The first is null.   

Referenced by place_operands().

◆ null_operand

struct operand_data null_operand
static
Initial value:
=
{
0, 0, "", "", E_VOIDmode, 0, 0, 0, 0, 0
}
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
Begin with a null operand at index 0.   

◆ odata

◆ odata_end

struct operand_data** odata_end = &null_operand.next
static

Referenced by place_operands().