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 "hash-map.h"
#include "hash-table.h"
Include dependency graph for genoutput.cc:

Data Structures

struct  operand_data
class  data
class  constraint_data
struct  operand_data_hasher
struct  output_def

Macros

#define MAX_MAX_OPERANDS   40
#define INSN_OUTPUT_FORMAT_NONE   0
#define INSN_OUTPUT_FORMAT_SINGLE   1
#define INSN_OUTPUT_FORMAT_MULTI   2
#define INSN_OUTPUT_FORMAT_FUNCTION   3

Functions

static int n_occurrences (int, const char *)
static const char * strip_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 (const struct operand_data *, const 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]
static hash_set< free_string_hashused_reg_names
static hash_table< operand_data_hasher > * operand_datas
static hash_map< nofree_string_hash, output_defoutput_codes

Macro Definition Documentation

◆ INSN_OUTPUT_FORMAT_FUNCTION

#define INSN_OUTPUT_FORMAT_FUNCTION   3

◆ INSN_OUTPUT_FORMAT_MULTI

#define INSN_OUTPUT_FORMAT_MULTI   2

◆ INSN_OUTPUT_FORMAT_NONE

#define INSN_OUTPUT_FORMAT_NONE   0
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

◆ MAX_MAX_OPERANDS

#define MAX_MAX_OPERANDS   40
Generate code from to output assembler insns as recognized from rtl.
   Copyright (C) 1987-2026 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()

int compare_operands ( const struct operand_data * d0,
const struct operand_data * d1 )
static

◆ gen_expand()

◆ gen_insn()

void gen_insn ( md_rtx_info * info)
static

◆ gen_peephole()

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 md_rtx_info::def, gen_peephole(), get_pattern_stats(), 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.

◆ init_insn_for_nothing()

void init_insn_for_nothing ( void )
static

◆ main()

◆ mdep_constraint_len()

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, end(), error_at(), constraint_data::loc, mdep_constraint_len(), message_at(), constraint_data::name, constraint_data::namelen, constraint_data::next_this_letter, and used_reg_names.

Referenced by mdep_constraint_len(), and validate_insn_alternatives().

◆ n_occurrences()

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.   

References n_occurrences.

◆ note_constraint()

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 constraints_by_letter_table, md_rtx_info::def, error_at(), exp(), general_mem, indep_constraints, constraint_data::loc, md_rtx_info::loc, message_at(), constraint_data::name, constraint_data::namelen, constraint_data::next_this_letter, note_constraint(), and XSTR.

Referenced by main(), and note_constraint().

◆ output_get_insn_name()

void output_get_insn_name ( void )
static

References output_get_insn_name().

Referenced by main(), and output_get_insn_name().

◆ output_insn_data()

◆ output_operand_data()

◆ output_prologue()

void output_prologue ( void )
static

References output_prologue().

Referenced by main(), and output_prologue().

◆ place_operands()

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(), operand_data::eq_next, i, operand_data::index, data::n_operands, operand_data::next, next_operand_number, NULL, odata_end, data::operand, operand_datas, data::operand_number, and place_operands().

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

◆ process_template()

◆ scan_operands()

void scan_operands ( class data * d,
rtx part,
int this_address_p,
int this_strict_low )
static

◆ strip_whitespace()

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

References strip_whitespace().

Referenced by scan_operands(), and strip_whitespace().

◆ validate_insn_alternatives()

void validate_insn_alternatives ( class data * d)
static

◆ validate_insn_operands()

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, operand_data::seen, and validate_insn_operands().

Referenced by gen_insn(), and validate_insn_operands().

◆ validate_optab_operands()

Variable Documentation

◆ constraints_by_letter_table

◆ general_mem

char general_mem[] = { TARGET_MEM_CONSTRAINT, 0 }
static

Referenced by add_constraint(), and note_constraint().

◆ idata

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

Referenced by 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 machine 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, 0, "", "", E_VOIDmode, 0, 0, 0, 0, 0
}
Begin with a null operand at index 0.   

◆ odata

struct operand_data* odata = &null_operand
static

Referenced by output_operand_data().

◆ odata_end

struct operand_data** odata_end = &null_operand.next
static

Referenced by place_operands().

◆ operand_datas

hash_table<operand_data_hasher>* operand_datas
static
Hashtable of known pattern operands.   

Referenced by main(), and place_operands().

◆ output_codes

hash_map<nofree_string_hash, output_def> output_codes
static
The output_* definitions emitted so far, keyed by the template that
produced them together with the .md location that template came from.
Two patterns agreeing on both get byte-identical definitions, down to the
#line, so the second can name the first rather than repeat it.   

Referenced by process_template().

◆ used_reg_names

hash_set<free_string_hash> used_reg_names
static

Referenced by main(), and mdep_constraint_len().