1 //===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
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
7 //===----------------------------------------------------------------------===//
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/InitLLVM.h"
16 #include "llvm/TableGen/Main.h"
17 #include "llvm/TableGen/Record.h"
18 #include "llvm/TableGen/SetTheory.h"
58 GenDirectivesEnumDecl
,
59 GenDirectivesEnumImpl
,
63 cl::opt
<bool> EmitLongStrLiterals(
64 "long-string-literals",
65 cl::desc("when emitting large string tables, prefer string literals over "
66 "comma-separated char literals. This can be a readability and "
67 "compile-time performance win, but upsets some compilers"),
68 cl::Hidden
, cl::init(true));
69 } // end namespace llvm
72 cl::opt
<ActionType
> Action(
73 cl::desc("Action to perform:"),
75 clEnumValN(PrintRecords
, "print-records",
76 "Print all records to stdout (default)"),
77 clEnumValN(PrintDetailedRecords
, "print-detailed-records",
78 "Print full details of all records to stdout"),
79 clEnumValN(NullBackend
, "null-backend",
80 "Do nothing after parsing (useful for timing)"),
81 clEnumValN(DumpJSON
, "dump-json",
82 "Dump all records as machine-readable JSON"),
83 clEnumValN(GenEmitter
, "gen-emitter", "Generate machine code emitter"),
84 clEnumValN(GenCodeBeads
, "gen-code-beads",
85 "Generate machine code beads"),
86 clEnumValN(GenRegisterInfo
, "gen-register-info",
87 "Generate registers and register classes info"),
88 clEnumValN(GenInstrInfo
, "gen-instr-info",
89 "Generate instruction descriptions"),
90 clEnumValN(GenInstrDocs
, "gen-instr-docs",
91 "Generate instruction documentation"),
92 clEnumValN(GenCallingConv
, "gen-callingconv",
93 "Generate calling convention descriptions"),
94 clEnumValN(GenAsmWriter
, "gen-asm-writer", "Generate assembly writer"),
95 clEnumValN(GenDisassembler
, "gen-disassembler",
96 "Generate disassembler"),
97 clEnumValN(GenPseudoLowering
, "gen-pseudo-lowering",
98 "Generate pseudo instruction lowering"),
99 clEnumValN(GenCompressInst
, "gen-compress-inst-emitter",
100 "Generate RISCV compressed instructions."),
101 clEnumValN(GenAsmMatcher
, "gen-asm-matcher",
102 "Generate assembly instruction matcher"),
103 clEnumValN(GenDAGISel
, "gen-dag-isel",
104 "Generate a DAG instruction selector"),
105 clEnumValN(GenDFAPacketizer
, "gen-dfa-packetizer",
106 "Generate DFA Packetizer for VLIW targets"),
107 clEnumValN(GenFastISel
, "gen-fast-isel",
108 "Generate a \"fast\" instruction selector"),
109 clEnumValN(GenSubtarget
, "gen-subtarget",
110 "Generate subtarget enumerations"),
111 clEnumValN(GenIntrinsicEnums
, "gen-intrinsic-enums",
112 "Generate intrinsic enums"),
113 clEnumValN(GenIntrinsicImpl
, "gen-intrinsic-impl",
114 "Generate intrinsic information"),
115 clEnumValN(PrintEnums
, "print-enums", "Print enum values for a class"),
116 clEnumValN(PrintSets
, "print-sets",
117 "Print expanded sets for testing DAG exprs"),
118 clEnumValN(GenOptParserDefs
, "gen-opt-parser-defs",
119 "Generate option definitions"),
120 clEnumValN(GenOptRST
, "gen-opt-rst", "Generate option RST"),
121 clEnumValN(GenCTags
, "gen-ctags", "Generate ctags-compatible index"),
122 clEnumValN(GenAttributes
, "gen-attrs", "Generate attributes"),
123 clEnumValN(GenSearchableTables
, "gen-searchable-tables",
124 "Generate generic binary-searchable table"),
125 clEnumValN(GenGlobalISel
, "gen-global-isel",
126 "Generate GlobalISel selector"),
127 clEnumValN(GenGICombiner
, "gen-global-isel-combiner",
128 "Generate GlobalISel combiner"),
129 clEnumValN(GenX86EVEX2VEXTables
, "gen-x86-EVEX2VEX-tables",
130 "Generate X86 EVEX to VEX compress tables"),
131 clEnumValN(GenX86FoldTables
, "gen-x86-fold-tables",
132 "Generate X86 fold tables"),
133 clEnumValN(GenRegisterBank
, "gen-register-bank",
134 "Generate registers bank descriptions"),
135 clEnumValN(GenExegesis
, "gen-exegesis",
136 "Generate llvm-exegesis tables"),
137 clEnumValN(GenAutomata
, "gen-automata", "Generate generic automata"),
138 clEnumValN(GenDirectivesEnumDecl
, "gen-directive-decl",
139 "Generate directive related declaration code (header file)"),
140 clEnumValN(GenDirectivesEnumImpl
, "gen-directive-impl",
141 "Generate directive related implementation code")));
143 cl::OptionCategory
PrintEnumsCat("Options for -print-enums");
144 cl::opt
<std::string
> Class("class", cl::desc("Print Enum list for this class"),
145 cl::value_desc("class name"),
146 cl::cat(PrintEnumsCat
));
148 bool LLVMTableGenMain(raw_ostream
&OS
, RecordKeeper
&Records
) {
151 OS
<< Records
; // No argument, dump all contents
153 case PrintDetailedRecords
:
154 EmitDetailedRecords(Records
, OS
);
156 case NullBackend
: // No backend at all.
159 EmitJSON(Records
, OS
);
162 EmitCodeEmitter(Records
, OS
);
165 EmitCodeBeads(Records
, OS
);
167 case GenRegisterInfo
:
168 EmitRegisterInfo(Records
, OS
);
171 EmitInstrInfo(Records
, OS
);
174 EmitInstrDocs(Records
, OS
);
177 EmitCallingConv(Records
, OS
);
180 EmitAsmWriter(Records
, OS
);
183 EmitAsmMatcher(Records
, OS
);
185 case GenDisassembler
:
186 EmitDisassembler(Records
, OS
);
188 case GenPseudoLowering
:
189 EmitPseudoLowering(Records
, OS
);
191 case GenCompressInst
:
192 EmitCompressInst(Records
, OS
);
195 EmitDAGISel(Records
, OS
);
197 case GenDFAPacketizer
:
198 EmitDFAPacketizer(Records
, OS
);
201 EmitFastISel(Records
, OS
);
204 EmitSubtarget(Records
, OS
);
206 case GenIntrinsicEnums
:
207 EmitIntrinsicEnums(Records
, OS
);
209 case GenIntrinsicImpl
:
210 EmitIntrinsicImpl(Records
, OS
);
212 case GenOptParserDefs
:
213 EmitOptParser(Records
, OS
);
216 EmitOptRST(Records
, OS
);
220 for (Record
*Rec
: Records
.getAllDerivedDefinitions(Class
))
221 OS
<< Rec
->getName() << ", ";
228 Sets
.addFieldExpander("Set", "Elements");
229 for (Record
*Rec
: Records
.getAllDerivedDefinitions("Set")) {
230 OS
<< Rec
->getName() << " = [";
231 const std::vector
<Record
*> *Elts
= Sets
.expand(Rec
);
232 assert(Elts
&& "Couldn't expand Set instance");
233 for (Record
*Elt
: *Elts
)
234 OS
<< ' ' << Elt
->getName();
240 EmitCTags(Records
, OS
);
243 EmitAttributes(Records
, OS
);
245 case GenSearchableTables
:
246 EmitSearchableTables(Records
, OS
);
249 EmitGlobalISel(Records
, OS
);
252 EmitGICombiner(Records
, OS
);
254 case GenRegisterBank
:
255 EmitRegisterBank(Records
, OS
);
257 case GenX86EVEX2VEXTables
:
258 EmitX86EVEX2VEXTables(Records
, OS
);
260 case GenX86FoldTables
:
261 EmitX86FoldTables(Records
, OS
);
264 EmitExegesis(Records
, OS
);
267 EmitAutomata(Records
, OS
);
269 case GenDirectivesEnumDecl
:
270 EmitDirectivesDecl(Records
, OS
);
272 case GenDirectivesEnumImpl
:
273 EmitDirectivesImpl(Records
, OS
);
281 int main(int argc
, char **argv
) {
282 InitLLVM
X(argc
, argv
);
283 cl::ParseCommandLineOptions(argc
, argv
);
285 return TableGenMain(argv
[0], &LLVMTableGenMain
);
288 #ifndef __has_feature
289 #define __has_feature(x) 0
292 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) || \
293 __has_feature(leak_sanitizer)
295 #include <sanitizer/lsan_interface.h>
296 // Disable LeakSanitizer for this binary as it has too many leaks that are not
297 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
298 LLVM_ATTRIBUTE_USED
int __lsan_is_turned_off() { return 1; }