12 changes: 3 additions & 9 deletions llvm/utils/TableGen/DAGISelEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "DAGISelMatcher.h"
#include "TableGenBackends.h"
#include "llvm/Support/Debug.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
Expand Down Expand Up @@ -125,6 +124,7 @@ struct PatternSortingPredicate {


void DAGISelEmitter::run(raw_ostream &OS) {
Records.startTimer("Parse patterns");
emitSourceFileHeader("DAG Instruction Selector for the " +
CGP.getTargetInfo().getName().str() + " target", OS);

Expand Down Expand Up @@ -187,11 +187,5 @@ void DAGISelEmitter::run(raw_ostream &OS) {
EmitMatcherTable(TheMatcher.get(), CGP, OS);
}

namespace llvm {

void EmitDAGISel(RecordKeeper &RK, raw_ostream &OS) {
RK.startTimer("Parse patterns");
DAGISelEmitter(RK).run(OS);
}

} // namespace llvm
static TableGen::Emitter::OptClass<DAGISelEmitter>
X("gen-dag-isel", "Generate a DAG instruction selector");
11 changes: 3 additions & 8 deletions llvm/utils/TableGen/DFAEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

#include "DFAEmitter.h"
#include "SequenceToOffsetTable.h"
#include "TableGenBackends.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/UniqueVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <cassert>
#include <cstdint>
#include <deque>
Expand Down Expand Up @@ -370,10 +370,5 @@ void CustomDfaEmitter::printActionValue(action_type A, raw_ostream &OS) {
OS << ")";
}

namespace llvm {

void EmitAutomata(RecordKeeper &RK, raw_ostream &OS) {
AutomatonEmitter(RK).run(OS);
}

} // namespace llvm
static TableGen::Emitter::OptClass<AutomatonEmitter>
X("gen-automata", "Generate generic automata");
12 changes: 3 additions & 9 deletions llvm/utils/TableGen/DFAPacketizerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "CodeGenSchedule.h"
#include "CodeGenTarget.h"
#include "DFAEmitter.h"
#include "TableGenBackends.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -206,6 +205,7 @@ void DFAPacketizerEmitter::createScheduleClasses(unsigned ItineraryIdx,
// 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";
Expand Down Expand Up @@ -353,11 +353,5 @@ void DFAPacketizerEmitter::emitForItineraries(
<< "\n}\n\n";
}

namespace llvm {

void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS) {
emitSourceFileHeader("Target DFA Packetizer Tables", OS);
DFAPacketizerEmitter(RK).run(OS);
}

} // end namespace llvm
static TableGen::Emitter::OptClass<DFAPacketizerEmitter>
X("gen-dfa-packetizer", "Generate DFA Packetizer for VLIW targets");
9 changes: 4 additions & 5 deletions llvm/utils/TableGen/DXILEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
//===----------------------------------------------------------------------===//

#include "SequenceToOffsetTable.h"
#include "TableGenBackends.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/DXILOperationCommon.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"

using namespace llvm;
using namespace llvm::dxil;
Expand Down Expand Up @@ -411,9 +411,7 @@ static void emitDXILOperationTable(std::vector<DXILOperationData> &DXILOps,
OS << "}\n ";
}

namespace llvm {

void EmitDXILOperation(RecordKeeper &Records, raw_ostream &OS) {
static void EmitDXILOperation(RecordKeeper &Records, raw_ostream &OS) {
std::vector<Record *> Ops = Records.getAllDerivedDefinitions("dxil_op");
OS << "// Generated code, do not edit.\n";
OS << "\n";
Expand All @@ -439,4 +437,5 @@ void EmitDXILOperation(RecordKeeper &Records, raw_ostream &OS) {
OS << "\n";
}

} // namespace llvm
static TableGen::Emitter::Opt X("gen-dxil-operation", EmitDXILOperation,
"Generate DXIL operation information");
1 change: 1 addition & 0 deletions llvm/utils/TableGen/DecoderEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "InfoByHwMode.h"
#include "TableGenBackends.h"
#include "VarLenCodeEmitterGen.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
Expand Down
20 changes: 10 additions & 10 deletions llvm/utils/TableGen/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
//===----------------------------------------------------------------------===//

#include "llvm/TableGen/DirectiveEmitter.h"
#include "TableGenBackends.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"

using namespace llvm;

Expand Down Expand Up @@ -174,11 +174,9 @@ bool DirectiveLanguage::HasValidityErrors() const {
return HasDuplicateClausesInDirectives(getDirectives());
}

namespace llvm {

// Generate the declaration section for the enumeration in the directive
// language
void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
static void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
const auto DirLang = DirectiveLanguage{Records};
if (DirLang.HasValidityErrors())
return;
Expand Down Expand Up @@ -247,8 +245,6 @@ void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
OS << "#endif // LLVM_" << DirLang.getName() << "_INC\n";
}

} // namespace llvm

// Generate function implementation for get<Enum>Name(StringRef Str)
static void GenerateGetName(const std::vector<Record *> &Records,
raw_ostream &OS, StringRef Enum,
Expand Down Expand Up @@ -877,11 +873,9 @@ void EmitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
GenerateIsAllowedClause(DirLang, OS);
}

namespace llvm {

// Generate the implemenation section for the enumeration in the directive
// language.
void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
static void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
const auto DirLang = DirectiveLanguage{Records};
if (DirLang.HasValidityErrors())
return;
Expand All @@ -893,4 +887,10 @@ void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
EmitDirectivesBasicImpl(DirLang, OS);
}

} // namespace llvm
static TableGen::Emitter::Opt
X("gen-directive-decl", EmitDirectivesDecl,
"Generate directive related declaration code (header file)");

static TableGen::Emitter::Opt
Y("gen-directive-impl", EmitDirectivesImpl,
"Generate directive related implementation code");
10 changes: 3 additions & 7 deletions llvm/utils/TableGen/DisassemblerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ using namespace llvm::X86Disassembler;
/// X86RecognizableInstr.cpp contains the implementation for a single
/// instruction.

namespace llvm {

extern void EmitDecoder(RecordKeeper &RK, raw_ostream &OS,
const std::string &PredicateNamespace);

void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) {
static void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) {
CodeGenTarget Target(Records);
emitSourceFileHeader(" * " + Target.getName().str() + " Disassembler", OS);

Expand Down Expand Up @@ -136,4 +131,5 @@ void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) {
EmitDecoder(Records, OS, PredicateNamespace);
}

} // end namespace llvm
static TableGen::Emitter::Opt X("gen-disassembler", EmitDisassembler,
"Generate disassembler");
10 changes: 2 additions & 8 deletions llvm/utils/TableGen/ExegesisEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

