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/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"
61 /// Storage for TimeRegionsOpt as a global so that backends aren't required to
62 /// include CommandLine.h
63 bool TimeRegions
= false;
64 } // end namespace llvm
67 cl::opt
<ActionType
> Action(
68 cl::desc("Action to perform:"),
70 clEnumValN(PrintRecords
, "print-records",
71 "Print all records to stdout (default)"),
72 clEnumValN(DumpJSON
, "dump-json",
73 "Dump all records as machine-readable JSON"),
74 clEnumValN(GenEmitter
, "gen-emitter", "Generate machine code emitter"),
75 clEnumValN(GenRegisterInfo
, "gen-register-info",
76 "Generate registers and register classes info"),
77 clEnumValN(GenInstrInfo
, "gen-instr-info",
78 "Generate instruction descriptions"),
79 clEnumValN(GenInstrDocs
, "gen-instr-docs",
80 "Generate instruction documentation"),
81 clEnumValN(GenCallingConv
, "gen-callingconv",
82 "Generate calling convention descriptions"),
83 clEnumValN(GenAsmWriter
, "gen-asm-writer", "Generate assembly writer"),
84 clEnumValN(GenDisassembler
, "gen-disassembler",
85 "Generate disassembler"),
86 clEnumValN(GenPseudoLowering
, "gen-pseudo-lowering",
87 "Generate pseudo instruction lowering"),
88 clEnumValN(GenCompressInst
, "gen-compress-inst-emitter",
89 "Generate RISCV compressed instructions."),
90 clEnumValN(GenAsmMatcher
, "gen-asm-matcher",
91 "Generate assembly instruction matcher"),
92 clEnumValN(GenDAGISel
, "gen-dag-isel",
93 "Generate a DAG instruction selector"),
94 clEnumValN(GenDFAPacketizer
, "gen-dfa-packetizer",
95 "Generate DFA Packetizer for VLIW targets"),
96 clEnumValN(GenFastISel
, "gen-fast-isel",
97 "Generate a \"fast\" instruction selector"),
98 clEnumValN(GenSubtarget
, "gen-subtarget",
99 "Generate subtarget enumerations"),
100 clEnumValN(GenIntrinsicEnums
, "gen-intrinsic-enums",
101 "Generate intrinsic enums"),
102 clEnumValN(GenIntrinsicImpl
, "gen-intrinsic-impl",
103 "Generate intrinsic information"),
104 clEnumValN(GenTgtIntrinsicEnums
, "gen-tgt-intrinsic-enums",
105 "Generate target intrinsic enums"),
106 clEnumValN(GenTgtIntrinsicImpl
, "gen-tgt-intrinsic-impl",
107 "Generate target intrinsic information"),
108 clEnumValN(PrintEnums
, "print-enums", "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", "Generate ctags-compatible index"),
114 clEnumValN(GenAttributes
, "gen-attrs", "Generate attributes"),
115 clEnumValN(GenSearchableTables
, "gen-searchable-tables",
116 "Generate generic binary-searchable table"),
117 clEnumValN(GenGlobalISel
, "gen-global-isel",
118 "Generate GlobalISel selector"),
119 clEnumValN(GenGICombiner
, "gen-global-isel-combiner",
120 "Generate GlobalISel combiner"),
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"),
129 clEnumValN(GenAutomata
, "gen-automata",
130 "Generate generic automata")));
132 cl::OptionCategory
PrintEnumsCat("Options for -print-enums");
133 cl::opt
<std::string
> Class("class", cl::desc("Print Enum list for this class"),
134 cl::value_desc("class name"),
135 cl::cat(PrintEnumsCat
));
138 TimeRegionsOpt("time-regions",
139 cl::desc("Time regions of tablegens execution"),
140 cl::location(TimeRegions
));
142 bool LLVMTableGenMain(raw_ostream
&OS
, RecordKeeper
&Records
) {
145 OS
<< Records
; // No argument, dump all contents
148 EmitJSON(Records
, OS
);
151 EmitCodeEmitter(Records
, OS
);
153 case GenRegisterInfo
:
154 EmitRegisterInfo(Records
, OS
);
157 EmitInstrInfo(Records
, OS
);
160 EmitInstrDocs(Records
, OS
);
163 EmitCallingConv(Records
, OS
);
166 EmitAsmWriter(Records
, OS
);
169 EmitAsmMatcher(Records
, OS
);
171 case GenDisassembler
:
172 EmitDisassembler(Records
, OS
);
174 case GenPseudoLowering
:
175 EmitPseudoLowering(Records
, OS
);
177 case GenCompressInst
:
178 EmitCompressInst(Records
, OS
);
181 EmitDAGISel(Records
, OS
);
183 case GenDFAPacketizer
:
184 EmitDFAPacketizer(Records
, OS
);
187 EmitFastISel(Records
, OS
);
190 EmitSubtarget(Records
, OS
);
192 case GenIntrinsicEnums
:
193 EmitIntrinsicEnums(Records
, OS
);
195 case GenIntrinsicImpl
:
196 EmitIntrinsicImpl(Records
, OS
);
198 case GenTgtIntrinsicEnums
:
199 EmitIntrinsicEnums(Records
, OS
, true);
201 case GenTgtIntrinsicImpl
:
202 EmitIntrinsicImpl(Records
, OS
, true);
204 case GenOptParserDefs
:
205 EmitOptParser(Records
, OS
);
209 for (Record
*Rec
: Records
.getAllDerivedDefinitions(Class
))
210 OS
<< Rec
->getName() << ", ";
217 Sets
.addFieldExpander("Set", "Elements");
218 for (Record
*Rec
: Records
.getAllDerivedDefinitions("Set")) {
219 OS
<< Rec
->getName() << " = [";
220 const std::vector
<Record
*> *Elts
= Sets
.expand(Rec
);
221 assert(Elts
&& "Couldn't expand Set instance");
222 for (Record
*Elt
: *Elts
)
223 OS
<< ' ' << Elt
->getName();
229 EmitCTags(Records
, OS
);
232 EmitAttributes(Records
, OS
);
234 case GenSearchableTables
:
235 EmitSearchableTables(Records
, OS
);
238 EmitGlobalISel(Records
, OS
);
241 EmitGICombiner(Records
, OS
);
243 case GenRegisterBank
:
244 EmitRegisterBank(Records
, OS
);
246 case GenX86EVEX2VEXTables
:
247 EmitX86EVEX2VEXTables(Records
, OS
);
249 case GenX86FoldTables
:
250 EmitX86FoldTables(Records
, OS
);
253 EmitExegesis(Records
, OS
);
256 EmitAutomata(Records
, OS
);
264 int main(int argc
, char **argv
) {
265 sys::PrintStackTraceOnErrorSignal(argv
[0]);
266 PrettyStackTraceProgram
X(argc
, argv
);
267 cl::ParseCommandLineOptions(argc
, argv
);
271 return TableGenMain(argv
[0], &LLVMTableGenMain
);
274 #ifndef __has_feature
275 #define __has_feature(x) 0
278 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) || \
279 __has_feature(leak_sanitizer)
281 #include <sanitizer/lsan_interface.h>
282 // Disable LeakSanitizer for this binary as it has too many leaks that are not
283 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
284 LLVM_ATTRIBUTE_USED
int __lsan_is_turned_off() { return 1; }