diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -3205,6 +3205,8 @@ Record *AsmParser = Target.getAsmParser(); StringRef ClassName = AsmParser->getValueAsString("AsmParserClassName"); + emitSourceFileHeader("Assembly Matcher Source Fragment", OS); + // Compute the information on the instructions to match. AsmMatcherInfo Info(AsmParser, Target, Records); Info.buildInfo(); @@ -4002,11 +4004,9 @@ OS << "#endif // GET_MNEMONIC_CHECKER\n\n"; } -namespace llvm { +namespace { + +TableGen::Emitter::OptClass + X("gen-asm-matcher", "Generate assembly instruction matcher"); -void EmitAsmMatcher(RecordKeeper &RK, raw_ostream &OS) { - emitSourceFileHeader("Assembly Matcher Source Fragment", OS); - AsmMatcherEmitter(RK).run(OS); } - -} // end namespace llvm diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp --- a/llvm/utils/TableGen/AsmWriterEmitter.cpp +++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp @@ -1300,17 +1300,16 @@ std::vector> TableDrivenOperandPrinters; unsigned BitsLeft = 0; unsigned AsmStrBits = 0; + emitSourceFileHeader("Assembly Writer Source Fragment", O); EmitGetMnemonic(O, TableDrivenOperandPrinters, BitsLeft, AsmStrBits); EmitPrintInstruction(O, TableDrivenOperandPrinters, BitsLeft, AsmStrBits); EmitGetRegisterName(O); EmitPrintAliasInstruction(O); } -namespace llvm { +namespace { -void EmitAsmWriter(RecordKeeper &RK, raw_ostream &OS) { - emitSourceFileHeader("Assembly Writer Source Fragment", OS); - AsmWriterEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass X("gen-asm-writer", + "Generate assembly writer"); -} // end namespace llvm +} diff --git a/llvm/utils/TableGen/Attributes.cpp b/llvm/utils/TableGen/Attributes.cpp --- a/llvm/utils/TableGen/Attributes.cpp +++ b/llvm/utils/TableGen/Attributes.cpp @@ -18,7 +18,7 @@ class Attributes { public: Attributes(RecordKeeper &R) : Records(R) {} - void emit(raw_ostream &OS); + void run(raw_ostream &OS); private: void emitTargetIndependentNames(raw_ostream &OS); @@ -124,16 +124,14 @@ OS << "#endif\n"; } -void Attributes::emit(raw_ostream &OS) { +void Attributes::run(raw_ostream &OS) { emitTargetIndependentNames(OS); emitFnAttrCompatCheck(OS, false); emitAttributeProperties(OS); } -namespace llvm { +namespace { -void EmitAttributes(RecordKeeper &RK, raw_ostream &OS) { - Attributes(RK).emit(OS); -} +TableGen::Emitter::OptClass X("gen-attrs", "Generate attributes"); -} // namespace llvm +} diff --git a/llvm/utils/TableGen/CTagsEmitter.cpp b/llvm/utils/TableGen/CTagsEmitter.cpp --- a/llvm/utils/TableGen/CTagsEmitter.cpp +++ b/llvm/utils/TableGen/CTagsEmitter.cpp @@ -86,8 +86,9 @@ T.emit(OS); } -namespace llvm { +namespace { -void EmitCTags(RecordKeeper &RK, raw_ostream &OS) { CTagsEmitter(RK).run(OS); } +TableGen::Emitter::OptClass X("gen-ctags", + "Generate ctags-compatible index"); -} // namespace llvm +} diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp --- a/llvm/utils/TableGen/CallingConvEmitter.cpp +++ b/llvm/utils/TableGen/CallingConvEmitter.cpp @@ -42,6 +42,8 @@ } // End anonymous namespace void CallingConvEmitter::run(raw_ostream &O) { + emitSourceFileHeader("Calling Convention Implementation Fragment", O); + std::vector CCs = Records.getAllDerivedDefinitions("CallingConv"); // Emit prototypes for all of the non-custom CC's so that they can forward ref @@ -427,11 +429,9 @@ } } -namespace llvm { +namespace { + +TableGen::Emitter::OptClass + X("gen-callingconv", "Generate calling convention descriptions"); -void EmitCallingConv(RecordKeeper &RK, raw_ostream &OS) { - emitSourceFileHeader("Calling Convention Implementation Fragment", OS); - CallingConvEmitter(RK).run(OS); } - -} // namespace llvm diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp --- a/llvm/utils/TableGen/CodeEmitterGen.cpp +++ b/llvm/utils/TableGen/CodeEmitterGen.cpp @@ -421,6 +421,8 @@ } void CodeEmitterGen::run(raw_ostream &o) { + emitSourceFileHeader("Machine Code Emitter", o); + CodeGenTarget Target(Records); std::vector Insts = Records.getAllDerivedDefinitions("Instruction"); @@ -563,13 +565,7 @@ } } -} // end anonymous namespace - -namespace llvm { - -void EmitCodeEmitter(RecordKeeper &RK, raw_ostream &OS) { - emitSourceFileHeader("Machine Code Emitter", OS); - CodeEmitterGen(RK).run(OS); -} +TableGen::Emitter::OptClass X("gen-emitter", + "Generate machine code emitter"); -} // end namespace llvm +} // namespace diff --git a/llvm/utils/TableGen/CompressInstEmitter.cpp b/llvm/utils/TableGen/CompressInstEmitter.cpp --- a/llvm/utils/TableGen/CompressInstEmitter.cpp +++ b/llvm/utils/TableGen/CompressInstEmitter.cpp @@ -904,10 +904,9 @@ emitCompressInstEmitter(o, EmitterType::CheckCompress); } -namespace llvm { +namespace { -void EmitCompressInst(RecordKeeper &RK, raw_ostream &OS) { - CompressInstEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass + X("gen-compress-inst-emitter", "Generate RISCV compressed instructions."); -} // namespace llvm +} diff --git a/llvm/utils/TableGen/DAGISelEmitter.cpp b/llvm/utils/TableGen/DAGISelEmitter.cpp --- a/llvm/utils/TableGen/DAGISelEmitter.cpp +++ b/llvm/utils/TableGen/DAGISelEmitter.cpp @@ -125,6 +125,7 @@ void DAGISelEmitter::run(raw_ostream &OS) { + Records.startTimer("Parse patterns"); emitSourceFileHeader("DAG Instruction Selector for the " + CGP.getTargetInfo().getName().str() + " target", OS); @@ -187,11 +188,9 @@ EmitMatcherTable(TheMatcher.get(), CGP, OS); } -namespace llvm { +namespace { -void EmitDAGISel(RecordKeeper &RK, raw_ostream &OS) { - RK.startTimer("Parse patterns"); - DAGISelEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass + X("gen-dag-isel", "Generate a DAG instruction selector"); -} // namespace llvm +} diff --git a/llvm/utils/TableGen/DFAEmitter.cpp b/llvm/utils/TableGen/DFAEmitter.cpp --- a/llvm/utils/TableGen/DFAEmitter.cpp +++ b/llvm/utils/TableGen/DFAEmitter.cpp @@ -370,10 +370,9 @@ OS << ")"; } -namespace llvm { +namespace { -void EmitAutomata(RecordKeeper &RK, raw_ostream &OS) { - AutomatonEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass X("gen-automata", + "Generate generic automata"); -} // namespace llvm +} diff --git a/llvm/utils/TableGen/DFAPacketizerEmitter.cpp b/llvm/utils/TableGen/DFAPacketizerEmitter.cpp --- a/llvm/utils/TableGen/DFAPacketizerEmitter.cpp +++ b/llvm/utils/TableGen/DFAPacketizerEmitter.cpp @@ -206,6 +206,7 @@ // Run the worklist algorithm to generate the DFA. // void DFAPacketizerEmitter::run(raw_ostream &OS) { + emitSourceFileHeader("Target DFA Packetizer Tables", OS); OS << "\n" << "#include \"llvm/CodeGen/DFAPacketizer.h\"\n"; OS << "namespace llvm {\n"; @@ -353,11 +354,9 @@ << "\n}\n\n"; } -namespace llvm { +namespace { -void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS) { - emitSourceFileHeader("Target DFA Packetizer Tables", OS); - DFAPacketizerEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass + X("gen-dfa-packetizer", "Generate DFA Packetizer for VLIW targets"); -} // end namespace llvm +} diff --git a/llvm/utils/TableGen/DXILEmitter.cpp b/llvm/utils/TableGen/DXILEmitter.cpp --- a/llvm/utils/TableGen/DXILEmitter.cpp +++ b/llvm/utils/TableGen/DXILEmitter.cpp @@ -411,7 +411,7 @@ OS << "}\n "; } -namespace llvm { +namespace { void EmitDXILOperation(RecordKeeper &Records, raw_ostream &OS) { std::vector Ops = Records.getAllDerivedDefinitions("dxil_op"); @@ -439,4 +439,7 @@ OS << "\n"; } -} // namespace llvm +TableGen::Emitter::Opt X("gen-dxil-operation", EmitDXILOperation, + "Generate DXIL operation information"); + +} // namespace diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp --- a/llvm/utils/TableGen/DirectiveEmitter.cpp +++ b/llvm/utils/TableGen/DirectiveEmitter.cpp @@ -173,7 +173,7 @@ return HasDuplicateClausesInDirectives(getDirectives()); } -namespace llvm { +namespace { // Generate the declaration section for the enumeration in the directive // language @@ -246,10 +246,6 @@ OS << "#endif // LLVM_" << DirLang.getName() << "_INC\n"; } -} // namespace llvm - -namespace { - // Generate function implementation for getName(StringRef Str) void GenerateGetName(const std::vector &Records, raw_ostream &OS, StringRef Enum, const DirectiveLanguage &DirLang, @@ -874,10 +870,6 @@ GenerateIsAllowedClause(DirLang, OS); } -} // namespace - -namespace llvm { - // Generate the implemenation section for the enumeration in the directive // language. void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) { @@ -892,4 +884,11 @@ EmitDirectivesBasicImpl(DirLang, OS); } -} // namespace llvm +TableGen::Emitter::Opt + X("gen-directive-decl", EmitDirectivesDecl, + "Generate directive related declaration code (header file)"); + +TableGen::Emitter::Opt Y("gen-directive-impl", EmitDirectivesImpl, + "Generate directive related implementation code"); + +} // namespace diff --git a/llvm/utils/TableGen/DisassemblerEmitter.cpp b/llvm/utils/TableGen/DisassemblerEmitter.cpp --- a/llvm/utils/TableGen/DisassemblerEmitter.cpp +++ b/llvm/utils/TableGen/DisassemblerEmitter.cpp @@ -99,6 +99,10 @@ extern void EmitDecoder(RecordKeeper &RK, raw_ostream &OS, const std::string &PredicateNamespace); +} + +namespace { + void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { CodeGenTarget Target(Records); emitSourceFileHeader(" * " + Target.getName().str() + " Disassembler", OS); @@ -136,4 +140,7 @@ EmitDecoder(Records, OS, PredicateNamespace); } -} // end namespace llvm +TableGen::Emitter::Opt X("gen-disassembler", EmitDisassembler, + "Generate disassembler"); + +} // namespace diff --git a/llvm/utils/TableGen/ExegesisEmitter.cpp b/llvm/utils/TableGen/ExegesisEmitter.cpp --- a/llvm/utils/TableGen/ExegesisEmitter.cpp +++ b/llvm/utils/TableGen/ExegesisEmitter.cpp @@ -201,12 +201,7 @@ emitPfmCountersLookupTable(OS); } -} // end anonymous namespace +TableGen::Emitter::OptClass X("gen-exegesis", + "Generate llvm-exegesis tables"); -namespace llvm { - -void EmitExegesis(RecordKeeper &RK, raw_ostream &OS) { - ExegesisEmitter(RK).run(OS); -} - -} // end namespace llvm +} // namespace diff --git a/llvm/utils/TableGen/FastISelEmitter.cpp b/llvm/utils/TableGen/FastISelEmitter.cpp --- a/llvm/utils/TableGen/FastISelEmitter.cpp +++ b/llvm/utils/TableGen/FastISelEmitter.cpp @@ -858,7 +858,7 @@ // TODO: SignaturesWithConstantForms should be empty here. } -namespace llvm { +namespace { void EmitFastISel(RecordKeeper &RK, raw_ostream &OS) { CodeGenDAGPatterns CGP(RK); @@ -876,4 +876,7 @@ F.printFunctionDefinitions(OS); } -} // namespace llvm +TableGen::Emitter::Opt X("gen-fast-isel", EmitFastISel, + "Generate a \"fast\" instruction selector"); + +} // namespace diff --git a/llvm/utils/TableGen/GICombinerEmitter.cpp b/llvm/utils/TableGen/GICombinerEmitter.cpp --- a/llvm/utils/TableGen/GICombinerEmitter.cpp +++ b/llvm/utils/TableGen/GICombinerEmitter.cpp @@ -1063,11 +1063,8 @@ << "#endif // ifdef " << Name.upper() << "_GENCOMBINERHELPER_CPP\n"; } -} // end anonymous namespace - //===----------------------------------------------------------------------===// -namespace llvm { void EmitGICombiner(RecordKeeper &RK, raw_ostream &OS) { CodeGenTarget Target(RK); emitSourceFileHeader("Global Combiner", OS); @@ -1083,4 +1080,7 @@ NumPatternTotalStatistic = NumPatternTotal; } -} // namespace llvm +TableGen::Emitter::Opt X("gen-global-isel-combiner", EmitGICombiner, + "Generate GlobalISel combiner"); + +} // namespace diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -6359,12 +6359,9 @@ unsigned OperandMatcher::getInsnVarID() const { return Insn.getInsnVarID(); } -} // end anonymous namespace - //===----------------------------------------------------------------------===// -namespace llvm { -void EmitGlobalISel(RecordKeeper &RK, raw_ostream &OS) { - GlobalISelEmitter(RK).run(OS); -} -} // namespace llvm +TableGen::Emitter::OptClass + X("gen-global-isel", "Generate GlobalISel selector"); + +} // namespace diff --git a/llvm/utils/TableGen/InstrDocsEmitter.cpp b/llvm/utils/TableGen/InstrDocsEmitter.cpp --- a/llvm/utils/TableGen/InstrDocsEmitter.cpp +++ b/llvm/utils/TableGen/InstrDocsEmitter.cpp @@ -55,10 +55,6 @@ return Result; } -} // namespace - -namespace llvm { - void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) { CodeGenDAGPatterns CDP(RK); CodeGenTarget &Target = CDP.getTargetInfo(); @@ -220,4 +216,7 @@ } } -} // end namespace llvm +TableGen::Emitter::Opt X("gen-instr-docs", EmitInstrDocs, + "Generate instruction documentation"); + +} // namespace diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp --- a/llvm/utils/TableGen/InstrInfoEmitter.cpp +++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp @@ -1245,7 +1245,7 @@ OS << "#endif // GET_INSTRINFO_SCHED_ENUM\n\n"; } -namespace llvm { +namespace { void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { RK.startTimer("Analyze DAG patterns"); @@ -1254,4 +1254,7 @@ EmitMapTable(RK, OS); } -} // end namespace llvm +TableGen::Emitter::Opt X("gen-instr-info", EmitInstrInfo, + "Generate instruction descriptions"); + +} // namespace diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -967,10 +967,20 @@ OS << "#endif\n\n"; } -void llvm::EmitIntrinsicEnums(RecordKeeper &RK, raw_ostream &OS) { +namespace { + +void EmitIntrinsicEnums(RecordKeeper &RK, raw_ostream &OS) { IntrinsicEmitter(RK).run(OS, /*Enums=*/true); } -void llvm::EmitIntrinsicImpl(RecordKeeper &RK, raw_ostream &OS) { +TableGen::Emitter::Opt X("gen-intrinsic-enums", EmitIntrinsicEnums, + "Generate intrinsic enums"); + +void EmitIntrinsicImpl(RecordKeeper &RK, raw_ostream &OS) { IntrinsicEmitter(RK).run(OS, /*Enums=*/false); } + +TableGen::Emitter::Opt Y("gen-intrinsic-impl", EmitIntrinsicImpl, + "Generate intrinsic information"); + +} // namespace diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp --- a/llvm/utils/TableGen/OptParserEmitter.cpp +++ b/llvm/utils/TableGen/OptParserEmitter.cpp @@ -213,7 +213,7 @@ /// OptParserEmitter - This tablegen backend takes an input .td file /// describing a list of options and emits a data structure for parsing and /// working with those options when given an input command line. -namespace llvm { +namespace { void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) { // Get the option groups and options. const std::vector &Groups = @@ -500,4 +500,8 @@ OS << "\n"; } -} // end namespace llvm + +TableGen::Emitter::Opt X("gen-opt-parser-defs", EmitOptParser, + "Generate option definitions"); + +} // namespace diff --git a/llvm/utils/TableGen/OptRSTEmitter.cpp b/llvm/utils/TableGen/OptRSTEmitter.cpp --- a/llvm/utils/TableGen/OptRSTEmitter.cpp +++ b/llvm/utils/TableGen/OptRSTEmitter.cpp @@ -16,7 +16,7 @@ /// OptParserEmitter - This tablegen backend takes an input .td file /// describing a list of options and emits a RST man page. -namespace llvm { +namespace { void EmitOptRST(RecordKeeper &Records, raw_ostream &OS) { llvm::StringMap> OptionsByGroup; std::vector OptionsWithoutGroup; @@ -103,4 +103,7 @@ } } } -} // end namespace llvm + +TableGen::Emitter::Opt X("gen-opt-rst", EmitOptRST, "Generate option RST"); + +} // namespace diff --git a/llvm/utils/TableGen/PseudoLoweringEmitter.cpp b/llvm/utils/TableGen/PseudoLoweringEmitter.cpp --- a/llvm/utils/TableGen/PseudoLoweringEmitter.cpp +++ b/llvm/utils/TableGen/PseudoLoweringEmitter.cpp @@ -314,10 +314,9 @@ emitLoweringEmitter(o); } -namespace llvm { +namespace { -void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS) { - PseudoLoweringEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass + X("gen-pseudo-lowering", "Generate pseudo instruction lowering"); -} // namespace llvm +} diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp --- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp +++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp @@ -47,7 +47,9 @@ return (*ISAInfo)->toString(); } -void llvm::EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) { +namespace { + +void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) { OS << "#ifndef PROC\n" << "#define PROC(ENUM, NAME, DEFAULT_MARCH)\n" << "#endif\n\n"; @@ -80,3 +82,8 @@ OS << "\n#undef TUNE_PROC\n"; } + +TableGen::Emitter::Opt X("gen-riscv-target-def", EmitRISCVTargetDef, + "Generate the list of CPU for RISCV"); + +} // namespace diff --git a/llvm/utils/TableGen/RegisterBankEmitter.cpp b/llvm/utils/TableGen/RegisterBankEmitter.cpp --- a/llvm/utils/TableGen/RegisterBankEmitter.cpp +++ b/llvm/utils/TableGen/RegisterBankEmitter.cpp @@ -328,10 +328,9 @@ OS << "#endif // GET_TARGET_REGBANK_IMPL\n"; } -namespace llvm { +namespace { -void EmitRegisterBank(RecordKeeper &RK, raw_ostream &OS) { - RegisterBankEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass + X("gen-register-bank", "Generate registers bank descriptions"); -} // end namespace llvm +} diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp --- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp +++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp @@ -1909,10 +1909,9 @@ } } -namespace llvm { +namespace { -void EmitRegisterInfo(RecordKeeper &RK, raw_ostream &OS) { - RegisterInfoEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass + X("gen-register-info", "Generate registers and register classes info"); -} // end namespace llvm +} diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp --- a/llvm/utils/TableGen/SearchableTableEmitter.cpp +++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp @@ -823,10 +823,9 @@ OS << "#undef " << Guard << "\n"; } -namespace llvm { +namespace { -void EmitSearchableTables(RecordKeeper &RK, raw_ostream &OS) { - SearchableTableEmitter(RK).run(OS); -} +TableGen::Emitter::OptClass + X("gen-searchable-tables", "Generate generic binary-searchable table"); -} // namespace llvm +} diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp --- a/llvm/utils/TableGen/SubtargetEmitter.cpp +++ b/llvm/utils/TableGen/SubtargetEmitter.cpp @@ -70,7 +70,7 @@ } }; - const CodeGenTarget &TGT; + CodeGenTarget TGT; RecordKeeper &Records; CodeGenSchedModels &SchedModels; std::string Target; @@ -128,8 +128,8 @@ void ParseFeaturesFunction(raw_ostream &OS); public: - SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT) - : TGT(TGT), Records(R), SchedModels(TGT.getSchedModels()), + SubtargetEmitter(RecordKeeper &R) + : TGT(R), Records(R), SchedModels(TGT.getSchedModels()), Target(TGT.getName()) {} void run(raw_ostream &o); @@ -1985,11 +1985,9 @@ EmitMCInstrAnalysisPredicateFunctions(OS); } -namespace llvm { +namespace { -void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) { - CodeGenTarget CGTarget(RK); - SubtargetEmitter(RK, CGTarget).run(OS); -} +TableGen::Emitter::OptClass + X("gen-subtarget", "Generate subtarget enumerations"); -} // end namespace llvm +} diff --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/TableGen.cpp --- a/llvm/utils/TableGen/TableGen.cpp +++ b/llvm/utils/TableGen/TableGen.cpp @@ -13,6 +13,7 @@ #include "TableGenBackends.h" // Declares all backends. #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" +#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TableGen/Main.h" #include "llvm/TableGen/Record.h" @@ -23,48 +24,6 @@ using namespace llvm; -enum ActionType { - PrintRecords, - PrintDetailedRecords, - NullBackend, - DumpJSON, - GenEmitter, - GenRegisterInfo, - GenInstrInfo, - GenInstrDocs, - GenAsmWriter, - GenAsmMatcher, - GenDisassembler, - GenPseudoLowering, - GenCompressInst, - GenCallingConv, - GenDAGISel, - GenDFAPacketizer, - GenFastISel, - GenSubtarget, - GenIntrinsicEnums, - GenIntrinsicImpl, - PrintEnums, - PrintSets, - GenOptParserDefs, - GenOptRST, - GenCTags, - GenAttributes, - GenSearchableTables, - GenGlobalISel, - GenGICombiner, - GenX86EVEX2VEXTables, - GenX86FoldTables, - GenX86MnemonicTables, - GenRegisterBank, - GenExegesis, - GenAutomata, - GenDirectivesEnumDecl, - GenDirectivesEnumImpl, - GenDXILOperation, - GenRISCVTargetDef, -}; - namespace llvm { cl::opt EmitLongStrLiterals( "long-string-literals", @@ -74,223 +33,70 @@ cl::Hidden, cl::init(true)); } // end namespace llvm +namespace llvm { +namespace TableGen { +namespace Emitter { +ManagedStatic, OptCreatorT> Action; +void *OptCreatorT::call() { + return new cl::opt(cl::desc("Action to perform:")); +} +} // namespace Emitter +} // namespace TableGen +} // namespace llvm + namespace { -cl::opt Action( - cl::desc("Action to perform:"), - cl::values( - clEnumValN(PrintRecords, "print-records", - "Print all records to stdout (default)"), - clEnumValN(PrintDetailedRecords, "print-detailed-records", - "Print full details of all records to stdout"), - clEnumValN(NullBackend, "null-backend", - "Do nothing after parsing (useful for timing)"), - clEnumValN(DumpJSON, "dump-json", - "Dump all records as machine-readable JSON"), - clEnumValN(GenEmitter, "gen-emitter", "Generate machine code emitter"), - clEnumValN(GenRegisterInfo, "gen-register-info", - "Generate registers and register classes info"), - clEnumValN(GenInstrInfo, "gen-instr-info", - "Generate instruction descriptions"), - clEnumValN(GenInstrDocs, "gen-instr-docs", - "Generate instruction documentation"), - clEnumValN(GenCallingConv, "gen-callingconv", - "Generate calling convention descriptions"), - clEnumValN(GenAsmWriter, "gen-asm-writer", "Generate assembly writer"), - clEnumValN(GenDisassembler, "gen-disassembler", - "Generate disassembler"), - clEnumValN(GenPseudoLowering, "gen-pseudo-lowering", - "Generate pseudo instruction lowering"), - clEnumValN(GenCompressInst, "gen-compress-inst-emitter", - "Generate RISCV compressed instructions."), - clEnumValN(GenAsmMatcher, "gen-asm-matcher", - "Generate assembly instruction matcher"), - clEnumValN(GenDAGISel, "gen-dag-isel", - "Generate a DAG instruction selector"), - clEnumValN(GenDFAPacketizer, "gen-dfa-packetizer", - "Generate DFA Packetizer for VLIW targets"), - clEnumValN(GenFastISel, "gen-fast-isel", - "Generate a \"fast\" instruction selector"), - clEnumValN(GenSubtarget, "gen-subtarget", - "Generate subtarget enumerations"), - clEnumValN(GenIntrinsicEnums, "gen-intrinsic-enums", - "Generate intrinsic enums"), - clEnumValN(GenIntrinsicImpl, "gen-intrinsic-impl", - "Generate intrinsic information"), - clEnumValN(PrintEnums, "print-enums", "Print enum values for a class"), - clEnumValN(PrintSets, "print-sets", - "Print expanded sets for testing DAG exprs"), - clEnumValN(GenOptParserDefs, "gen-opt-parser-defs", - "Generate option definitions"), - clEnumValN(GenOptRST, "gen-opt-rst", "Generate option RST"), - clEnumValN(GenCTags, "gen-ctags", "Generate ctags-compatible index"), - clEnumValN(GenAttributes, "gen-attrs", "Generate attributes"), - clEnumValN(GenSearchableTables, "gen-searchable-tables", - "Generate generic binary-searchable table"), - clEnumValN(GenGlobalISel, "gen-global-isel", - "Generate GlobalISel selector"), - clEnumValN(GenGICombiner, "gen-global-isel-combiner", - "Generate GlobalISel combiner"), - clEnumValN(GenX86EVEX2VEXTables, "gen-x86-EVEX2VEX-tables", - "Generate X86 EVEX to VEX compress tables"), - clEnumValN(GenX86FoldTables, "gen-x86-fold-tables", - "Generate X86 fold tables"), - clEnumValN(GenX86MnemonicTables, "gen-x86-mnemonic-tables", - "Generate X86 mnemonic tables"), - clEnumValN(GenRegisterBank, "gen-register-bank", - "Generate registers bank descriptions"), - clEnumValN(GenExegesis, "gen-exegesis", - "Generate llvm-exegesis tables"), - clEnumValN(GenAutomata, "gen-automata", "Generate generic automata"), - clEnumValN(GenDirectivesEnumDecl, "gen-directive-decl", - "Generate directive related declaration code (header file)"), - clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl", - "Generate directive related implementation code"), - clEnumValN(GenDXILOperation, "gen-dxil-operation", - "Generate DXIL operation information"), - clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def", - "Generate the list of CPU for RISCV"))); + cl::OptionCategory PrintEnumsCat("Options for -print-enums"); cl::opt Class("class", cl::desc("Print Enum list for this class"), cl::value_desc("class name"), cl::cat(PrintEnumsCat)); -bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { - switch (Action) { - case PrintRecords: - OS << Records; // No argument, dump all contents - break; - case PrintDetailedRecords: - EmitDetailedRecords(Records, OS); - break; - case NullBackend: // No backend at all. - break; - case DumpJSON: - EmitJSON(Records, OS); - break; - case GenEmitter: - EmitCodeEmitter(Records, OS); - break; - case GenRegisterInfo: - EmitRegisterInfo(Records, OS); - break; - case GenInstrInfo: - EmitInstrInfo(Records, OS); - break; - case GenInstrDocs: - EmitInstrDocs(Records, OS); - break; - case GenCallingConv: - EmitCallingConv(Records, OS); - break; - case GenAsmWriter: - EmitAsmWriter(Records, OS); - break; - case GenAsmMatcher: - EmitAsmMatcher(Records, OS); - break; - case GenDisassembler: - EmitDisassembler(Records, OS); - break; - case GenPseudoLowering: - EmitPseudoLowering(Records, OS); - break; - case GenCompressInst: - EmitCompressInst(Records, OS); - break; - case GenDAGISel: - EmitDAGISel(Records, OS); - break; - case GenDFAPacketizer: - EmitDFAPacketizer(Records, OS); - break; - case GenFastISel: - EmitFastISel(Records, OS); - break; - case GenSubtarget: - EmitSubtarget(Records, OS); - break; - case GenIntrinsicEnums: - EmitIntrinsicEnums(Records, OS); - break; - case GenIntrinsicImpl: - EmitIntrinsicImpl(Records, OS); - break; - case GenOptParserDefs: - EmitOptParser(Records, OS); - break; - case GenOptRST: - EmitOptRST(Records, OS); - break; - case PrintEnums: { - for (Record *Rec : Records.getAllDerivedDefinitions(Class)) - OS << Rec->getName() << ", "; - OS << "\n"; - break; - } - case PrintSets: - { - SetTheory Sets; - Sets.addFieldExpander("Set", "Elements"); - for (Record *Rec : Records.getAllDerivedDefinitions("Set")) { - OS << Rec->getName() << " = ["; - const std::vector *Elts = Sets.expand(Rec); - assert(Elts && "Couldn't expand Set instance"); - for (Record *Elt : *Elts) - OS << ' ' << Elt->getName(); - OS << " ]\n"; - } - break; +void PrintRecords(RecordKeeper &Records, raw_ostream &OS) { + OS << Records; // No argument, dump all contents +} + +void PrintEnums(RecordKeeper &Records, raw_ostream &OS) { + for (Record *Rec : Records.getAllDerivedDefinitions(Class)) + OS << Rec->getName() << ", "; + OS << "\n"; +} + +void PrintSets(RecordKeeper &Records, raw_ostream &OS) { + SetTheory Sets; + Sets.addFieldExpander("Set", "Elements"); + for (Record *Rec : Records.getAllDerivedDefinitions("Set")) { + OS << Rec->getName() << " = ["; + const std::vector *Elts = Sets.expand(Rec); + assert(Elts && "Couldn't expand Set instance"); + for (Record *Elt : *Elts) + OS << ' ' << Elt->getName(); + OS << " ]\n"; } - case GenCTags: - EmitCTags(Records, OS); - break; - case GenAttributes: - EmitAttributes(Records, OS); - break; - case GenSearchableTables: - EmitSearchableTables(Records, OS); - break; - case GenGlobalISel: - EmitGlobalISel(Records, OS); - break; - case GenGICombiner: - EmitGICombiner(Records, OS); - break; - case GenRegisterBank: - EmitRegisterBank(Records, OS); - break; - case GenX86EVEX2VEXTables: - EmitX86EVEX2VEXTables(Records, OS); - break; - case GenX86MnemonicTables: - EmitX86MnemonicTables(Records, OS); - break; - case GenX86FoldTables: - EmitX86FoldTables(Records, OS); - break; - case GenExegesis: - EmitExegesis(Records, OS); - break; - case GenAutomata: - EmitAutomata(Records, OS); - break; - case GenDirectivesEnumDecl: - EmitDirectivesDecl(Records, OS); - break; - case GenDirectivesEnumImpl: - EmitDirectivesImpl(Records, OS); - break; - case GenDXILOperation: - EmitDXILOperation(Records, OS); - break; - case GenRISCVTargetDef: - EmitRISCVTargetDef(Records, OS); - break; +} + +bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { + if (TableGen::Emitter::Action->getValue()) { + (TableGen::Emitter::Action->getValue())(Records, OS); + return false; } + PrintRecords(Records, OS); + return false; } -} + +TableGen::Emitter::Opt X[] = { + {"print-records", PrintRecords, "Print all records to stdout (default)"}, + {"print-detailed-records", EmitDetailedRecords, + "Print full details of all records to stdout"}, + {"null-backend", [](RecordKeeper &Records, raw_ostream &OS) {}, + "Do nothing after parsing (useful for timing)"}, + {"dump-json", EmitJSON, "Dump all records as machine-readable JSON"}, + {"print-enums", PrintEnums, "Print enum values for a class"}, + {"print-sets", PrintSets, "Print expanded sets for testing DAG exprs"}, +}; + +} // namespace int main(int argc, char **argv) { InitLLVM X(argc, argv); diff --git a/llvm/utils/TableGen/TableGenBackends.h b/llvm/utils/TableGen/TableGenBackends.h --- a/llvm/utils/TableGen/TableGenBackends.h +++ b/llvm/utils/TableGen/TableGenBackends.h @@ -15,6 +15,10 @@ #ifndef LLVM_UTILS_TABLEGEN_TABLEGENBACKENDS_H #define LLVM_UTILS_TABLEGEN_TABLEGENBACKENDS_H +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/ManagedStatic.h" + // A TableGen backend is a function that looks like // // EmitFoo(RecordKeeper &RK, raw_ostream &OS /*, anything else you need */ ) @@ -61,40 +65,33 @@ class raw_ostream; class RecordKeeper; -void EmitIntrinsicEnums(RecordKeeper &RK, raw_ostream &OS); -void EmitIntrinsicImpl(RecordKeeper &RK, raw_ostream &OS); -void EmitAsmMatcher(RecordKeeper &RK, raw_ostream &OS); -void EmitAsmWriter(RecordKeeper &RK, raw_ostream &OS); -void EmitCallingConv(RecordKeeper &RK, raw_ostream &OS); -void EmitCodeEmitter(RecordKeeper &RK, raw_ostream &OS); -void EmitDAGISel(RecordKeeper &RK, raw_ostream &OS); -void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS); -void EmitDisassembler(RecordKeeper &RK, raw_ostream &OS); -void EmitFastISel(RecordKeeper &RK, raw_ostream &OS); -void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS); -void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS); -void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS); -void EmitCompressInst(RecordKeeper &RK, raw_ostream &OS); -void EmitRegisterInfo(RecordKeeper &RK, raw_ostream &OS); -void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS); +namespace TableGen { +namespace Emitter { +using FnT = void (*)(RecordKeeper &Records, raw_ostream &OS); + +struct OptCreatorT { + static void *call(); +}; + +extern ManagedStatic, OptCreatorT> Action; + +struct Opt { + Opt(StringRef p, FnT fn, StringRef desc) { + Action->getParser().addLiteralOption(p, fn, desc); + } +}; + +template class OptClass : Opt { + static void run(RecordKeeper &RK, raw_ostream &OS) { EmitterC(RK).run(OS); } + +public: + OptClass(StringRef p, StringRef d) : Opt(p, run, d) {} +}; + +} // namespace Emitter +} // namespace TableGen + void EmitMapTable(RecordKeeper &RK, raw_ostream &OS); -void EmitOptParser(RecordKeeper &RK, raw_ostream &OS); -void EmitOptRST(RecordKeeper &RK, raw_ostream &OS); -void EmitCTags(RecordKeeper &RK, raw_ostream &OS); -void EmitAttributes(RecordKeeper &RK, raw_ostream &OS); -void EmitSearchableTables(RecordKeeper &RK, raw_ostream &OS); -void EmitGlobalISel(RecordKeeper &RK, raw_ostream &OS); -void EmitGICombiner(RecordKeeper &RK, raw_ostream &OS); -void EmitX86EVEX2VEXTables(RecordKeeper &RK, raw_ostream &OS); -void EmitX86FoldTables(RecordKeeper &RK, raw_ostream &OS); -void EmitX86MnemonicTables(RecordKeeper &RK, raw_ostream &OS); -void EmitRegisterBank(RecordKeeper &RK, raw_ostream &OS); -void EmitExegesis(RecordKeeper &RK, raw_ostream &OS); -void EmitAutomata(RecordKeeper &RK, raw_ostream &OS); -void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS); -void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS); -void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS); -void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS); } // End llvm namespace diff --git a/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp b/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp --- a/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp +++ b/llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp @@ -239,10 +239,8 @@ // Print CheckVEXInstPredicate function. printCheckPredicate(EVEX2VEXPredicates, OS); } -} // namespace -namespace llvm { -void EmitX86EVEX2VEXTables(RecordKeeper &RK, raw_ostream &OS) { - X86EVEX2VEXTablesEmitter(RK).run(OS); -} -} // namespace llvm +TableGen::Emitter::OptClass + X("gen-x86-EVEX2VEX-tables", "Generate X86 EVEX to VEX compress tables"); + +} // namespace diff --git a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp --- a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp +++ b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp @@ -165,7 +165,7 @@ X86FoldTablesEmitter(RecordKeeper &R) : Records(R), Target(R) {} // run - Generate the 6 X86 memory fold tables. - void run(formatted_raw_ostream &OS); + void run(raw_ostream &OS); private: // Decides to which table to add the entry with the given instructions. @@ -512,7 +512,8 @@ } } -void X86FoldTablesEmitter::run(formatted_raw_ostream &OS) { +void X86FoldTablesEmitter::run(raw_ostream &o) { + formatted_raw_ostream OS(o); emitSourceFileHeader("X86 fold tables", OS); // Holds all memory instructions @@ -611,10 +612,9 @@ printTable(Table4, "Table4", OS); } -namespace llvm { +namespace { + +TableGen::Emitter::OptClass X("gen-x86-fold-tables", + "Generate X86 fold tables"); -void EmitX86FoldTables(RecordKeeper &RK, raw_ostream &o) { - formatted_raw_ostream OS(o); - X86FoldTablesEmitter(RK).run(OS); } -} // namespace llvm diff --git a/llvm/utils/TableGen/X86MnemonicTables.cpp b/llvm/utils/TableGen/X86MnemonicTables.cpp --- a/llvm/utils/TableGen/X86MnemonicTables.cpp +++ b/llvm/utils/TableGen/X86MnemonicTables.cpp @@ -86,10 +86,7 @@ OS << "} // end namespace X86\n} // end namespace llvm"; } -} // namespace +TableGen::Emitter::OptClass + X("gen-x86-mnemonic-tables", "Generate X86 mnemonic tables"); -namespace llvm { -void EmitX86MnemonicTables(RecordKeeper &RK, raw_ostream &OS) { - X86MnemonicTablesEmitter(RK).run(OS); -} -} // namespace llvm +} // namespace