#include "TableGenBackends.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringRef.h"
Expand Down Expand Up @@ -203,10 +202,5 @@ void ExegesisEmitter::run(raw_ostream &OS) const {

} // end anonymous namespace

namespace llvm {

void EmitExegesis(RecordKeeper &RK, raw_ostream &OS) {
ExegesisEmitter(RK).run(OS);
}

} // end namespace llvm
static TableGen::Emitter::OptClass<ExegesisEmitter>
X("gen-exegesis", "Generate llvm-exegesis tables");
8 changes: 3 additions & 5 deletions llvm/utils/TableGen/FastISelEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "CodeGenRegisters.h"
#include "CodeGenTarget.h"
#include "InfoByHwMode.h"
#include "TableGenBackends.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/TableGen/Error.h"
Expand Down Expand Up @@ -858,9 +857,7 @@ void FastISelMap::printFunctionDefinitions(raw_ostream &OS) {
// TODO: SignaturesWithConstantForms should be empty here.
}

namespace llvm {

void EmitFastISel(RecordKeeper &RK, raw_ostream &OS) {
static void EmitFastISel(RecordKeeper &RK, raw_ostream &OS) {
CodeGenDAGPatterns CGP(RK);
const CodeGenTarget &Target = CGP.getTargetInfo();
emitSourceFileHeader("\"Fast\" Instruction Selector for the " +
Expand All @@ -876,4 +873,5 @@ void EmitFastISel(RecordKeeper &RK, raw_ostream &OS) {
F.printFunctionDefinitions(OS);
}

} // namespace llvm
static TableGen::Emitter::Opt X("gen-fast-isel", EmitFastISel,
"Generate a \"fast\" instruction selector");
7 changes: 3 additions & 4 deletions llvm/utils/TableGen/GICombinerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "GlobalISel/GIMatchDagOperands.h"
#include "GlobalISel/GIMatchDagPredicate.h"
#include "GlobalISel/GIMatchTree.h"
#include "TableGenBackends.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringSet.h"
Expand Down Expand Up @@ -1067,8 +1066,7 @@ void GICombinerEmitter::run(raw_ostream &OS) {

//===----------------------------------------------------------------------===//

namespace llvm {
void EmitGICombiner(RecordKeeper &RK, raw_ostream &OS) {
static void EmitGICombiner(RecordKeeper &RK, raw_ostream &OS) {
CodeGenTarget Target(RK);
emitSourceFileHeader("Global Combiner", OS);

Expand All @@ -1083,4 +1081,5 @@ void EmitGICombiner(RecordKeeper &RK, raw_ostream &OS) {
NumPatternTotalStatistic = NumPatternTotal;
}

} // namespace llvm
static TableGen::Emitter::Opt X("gen-global-isel-combiner", EmitGICombiner,
"Generate GlobalISel combiner");
8 changes: 2 additions & 6 deletions llvm/utils/TableGen/GlobalISelEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "CodeGenTarget.h"
#include "InfoByHwMode.h"
#include "SubtargetFeatureInfo.h"
#include "TableGenBackends.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/CodeGenCoverage.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -6363,8 +6362,5 @@ unsigned OperandMatcher::getInsnVarID() const { return Insn.getInsnVarID(); }

//===----------------------------------------------------------------------===//

namespace llvm {
void EmitGlobalISel(RecordKeeper &RK, raw_ostream &OS) {
GlobalISelEmitter(RK).run(OS);
}
} // namespace llvm
static TableGen::Emitter::OptClass<GlobalISelEmitter>
X("gen-global-isel", "Generate GlobalISel selector");
9 changes: 4 additions & 5 deletions llvm/utils/TableGen/InstrDocsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "CodeGenDAGPatterns.h"
#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "TableGenBackends.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <string>
#include <vector>

Expand Down Expand Up @@ -54,9 +54,7 @@ static std::string escapeForRST(StringRef Str) {
return Result;
}

namespace llvm {

void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
static void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
CodeGenDAGPatterns CDP(RK);
CodeGenTarget &Target = CDP.getTargetInfo();
unsigned VariantCount = Target.getAsmParserVariantCount();
Expand Down Expand Up @@ -217,4 +215,5 @@ void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
}
}

} // end namespace llvm
static TableGen::Emitter::Opt X("gen-instr-docs", EmitInstrDocs,
"Generate instruction documentation");
7 changes: 3 additions & 4 deletions llvm/utils/TableGen/InstrInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,13 +1245,12 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
OS << "#endif // GET_INSTRINFO_SCHED_ENUM\n\n";
}

namespace llvm {

void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) {
static void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) {
RK.startTimer("Analyze DAG patterns");
InstrInfoEmitter(RK).run(OS);
RK.startTimer("Emit map table");
EmitMapTable(RK, OS);
}

} // end namespace llvm
static TableGen::Emitter::Opt X("gen-instr-info", EmitInstrInfo,
"Generate instruction descriptions");
11 changes: 8 additions & 3 deletions llvm/utils/TableGen/IntrinsicEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "CodeGenIntrinsics.h"
#include "SequenceToOffsetTable.h"
#include "TableGenBackends.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
Expand Down Expand Up @@ -967,10 +966,16 @@ void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(
OS << "#endif\n\n";
}

void llvm::EmitIntrinsicEnums(RecordKeeper &RK, raw_ostream &OS) {
static void EmitIntrinsicEnums(RecordKeeper &RK, raw_ostream &OS) {
IntrinsicEmitter(RK).run(OS, /*Enums=*/true);
}

void llvm::EmitIntrinsicImpl(RecordKeeper &RK, raw_ostream &OS) {
static TableGen::Emitter::Opt X("gen-intrinsic-enums", EmitIntrinsicEnums,
"Generate intrinsic enums");

static void EmitIntrinsicImpl(RecordKeeper &RK, raw_ostream &OS) {
IntrinsicEmitter(RK).run(OS, /*Enums=*/false);
}

static TableGen::Emitter::Opt Y("gen-intrinsic-impl", EmitIntrinsicImpl,
"Generate intrinsic information");
8 changes: 4 additions & 4 deletions llvm/utils/TableGen/OptParserEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//

#include "OptEmitter.h"
#include "TableGenBackends.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
Expand Down Expand Up @@ -213,8 +212,7 @@ static MarshallingInfo createMarshallingInfo(const Record &R) {
/// 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 {
void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
static void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
// Get the option groups and options.
const std::vector<Record*> &Groups =
Records.getAllDerivedDefinitions("OptionGroup");
Expand Down Expand Up @@ -500,4 +498,6 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {

OS << "\n";
}
} // end namespace llvm

static TableGen::Emitter::Opt X("gen-opt-parser-defs", EmitOptParser,
"Generate option definitions");
9 changes: 5 additions & 4 deletions llvm/utils/TableGen/OptRSTEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
//===----------------------------------------------------------------------===//

#include "OptEmitter.h"
#include "TableGenBackends.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"

using namespace llvm;

/// OptParserEmitter - This tablegen backend takes an input .td file
/// describing a list of options and emits a RST man page.
namespace llvm {
void EmitOptRST(RecordKeeper &Records, raw_ostream &OS) {
static void EmitOptRST(RecordKeeper &Records, raw_ostream &OS) {
llvm::StringMap<std::vector<Record *>> OptionsByGroup;
std::vector<Record *> OptionsWithoutGroup;

Expand Down Expand Up @@ -103,4 +102,6 @@ void EmitOptRST(RecordKeeper &Records, raw_ostream &OS) {
}
}
}
} // end namespace llvm

static TableGen::Emitter::Opt X("gen-opt-rst", EmitOptRST,
"Generate option RST");
10 changes: 2 additions & 8 deletions llvm/utils/TableGen/PseudoLoweringEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "TableGenBackends.h"
#include "llvm/ADT/IndexedMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
Expand Down Expand Up @@ -314,10 +313,5 @@ void PseudoLoweringEmitter::run(raw_ostream &o) {
emitLoweringEmitter(o);
}

namespace llvm {

void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS) {
PseudoLoweringEmitter(RK).run(OS);
}

} // namespace llvm
static TableGen::Emitter::OptClass<PseudoLoweringEmitter>
X("gen-pseudo-lowering", "Generate pseudo instruction lowering");
7 changes: 5 additions & 2 deletions llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
//
//===----------------------------------------------------------------------===//

#include "TableGenBackends.h"
#include "llvm/Support/RISCVISAInfo.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"

using namespace llvm;

Expand Down Expand Up @@ -47,7 +47,7 @@ static std::string getMArch(const Record &Rec) {
return (*ISAInfo)->toString();
}

void llvm::EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
OS << "#ifndef PROC\n"
<< "#define PROC(ENUM, NAME, DEFAULT_MARCH)\n"
<< "#endif\n\n";
Expand Down Expand Up @@ -80,3 +80,6 @@ void llvm::EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {

OS << "\n#undef TUNE_PROC\n";
}

static TableGen::Emitter::Opt X("gen-riscv-target-def", EmitRISCVTargetDef,
"Generate the list of CPU for RISCV");
10 changes: 2 additions & 8 deletions llvm/utils/TableGen/RegisterBankEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "CodeGenRegisters.h"
#include "CodeGenTarget.h"
#include "InfoByHwMode.h"
#include "TableGenBackends.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/TableGen/Error.h"
Expand Down Expand Up @@ -328,10 +327,5 @@ void RegisterBankEmitter::run(raw_ostream &OS) {
OS << "#endif // GET_TARGET_REGBANK_IMPL\n";
}

namespace llvm {

void EmitRegisterBank(RecordKeeper &RK, raw_ostream &OS) {
RegisterBankEmitter(RK).run(OS);
}

} // end namespace llvm
static TableGen::Emitter::OptClass<RegisterBankEmitter>
X("gen-register-bank", "Generate registers bank descriptions");
10 changes: 2 additions & 8 deletions llvm/utils/TableGen/RegisterInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "CodeGenTarget.h"
#include "InfoByHwMode.h"
#include "SequenceToOffsetTable.h"
#include "TableGenBackends.h"
#include "Types.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
Expand Down Expand Up @@ -1909,10 +1908,5 @@ void RegisterInfoEmitter::debugDump(raw_ostream &OS) {
}
}

namespace llvm {

void EmitRegisterInfo(RecordKeeper &RK, raw_ostream &OS) {
RegisterInfoEmitter(RK).run(OS);
}

} // end namespace llvm
static TableGen::Emitter::OptClass<RegisterInfoEmitter>
X("gen-register-info", "Generate registers and register classes info");
11 changes: 3 additions & 8 deletions llvm/utils/TableGen/SearchableTableEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
//===----------------------------------------------------------------------===//

#include "CodeGenIntrinsics.h"
#include "TableGenBackends.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <algorithm>
#include <set>
#include <string>
Expand Down Expand Up @@ -823,10 +823,5 @@ void SearchableTableEmitter::run(raw_ostream &OS) {
OS << "#undef " << Guard << "\n";
}

namespace llvm {

void EmitSearchableTables(RecordKeeper &RK, raw_ostream &OS) {
SearchableTableEmitter(RK).run(OS);
}

} // namespace llvm
static TableGen::Emitter::OptClass<SearchableTableEmitter>
X("gen-searchable-tables", "Generate generic binary-searchable table");
17 changes: 5 additions & 12 deletions llvm/utils/TableGen/SubtargetEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "CodeGenSchedule.h"
#include "CodeGenTarget.h"
#include "PredicateExpander.h"
#include "TableGenBackends.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringExtras.h"
Expand Down Expand Up @@ -70,7 +69,7 @@ class SubtargetEmitter {
}
};

const CodeGenTarget &TGT;
CodeGenTarget TGT;
RecordKeeper &Records;
CodeGenSchedModels &SchedModels;
std::string Target;
Expand Down Expand Up @@ -128,8 +127,8 @@ class SubtargetEmitter {
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);
Expand Down Expand Up @@ -1985,11 +1984,5 @@ void SubtargetEmitter::run(raw_ostream &OS) {
EmitMCInstrAnalysisPredicateFunctions(OS);
}

namespace llvm {

void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) {
CodeGenTarget CGTarget(RK);
SubtargetEmitter(RK, CGTarget).run(OS);
}

} // end namespace llvm
static TableGen::Emitter::OptClass<SubtargetEmitter>
X("gen-subtarget", "Generate subtarget enumerations");
289 changes: 37 additions & 252 deletions llvm/utils/TableGen/TableGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,20 @@
//
//===----------------------------------------------------------------------===//

