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"
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
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");
132 Class("class", cl::desc("Print Enum list for this class"),
133 cl::value_desc("class name"), cl::cat(PrintEnumsCat
));
136 TimeRegionsOpt("time-regions",
137 cl::desc("Time regions of tablegens execution"),
138 cl::location(TimeRegions
));
140 bool LLVMTableGenMain(raw_ostream
&OS
, RecordKeeper
&Records
) {
143 OS
<< Records
; // No argument, dump all contents
146 EmitJSON(Records
, OS
);
149 EmitCodeEmitter(Records
, OS
);
151 case GenRegisterInfo
:
152 EmitRegisterInfo(Records
, OS
);
155 EmitInstrInfo(Records
, OS
);
158 EmitInstrDocs(Records
, OS
);
161 EmitCallingConv(Records
, OS
);
164 EmitAsmWriter(Records
, OS
);
167 EmitAsmMatcher(Records
, OS
);
169 case GenDisassembler
:
170 EmitDisassembler(Records
, OS
);
172 case GenPseudoLowering
:
173 EmitPseudoLowering(Records
, OS
);
175 case GenCompressInst
:
176 EmitCompressInst(Records
, OS
);
179 EmitDAGISel(Records
, OS
);
181 case GenDFAPacketizer
:
182 EmitDFAPacketizer(Records
, OS
);
185 EmitFastISel(Records
, OS
);
188 EmitSubtarget(Records
, OS
);
190 case GenIntrinsicEnums
:
191 EmitIntrinsicEnums(Records
, OS
);
193 case GenIntrinsicImpl
:
194 EmitIntrinsicImpl(Records
, OS
);
196 case GenTgtIntrinsicEnums
:
197 EmitIntrinsicEnums(Records
, OS
, true);
199 case GenTgtIntrinsicImpl
:
200 EmitIntrinsicImpl(Records
, OS
, true);
202 case GenOptParserDefs
:
203 EmitOptParser(Records
, OS
);
207 for (Record
*Rec
: Records
.getAllDerivedDefinitions(Class
))
208 OS
<< Rec
->getName() << ", ";
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();
227 EmitCTags(Records
, OS
);
230 EmitAttributes(Records
, OS
);
232 case GenSearchableTables
:
233 EmitSearchableTables(Records
, OS
);
236 EmitGlobalISel(Records
, OS
);
238 case GenRegisterBank
:
239 EmitRegisterBank(Records
, OS
);
241 case GenX86EVEX2VEXTables
:
242 EmitX86EVEX2VEXTables(Records
, OS
);
244 case GenX86FoldTables
:
245 EmitX86FoldTables(Records
, OS
);
248 EmitExegesis(Records
, OS
);
256 int main(int argc
, char **argv
) {
257 sys::PrintStackTraceOnErrorSignal(argv
[0]);
258 PrettyStackTraceProgram
X(argc
, argv
);
259 cl::ParseCommandLineOptions(argc
, argv
);
263 return TableGenMain(argv
[0], &LLVMTableGenMain
);
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)