GCC Middle and Back End API Reference
gensupport.h
Go to the documentation of this file.
1/* Declarations for rtx-reader support for gen* routines.
2 Copyright (C) 2000-2026 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_GENSUPPORT_H
21#define GCC_GENSUPPORT_H
22
23#include "hash-set.h"
24#include "read-md.h"
25
26struct obstack;
27extern struct obstack *rtl_obstack;
28
29/* Information about an .md define_* rtx. */
31public:
32 /* The rtx itself. */
34
35 /* The location of the first line of the rtx. */
37
38 /* The unique number attached to the rtx. Currently all define_insns,
39 define_expands, define_splits, define_peepholes and define_peephole2s
40 share the same insn_code index space. */
41 int index;
42};
43
44#define OPTAB_CL(name, pat, c, b, l) name,
45#define OPTAB_CX(name, pat)
46#define OPTAB_CD(name, pat) name,
47#define OPTAB_NL(name, pat, c, b, s, l) name,
48#define OPTAB_NC(name, pat, c) name,
49#define OPTAB_NX(name, pat)
50#define OPTAB_VL(name, pat, c, b, s, l) name,
51#define OPTAB_VC(name, pat, c) name,
52#define OPTAB_VX(name, pat)
53#define OPTAB_DC(name, pat, c) name,
54#define OPTAB_D(name, pat) name,
55
56/* Enumerates all optabs. */
57typedef enum optab_tag {
59#include "optabs.def"
62
63#undef OPTAB_CL
64#undef OPTAB_CX
65#undef OPTAB_CD
66#undef OPTAB_NL
67#undef OPTAB_NC
68#undef OPTAB_NX
69#undef OPTAB_VL
70#undef OPTAB_VC
71#undef OPTAB_VX
72#undef OPTAB_DC
73#undef OPTAB_D
74
75/* Describes one entry in optabs.def. */
77{
78 /* The name of the optab (e.g. "add_optab"). */
79 const char *name;
80
81 /* The pattern that matching define_expands and define_insns have.
82 See the comment at the head of optabs.def for details. */
83 const char *pattern;
84
85 /* The initializers (in the form of C code) for the libcall_basename,
86 libcall_suffix and libcall_gen fields of (convert_)optab_libcall_d. */
87 const char *base;
88 const char *suffix;
89 const char *libcall;
90
91 /* The optab's enum value. */
92 unsigned int op;
93
94 /* The value returned by optab_to_code (OP). */
96
97 /* CODE if code_to_optab (CODE) should return OP, otherwise UNKNOWN. */
99
100 /* 1: conversion optabs with libcall data,
101 2: conversion optabs without libcall data,
102 3: non-conversion optabs with libcall data ("normal" and "overflow"
103 optabs in the optabs.def comment)
104 4: non-conversion optabs without libcall data ("direct" optabs). */
105 unsigned int kind;
106};
107
108extern optab_def optabs[];
109extern unsigned int num_optabs;
110
112extern unsigned int get_register_filter_id (const char *);
113
114extern unsigned int num_dependent_filters;
115
116/* Information about an instruction name that matches an optab pattern. */
118{
119 /* The name of the instruction. */
120 const char *name;
121
122 /* The matching optab. */
123 unsigned int op;
124
125 /* The optab modes. M2 is only significant for conversion optabs;
126 it is zero otherwise. */
127 unsigned int m1, m2;
128
129 /* An index that provides a lexicographical sort of (OP, M2, M1).
130 Used by genopinit.cc. */
131 unsigned int sort_num;
132};
133
135extern rtx_reader *init_rtx_reader_args_cb (int, const char **,
136 bool (*)(const char *));
137extern rtx_reader *init_rtx_reader_args (int, const char **);
138extern int count_patterns ();
139extern bool read_md_rtx (md_rtx_info *);
140extern unsigned int get_num_insn_codes ();
141
142/* Set this to 0 to disable automatic elision of insn patterns which
143 can never be used in this configuration. See genconditions.cc.
144 Must be set before calling init_md_reader. */
145extern int insn_elision;
146
147/* Return the C test that says whether a definition rtx can be used,
148 or "" if it can be used unconditionally. */
149extern const char *get_c_test (rtx);
150
151/* If the C test passed as the argument can be evaluated at compile
152 time, return its truth value; else return -1. The test must have
153 appeared somewhere in the machine description when genconditions
154 was run. */
155extern int maybe_eval_c_test (const char *);
156
157/* Add an entry to the table of conditions. Used by genconditions and
158 by read-rtl.cc. */
159extern void add_c_test (const char *, int);
160
161/* This structure is used internally by gensupport.cc and genconditions.cc. */
162struct c_test
163{
164 const char *expr;
165 int value;
166};
167
168#ifdef __HASHTAB_H__
169extern hashval_t hash_c_test (const void *);
170extern int cmp_c_test (const void *, const void *);
171extern void traverse_c_tests (htab_trav, void *);
172#endif
173
174/* Predicate handling: helper functions and data structures. */
175
177{
178 struct pred_data *next; /* for iterating over the set of all preds */
179 const char *name; /* predicate name */
180 bool special; /* special handling of modes? */
181
182 /* data used primarily by genpreds.cc */
183 const char *c_block; /* C test block */
184 rtx exp; /* RTL test expression */
185
186 /* data used primarily by genrecog.cc */
187 enum rtx_code singleton; /* if pred takes only one code, that code */
188 int num_codes; /* number of codes accepted */
189 bool allows_non_lvalue; /* if pred allows non-lvalue expressions */
190 bool allows_non_const; /* if pred allows non-const expressions */
191 bool codes[NUM_RTX_CODE]; /* set of codes accepted */
192};
193
194extern struct pred_data *first_predicate;
195extern struct pred_data *lookup_predicate (const char *);
196extern void add_predicate_code (struct pred_data *, enum rtx_code);
197extern void add_predicate (struct pred_data *);
198
199#define FOR_ALL_PREDICATES(p) for (p = first_predicate; p; p = p->next)
200
202{
203 /* The largest match_operand, match_operator or match_parallel
204 number found. */
206
207 /* The largest match_dup, match_op_dup or match_par_dup number found. */
209
210 /* The smallest and largest match_scratch number found. */
213
214 /* The number of times match_dup, match_op_dup or match_par_dup appears
215 in the pattern. */
217
218 /* The number of rtx arguments to the generator function. */
220
221 /* The number of rtx operands in an insn. */
223
224 /* The number of operand variables that are needed. */
226};
227
229
230extern void get_pattern_stats (struct pattern_stats *ranges, rtvec vec);
231extern void compute_test_codes (rtx, file_location, char *);
233extern const char *get_emit_function (rtx);
234extern bool find_optab (optab_pattern *, const char *);
235extern FILE *choose_output (const vec<FILE *> &, unsigned &);
236
237#endif /* GCC_GENSUPPORT_H */
Definition read-md.h:26
Definition hash-set.h:37
Definition gensupport.h:30
file_location loc
Definition gensupport.h:36
rtx def
Definition gensupport.h:33
int index
Definition gensupport.h:41
Definition read-md.h:342
struct rtx_def * rtx
Definition coretypes.h:57
struct rtvec_def * rtvec
Definition coretypes.h:91
static struct obstack obstack
Definition gcc.cc:366
#define NUM_RTX_CODE
Definition gengenrtl.cc:40
optab_def optabs[]
Definition gensupport.cc:3796
unsigned int num_optabs
Definition gensupport.cc:3802
int insn_elision
Definition gensupport.cc:45
hash_set< rtx > compact_syntax
Definition gensupport.cc:39
int cmp_c_test(const void *x, const void *y)
Definition gensupport.cc:3423
struct pred_data * first_predicate
Definition gensupport.cc:3482
vec< const char * > register_filters
Definition gensupport.cc:408
struct obstack * rtl_obstack
Definition gensupport.cc:48
hashval_t hash_c_test(const void *x)
Definition gensupport.cc:3397
void traverse_c_tests(htab_trav callback, void *info)
Definition gensupport.cc:3472
unsigned int num_dependent_filters
Definition gensupport.cc:410
rtx_reader * init_rtx_reader_args(int, const char **)
Definition gensupport.cc:3204
bool find_optab(optab_pattern *, const char *)
Definition gensupport.cc:3917
void add_predicate_code(struct pred_data *, enum rtx_code)
Definition gensupport.cc:3509
unsigned int get_register_filter_id(const char *)
Definition gensupport.cc:417
int count_patterns()
Definition gensupport.cc:3211
const char * get_c_test(rtx)
Definition gensupport.cc:3373
void compute_test_codes(rtx, file_location, char *)
Definition gensupport.cc:227
void add_c_test(const char *, int)
Definition gensupport.cc:3455
rtx add_implicit_parallel(rtvec)
Definition gensupport.cc:154
file_location get_file_location(rtx)
Definition gensupport.cc:3353
unsigned int get_num_insn_codes()
Definition gensupport.cc:3364
const char * get_emit_function(rtx)
Definition gensupport.cc:3759
enum optab_tag optab
FILE * choose_output(const vec< FILE * > &, unsigned &)
Definition gensupport.cc:3944
struct pred_data * lookup_predicate(const char *)
Definition gensupport.cc:3499
rtx_reader * init_rtx_reader_args_cb(int, const char **, bool(*)(const char *))
Definition gensupport.cc:3160
int maybe_eval_c_test(const char *)
Definition gensupport.cc:3436
optab_tag
Definition gensupport.h:57
@ NUM_OPTABS
Definition gensupport.h:637
@ unknown_optab
Definition gensupport.h:58
void get_pattern_stats(struct pattern_stats *ranges, rtvec vec)
Definition gensupport.cc:3732
void add_predicate(struct pred_data *)
Definition gensupport.cc:3537
bool read_md_rtx(md_rtx_info *)
Definition gensupport.cc:3268
rtx_code
Definition rtl.h:48
Definition gensupport.h:163
int value
Definition gensupport.h:165
const char * expr
Definition gensupport.h:164
Definition gensupport.h:77
const char * base
Definition gensupport.h:87
unsigned int kind
Definition gensupport.h:105
const char * suffix
Definition gensupport.h:88
const char * name
Definition gensupport.h:79
unsigned int op
Definition gensupport.h:92
const char * libcall
Definition gensupport.h:89
enum rtx_code rcode
Definition gensupport.h:98
enum rtx_code fcode
Definition gensupport.h:95
const char * pattern
Definition gensupport.h:83
Definition gensupport.h:118
unsigned int op
Definition gensupport.h:123
const char * name
Definition gensupport.h:120
unsigned int sort_num
Definition gensupport.h:131
unsigned int m1
Definition gensupport.h:127
unsigned int m2
Definition gensupport.h:127
Definition gensupport.h:202
int min_scratch_opno
Definition gensupport.h:211
int max_scratch_opno
Definition gensupport.h:212
int num_generator_args
Definition gensupport.h:219
int num_dups
Definition gensupport.h:216
int num_operand_vars
Definition gensupport.h:225
int max_dup_opno
Definition gensupport.h:208
int num_insn_operands
Definition gensupport.h:222
int max_opno
Definition gensupport.h:205
Definition gensupport.h:177
bool codes[NUM_RTX_CODE]
Definition gensupport.h:191
struct pred_data * next
Definition gensupport.h:178
bool allows_non_lvalue
Definition gensupport.h:189
rtx exp
Definition gensupport.h:184
bool special
Definition gensupport.h:180
const char * name
Definition gensupport.h:179
int num_codes
Definition gensupport.h:188
bool allows_non_const
Definition gensupport.h:190
const char * c_block
Definition gensupport.h:183
enum rtx_code singleton
Definition gensupport.h:187
Definition vec.h:450