#include "TableGenBackends.h" // Declares all backends.
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Main.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/SetTheory.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <cassert>
#include <string>
#include <vector>

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<bool> EmitLongStrLiterals(
"long-string-literals",
Expand All @@ -75,228 +34,54 @@ cl::opt<bool> EmitLongStrLiterals(
} // end namespace llvm

namespace {
cl::opt<ActionType> 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<std::string> 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<Record*> *Elts = Sets.expand(Rec);
assert(Elts && "Couldn't expand Set instance");
for (Record *Elt : *Elts)
OS << ' ' << Elt->getName();
OS << " ]\n";
}
break;
}
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;
}
void PrintRecords(RecordKeeper &Records, raw_ostream &OS) {
OS << Records; // No argument, dump all contents
}

return false;
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<Record *> *Elts = Sets.expand(Rec);
assert(Elts && "Couldn't expand Set instance");
for (Record *Elt : *Elts)
OS << ' ' << Elt->getName();
OS << " ]\n";
}
}

TableGen::Emitter::Opt X[] = {
{"print-records", PrintRecords, "Print all records to stdout (default)",
true},
{"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);
cl::ParseCommandLineOptions(argc, argv);

return TableGenMain(argv[0], &LLVMTableGenMain);
return TableGenMain(argv[0]);
}

#ifndef __has_feature
Expand Down
41 changes: 7 additions & 34 deletions llvm/utils/TableGen/TableGenBackends.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef LLVM_UTILS_TABLEGEN_TABLEGENBACKENDS_H
#define LLVM_UTILS_TABLEGEN_TABLEGENBACKENDS_H

#include <string>

// A TableGen backend is a function that looks like
//
// EmitFoo(RecordKeeper &RK, raw_ostream &OS /*, anything else you need */ )
Expand Down Expand Up @@ -61,41 +63,12 @@ namespace llvm {
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);
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
// Defined in DecoderEmitter.cpp
void EmitDecoder(RecordKeeper &RK, raw_ostream &OS,
const std::string &PredicateNamespace);

} // namespace llvm

