1/* Declarations for rtx-reader support for gen* routines.
2 Copyright (C) 2000-2017 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 "read-md.h"
24
25struct obstack;
26extern struct obstack *rtl_obstack;
27
28/* Information about an .md define_* rtx. */
29struct md_rtx_info {
30 /* The rtx itself. */
31 rtx def;
32
33 /* The location of the first line of the rtx. */
34 file_location loc;
35
36 /* The unique number attached to the rtx. Currently all define_insns,
37 define_expands, define_splits, define_peepholes and define_peephole2s
38 share the same insn_code index space. */
39 int index;
40};
41
42#define OPTAB_CL(name, pat, c, b, l) name,
43#define OPTAB_CX(name, pat)
44#define OPTAB_CD(name, pat) name,
45#define OPTAB_NL(name, pat, c, b, s, l) name,
46#define OPTAB_NC(name, pat, c) name,
47#define OPTAB_NX(name, pat)
48#define OPTAB_VL(name, pat, c, b, s, l) name,
49#define OPTAB_VC(name, pat, c) name,
50#define OPTAB_VX(name, pat)
51#define OPTAB_DC(name, pat, c) name,
52#define OPTAB_D(name, pat) name,
53
54/* Enumerates all optabs. */
55typedef enum optab_tag {
56 unknown_optab,
57#include "optabs.def"
58 NUM_OPTABS
59} optab;
60
61#undef OPTAB_CL
62#undef OPTAB_CX
63#undef OPTAB_CD
64#undef OPTAB_NL
65#undef OPTAB_NC
66#undef OPTAB_NX
67#undef OPTAB_VL
68#undef OPTAB_VC
69#undef OPTAB_VX
70#undef OPTAB_DC
71#undef OPTAB_D
72
73/* Describes one entry in optabs.def. */
74struct optab_def
75{
76 /* The name of the optab (e.g. "add_optab"). */
77 const char *name;
78
79 /* The pattern that matching define_expands and define_insns have.
80 See the comment at the head of optabs.def for details. */
81 const char *pattern;
82
83 /* The initializers (in the form of C code) for the libcall_basename,
84 libcall_suffix and libcall_gen fields of (convert_)optab_libcall_d. */
85 const char *base;
86 const char *suffix;
87 const char *libcall;
88
89 /* The optab's enum value. */
90 unsigned int op;
91
92 /* The value returned by optab_to_code (OP). */
93 enum rtx_code fcode;
94
95 /* CODE if code_to_optab (CODE) should return OP, otherwise UNKNOWN. */
96 enum rtx_code rcode;
97
98 /* 1: conversion optabs with libcall data,
99 2: conversion optabs without libcall data,
100 3: non-conversion optabs with libcall data ("normal" and "overflow"
101 optabs in the optabs.def comment)
102 4: non-conversion optabs without libcall data ("direct" optabs). */
103 unsigned int kind;
104};
105
106extern optab_def optabs[];
107extern unsigned int num_optabs;
108
109/* Information about an instruction name that matches an optab pattern. */
110struct optab_pattern
111{
112 /* The name of the instruction. */
113 const char *name;
114
115 /* The matching optab. */
116 unsigned int op;
117
118 /* The optab modes. M2 is only significant for conversion optabs;
119 it is zero otherwise. */
120 unsigned int m1, m2;
121
122 /* An index that provides a lexicographical sort of (OP, M2, M1).
123 Used by genopinit.c. */
124 unsigned int sort_num;
125};
126
127extern rtx add_implicit_parallel (rtvec);
128extern rtx_reader *init_rtx_reader_args_cb (int, const char **,
129 bool (*)(const char *));
130extern rtx_reader *init_rtx_reader_args (int, const char **);
131extern bool read_md_rtx (md_rtx_info *);
132extern unsigned int get_num_insn_codes ();
133
134/* Set this to 0 to disable automatic elision of insn patterns which
135 can never be used in this configuration. See genconditions.c.
136 Must be set before calling init_md_reader. */
137extern int insn_elision;
138
139/* Return the C test that says whether a definition rtx can be used,
140 or "" if it can be used unconditionally. */
141extern const char *get_c_test (rtx);
142
143/* If the C test passed as the argument can be evaluated at compile
144 time, return its truth value; else return -1. The test must have
145 appeared somewhere in the machine description when genconditions
146 was run. */
147extern int maybe_eval_c_test (const char *);
148
149/* Add an entry to the table of conditions. Used by genconditions and
150 by read-rtl.c. */
151extern void add_c_test (const char *, int);
152
153/* This structure is used internally by gensupport.c and genconditions.c. */
154struct c_test
155{
156 const char *expr;
157 int value;
158};
159
160#ifdef __HASHTAB_H__
161extern hashval_t hash_c_test (const void *);
162extern int cmp_c_test (const void *, const void *);
163extern void traverse_c_tests (htab_trav, void *);
164#endif
165
166/* Predicate handling: helper functions and data structures. */
167
168struct pred_data
169{
170 struct pred_data *next; /* for iterating over the set of all preds */
171 const char *name; /* predicate name */
172 bool special; /* special handling of modes? */
173
174 /* data used primarily by genpreds.c */
175 const char *c_block; /* C test block */
176 rtx exp; /* RTL test expression */
177
178 /* data used primarily by genrecog.c */
179 enum rtx_code singleton; /* if pred takes only one code, that code */
180 int num_codes; /* number of codes accepted */
181 bool allows_non_lvalue; /* if pred allows non-lvalue expressions */
182 bool allows_non_const; /* if pred allows non-const expressions */
183 bool codes[NUM_RTX_CODE]; /* set of codes accepted */
184};
185
186extern struct pred_data *first_predicate;
187extern struct pred_data *lookup_predicate (const char *);
188extern void add_predicate_code (struct pred_data *, enum rtx_code);
189extern void add_predicate (struct pred_data *);
190
191#define FOR_ALL_PREDICATES(p) for (p = first_predicate; p; p = p->next)
192
193struct pattern_stats
194{
195 /* The largest match_operand, match_operator or match_parallel
196 number found. */
197 int max_opno;
198
199 /* The largest match_dup, match_op_dup or match_par_dup number found. */
200 int max_dup_opno;
201
202 /* The smallest and largest match_scratch number found. */
203 int min_scratch_opno;
204 int max_scratch_opno;
205
206 /* The number of times match_dup, match_op_dup or match_par_dup appears
207 in the pattern. */
208 int num_dups;
209
210 /* The number of rtx arguments to the generator function. */
211 int num_generator_args;
212
213 /* The number of rtx operands in an insn. */
214 int num_insn_operands;
215
216 /* The number of operand variables that are needed. */
217 int num_operand_vars;
218};
219
220extern void get_pattern_stats (struct pattern_stats *ranges, rtvec vec);
221extern void compute_test_codes (rtx, file_location, char *);
222extern file_location get_file_location (rtx);
223extern const char *get_emit_function (rtx);
224extern bool needs_barrier_p (rtx);
225extern bool find_optab (optab_pattern *, const char *);
226
227#endif /* GCC_GENSUPPORT_H */
228