gn build: Merge r372706
[llvm-complete.git] / utils / TableGen / TableGen.cpp
blobc485ed2feb7afd7eba66038558294f04ad37e3af
1 //===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the main function for LLVM's TableGen.
11 //===----------------------------------------------------------------------===//
13 #include "TableGenBackends.h" // Declares all backends.
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/ManagedStatic.h"
16 #include "llvm/Support/PrettyStackTrace.h"
17 #include "llvm/Support/Signals.h"
18 #include "llvm/TableGen/Main.h"
19 #include "llvm/TableGen/Record.h"
20 #include "llvm/TableGen/SetTheory.h"
22 using namespace llvm;
24 enum ActionType {
25 PrintRecords,
26 DumpJSON,
27 GenEmitter,
28 GenRegisterInfo,
29 GenInstrInfo,
30 GenInstrDocs,
31 GenAsmWriter,
32 GenAsmMatcher,
33 GenDisassembler,
34 GenPseudoLowering,
35 GenCompressInst,
36 GenCallingConv,
37 GenDAGISel,
38 GenDFAPacketizer,
39 GenFastISel,
40 GenSubtarget,
41 GenIntrinsicEnums,
42 GenIntrinsicImpl,
43 GenTgtIntrinsicEnums,
44 GenTgtIntrinsicImpl,
45 PrintEnums,
46 PrintSets,
47 GenOptParserDefs,
48 GenCTags,
49 GenAttributes,
50 GenSearchableTables,
51 GenGlobalISel,
52 GenX86EVEX2VEXTables,
53 GenX86FoldTables,
54 GenRegisterBank,
55 GenExegesis,
58 namespace llvm {
59 /// Storage for TimeRegionsOpt as a global so that backends aren't required to
60 /// include CommandLine.h
61 bool TimeRegions = false;
62 } // end namespace llvm
64 namespace {
65 cl::opt<ActionType>
66 Action(cl::desc("Action to perform:"),
67 cl::values(clEnumValN(PrintRecords, "print-records",
68 "Print all records to stdout (default)"),
69 clEnumValN(DumpJSON, "dump-json",
70 "Dump all records as machine-readable JSON"),
71 clEnumValN(GenEmitter, "gen-emitter",
72 "Generate machine code emitter"),
73 clEnumValN(GenRegisterInfo, "gen-register-info",
74 "Generate registers and register classes info"),
75 clEnumValN(GenInstrInfo, "gen-instr-info",
76 "Generate instruction descriptions"),
77 clEnumValN(GenInstrDocs, "gen-instr-docs",
78 "Generate instruction documentation"),
79 clEnumValN(GenCallingConv, "gen-callingconv",
80 "Generate calling convention descriptions"),
81 clEnumValN(GenAsmWriter, "gen-asm-writer",
82 "Generate assembly writer"),
83 clEnumValN(GenDisassembler, "gen-disassembler",
84 "Generate disassembler"),
85 clEnumValN(GenPseudoLowering, "gen-pseudo-lowering",
86 "Generate pseudo instruction lowering"),
87 clEnumValN(GenCompressInst, "gen-compress-inst-emitter",
88 "Generate RISCV compressed instructions."),
89 clEnumValN(GenAsmMatcher, "gen-asm-matcher",
90 "Generate assembly instruction matcher"),
91 clEnumValN(GenDAGISel, "gen-dag-isel",
92 "Generate a DAG instruction selector"),
93 clEnumValN(GenDFAPacketizer, "gen-dfa-packetizer",
94 "Generate DFA Packetizer for VLIW targets"),
95 clEnumValN(GenFastISel, "gen-fast-isel",
96 "Generate a \"fast\" instruction selector"),
97 clEnumValN(GenSubtarget, "gen-subtarget",
98 "Generate subtarget enumerations"),
99 clEnumValN(GenIntrinsicEnums, "gen-intrinsic-enums",
100 "Generate intrinsic enums"),
101 clEnumValN(GenIntrinsicImpl, "gen-intrinsic-impl",
102 "Generate intrinsic information"),
103 clEnumValN(GenTgtIntrinsicEnums, "gen-tgt-intrinsic-enums",
104 "Generate target intrinsic enums"),
105 clEnumValN(GenTgtIntrinsicImpl, "gen-tgt-intrinsic-impl",
106 "Generate target intrinsic information"),
107 clEnumValN(PrintEnums, "print-enums",
108 "Print enum values for a class"),
109 clEnumValN(PrintSets, "print-sets",
110 "Print expanded sets for testing DAG exprs"),
111 clEnumValN(GenOptParserDefs, "gen-opt-parser-defs",
112 "Generate option definitions"),
113 clEnumValN(GenCTags, "gen-ctags",
114 "Generate ctags-compatible index"),
115 clEnumValN(GenAttributes, "gen-attrs",
116 "Generate attributes"),
117 clEnumValN(GenSearchableTables, "gen-searchable-tables",
118 "Generate generic binary-searchable table"),
119 clEnumValN(GenGlobalISel, "gen-global-isel",
120 "Generate GlobalISel selector"),
121 clEnumValN(GenX86EVEX2VEXTables, "gen-x86-EVEX2VEX-tables",
122 "Generate X86 EVEX to VEX compress tables"),
123 clEnumValN(GenX86FoldTables, "gen-x86-fold-tables",
124 "Generate X86 fold tables"),
125 clEnumValN(GenRegisterBank, "gen-register-bank",
126 "Generate registers bank descriptions"),
127 clEnumValN(GenExegesis, "gen-exegesis",
128 "Generate llvm-exegesis tables")));
130 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
131 cl::opt<std::string>
132 Class("class", cl::desc("Print Enum list for this class"),
133 cl::value_desc("class name"), cl::cat(PrintEnumsCat));
135 cl::opt<bool, true>
136 TimeRegionsOpt("time-regions",
137 cl::desc("Time regions of tablegens execution"),
138 cl::location(TimeRegions));
140 bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
141 switch (Action) {
142 case PrintRecords:
143 OS << Records; // No argument, dump all contents
144 break;
145 case DumpJSON:
146 EmitJSON(Records, OS);
147 break;
148 case GenEmitter:
149 EmitCodeEmitter(Records, OS);
150 break;
151 case GenRegisterInfo:
152 EmitRegisterInfo(Records, OS);
153 break;
154 case GenInstrInfo:
155 EmitInstrInfo(Records, OS);
156 break;
157 case GenInstrDocs:
158 EmitInstrDocs(Records, OS);
159 break;
160 case GenCallingConv:
161 EmitCallingConv(Records, OS);
162 break;
163 case GenAsmWriter:
164 EmitAsmWriter(Records, OS);
165 break;
166 case GenAsmMatcher:
167 EmitAsmMatcher(Records, OS);
168 break;
169 case GenDisassembler:
170 EmitDisassembler(Records, OS);
171 break;
172 case GenPseudoLowering:
173 EmitPseudoLowering(Records, OS);
174 break;
175 case GenCompressInst:
176 EmitCompressInst(Records, OS);
177 break;
178 case GenDAGISel:
179 EmitDAGISel(Records, OS);
180 break;
181 case GenDFAPacketizer:
182 EmitDFAPacketizer(Records, OS);
183 break;
184 case GenFastISel:
185 EmitFastISel(Records, OS);
186 break;
187 case GenSubtarget:
188 EmitSubtarget(Records, OS);
189 break;
190 case GenIntrinsicEnums:
191 EmitIntrinsicEnums(Records, OS);
192 break;
193 case GenIntrinsicImpl:
194 EmitIntrinsicImpl(Records, OS);
195 break;
196 case GenTgtIntrinsicEnums:
197 EmitIntrinsicEnums(Records, OS, true);
198 break;
199 case GenTgtIntrinsicImpl:
200 EmitIntrinsicImpl(Records, OS, true);
201 break;
202 case GenOptParserDefs:
203 EmitOptParser(Records, OS);
204 break;
205 case PrintEnums:
207 for (Record *Rec : Records.getAllDerivedDefinitions(Class))
208 OS << Rec->getName() << ", ";
209 OS << "\n";
210 break;
212 case PrintSets:
214 SetTheory Sets;
215 Sets.addFieldExpander("Set", "Elements");
216 for (Record *Rec : Records.getAllDerivedDefinitions("Set")) {
217 OS << Rec->getName() << " = [";
218 const std::vector<Record*> *Elts = Sets.expand(Rec);
219 assert(Elts && "Couldn't expand Set instance");
220 for (Record *Elt : *Elts)
221 OS << ' ' << Elt->getName();
222 OS << " ]\n";
224 break;
226 case GenCTags:
227 EmitCTags(Records, OS);
228 break;
229 case GenAttributes:
230 EmitAttributes(Records, OS);
231 break;
232 case GenSearchableTables:
233 EmitSearchableTables(Records, OS);
234 break;
235 case GenGlobalISel:
236 EmitGlobalISel(Records, OS);
237 break;
238 case GenRegisterBank:
239 EmitRegisterBank(Records, OS);
240 break;
241 case GenX86EVEX2VEXTables:
242 EmitX86EVEX2VEXTables(Records, OS);
243 break;
244 case GenX86FoldTables:
245 EmitX86FoldTables(Records, OS);
246 break;
247 case GenExegesis:
248 EmitExegesis(Records, OS);
249 break;
252 return false;
256 int main(int argc, char **argv) {
257 sys::PrintStackTraceOnErrorSignal(argv[0]);
258 PrettyStackTraceProgram X(argc, argv);
259 cl::ParseCommandLineOptions(argc, argv);
261 llvm_shutdown_obj Y;
263 return TableGenMain(argv[0], &LLVMTableGenMain);
266 #ifdef __has_feature
267 #if __has_feature(address_sanitizer)
268 #include <sanitizer/lsan_interface.h>
269 // Disable LeakSanitizer for this binary as it has too many leaks that are not
270 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
271 LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return 1; }
272 #endif // __has_feature(address_sanitizer)
273 #endif // defined(__has_feature)