#endif
8 changes: 2 additions & 6 deletions llvm/utils/TableGen/X86EVEX2VEXTablesEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "TableGenBackends.h"
#include "X86RecognizableInstr.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
Expand Down Expand Up @@ -241,8 +240,5 @@ void X86EVEX2VEXTablesEmitter::run(raw_ostream &OS) {
}
} // namespace

namespace llvm {
void EmitX86EVEX2VEXTables(RecordKeeper &RK, raw_ostream &OS) {
X86EVEX2VEXTablesEmitter(RK).run(OS);
}
} // namespace llvm
static TableGen::Emitter::OptClass<X86EVEX2VEXTablesEmitter>
X("gen-x86-EVEX2VEX-tables", "Generate X86 EVEX to VEX compress tables");
15 changes: 5 additions & 10 deletions llvm/utils/TableGen/X86FoldTablesEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "TableGenBackends.h"
#include "X86RecognizableInstr.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/FormattedStream.h"
Expand Down Expand Up @@ -141,7 +140,7 @@ class X86FoldTablesEmitter {
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.
Expand Down Expand Up @@ -522,7 +521,8 @@ void X86FoldTablesEmitter::updateTables(const CodeGenInstruction *RegInstr,
}
}

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
Expand Down Expand Up @@ -613,10 +613,5 @@ void X86FoldTablesEmitter::run(formatted_raw_ostream &OS) {
printTable(Table4, "Table4", OS);
}

namespace llvm {

void EmitX86FoldTables(RecordKeeper &RK, raw_ostream &o) {
formatted_raw_ostream OS(o);
X86FoldTablesEmitter(RK).run(OS);
}
} // namespace llvm
static TableGen::Emitter::OptClass<X86FoldTablesEmitter>
X("gen-x86-fold-tables", "Generate X86 fold tables");
8 changes: 2 additions & 6 deletions llvm/utils/TableGen/X86MnemonicTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "TableGenBackends.h"
#include "X86RecognizableInstr.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
Expand Down Expand Up @@ -88,8 +87,5 @@ void X86MnemonicTablesEmitter::run(raw_ostream &OS) {

} // namespace

namespace llvm {
void EmitX86MnemonicTables(RecordKeeper &RK, raw_ostream &OS) {
X86MnemonicTablesEmitter(RK).run(OS);
}
} // namespace llvm
static TableGen::Emitter::OptClass<X86MnemonicTablesEmitter>
X("gen-x86-mnemonic-tables", "Generate X86 mnemonic tables");