diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt --- a/llvm/utils/TableGen/CMakeLists.txt +++ b/llvm/utils/TableGen/CMakeLists.txt @@ -22,13 +22,13 @@ DAGISelMatcherGen.cpp DAGISelMatcherOpt.cpp DAGISelMatcher.cpp + DecoderEmitter.cpp DFAEmitter.cpp DFAPacketizerEmitter.cpp DirectiveEmitter.cpp DisassemblerEmitter.cpp ExegesisEmitter.cpp FastISelEmitter.cpp - FixedLenDecoderEmitter.cpp GICombinerEmitter.cpp GlobalISelEmitter.cpp InfoByHwMode.cpp diff --git a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp rename from llvm/utils/TableGen/FixedLenDecoderEmitter.cpp rename to llvm/utils/TableGen/DecoderEmitter.cpp --- a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp +++ b/llvm/utils/TableGen/DecoderEmitter.cpp @@ -1,4 +1,4 @@ -//===------------ FixedLenDecoderEmitter.cpp - Decoder Generator ----------===// +//===------------ DecoderEmitter.cpp - Decoder Generator ----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// // // It contains the tablegen backend that emits the decoder functions for -// targets with fixed length instruction set. +// targets with fixed/variable length instruction set. // //===----------------------------------------------------------------------===// @@ -122,14 +122,14 @@ return OS; } -class FixedLenDecoderEmitter { +class DecoderEmitter { RecordKeeper &RK; std::vector NumberedEncodings; public: // Defaults preserved here for documentation, even though they aren't // strictly necessary given the way that this is currently being called. - FixedLenDecoderEmitter(RecordKeeper &R, std::string PredicateNamespace, + DecoderEmitter(RecordKeeper &R, std::string PredicateNamespace, std::string GPrefix = "if (", std::string GPostfix = " == MCDisassembler::Fail)", std::string ROK = "MCDisassembler::Success", @@ -411,13 +411,13 @@ unsigned BitWidth; // Parent emitter - const FixedLenDecoderEmitter *Emitter; + const DecoderEmitter *Emitter; public: FilterChooser(ArrayRef Insts, const std::vector &IDs, const std::map> &Ops, - unsigned BW, const FixedLenDecoderEmitter *E) + unsigned BW, const DecoderEmitter *E) : AllInstructions(Insts), Opcodes(IDs), Operands(Ops), FilterBitValues(BW, BIT_UNFILTERED), Parent(nullptr), BestIndex(-1), BitWidth(BW), Emitter(E) { @@ -771,7 +771,7 @@ ////////////////////////////////// // Emit the decoder state machine table. -void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, +void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, unsigned Indentation, unsigned BitWidth, @@ -960,7 +960,7 @@ OS.indent(Indentation) << "};\n\n"; } -void FixedLenDecoderEmitter::emitInstrLenTable( +void DecoderEmitter::emitInstrLenTable( formatted_raw_ostream &OS, std::vector &InstrLen) const { OS << "static const uint8_t InstrLenTable[] = {\n"; for (unsigned &Len : InstrLen) { @@ -969,7 +969,7 @@ OS << "};\n\n"; } -void FixedLenDecoderEmitter:: +void DecoderEmitter:: emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, unsigned Indentation) const { // The predicate function is just a big switch statement based on the @@ -994,7 +994,7 @@ OS.indent(Indentation) << "}\n\n"; } -void FixedLenDecoderEmitter:: +void DecoderEmitter:: emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, unsigned Indentation) const { // The decoder function is just a big switch statement based on the @@ -2518,7 +2518,7 @@ } // Emits disassembler code for instruction decoding. -void FixedLenDecoderEmitter::run(raw_ostream &o) { +void DecoderEmitter::run(raw_ostream &o) { formatted_raw_ostream OS(o); OS << "#include \"llvm/MC/MCInst.h\"\n"; OS << "#include \"llvm/MC/MCSubtargetInfo.h\"\n"; @@ -2690,12 +2690,12 @@ namespace llvm { -void EmitFixedLenDecoder(RecordKeeper &RK, raw_ostream &OS, +void EmitDecoder(RecordKeeper &RK, raw_ostream &OS, const std::string &PredicateNamespace, const std::string &GPrefix, const std::string &GPostfix, const std::string &ROK, const std::string &RFail, const std::string &L) { - FixedLenDecoderEmitter(RK, PredicateNamespace, GPrefix, GPostfix, + DecoderEmitter(RK, PredicateNamespace, GPrefix, GPostfix, ROK, RFail, L).run(OS); } 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 @@ -95,7 +95,7 @@ namespace llvm { -extern void EmitFixedLenDecoder(RecordKeeper &RK, raw_ostream &OS, +extern void EmitDecoder(RecordKeeper &RK, raw_ostream &OS, const std::string &PredicateNamespace, const std::string &GPrefix, const std::string &GPostfix, @@ -125,9 +125,9 @@ return; } - // WebAssembly has variable length opcodes, so can't use EmitFixedLenDecoder - // below (which depends on a Size table-gen Record), and also uses a custom - // disassembler. + // TODO: Since now the original decoder emitter is able to emit decoder for + // variable length opcode, we might have to migrate webassembly to use + // that. if (Target.getName() == "WebAssembly") { emitWebAssemblyDisassemblerTables(OS, Target.getInstructionsByEnumValue()); return; @@ -140,7 +140,7 @@ if (PredicateNamespace == "Thumb") PredicateNamespace = "ARM"; - EmitFixedLenDecoder(Records, OS, PredicateNamespace, + EmitDecoder(Records, OS, PredicateNamespace, "if (!Check(S, ", "))", "S", "MCDisassembler::Fail", " MCDisassembler::DecodeStatus S = " @@ -148,7 +148,7 @@ return; } - EmitFixedLenDecoder(Records, OS, std::string(Target.getName()), "if (", + EmitDecoder(Records, OS, std::string(Target.getName()), "if (", " == MCDisassembler::Fail)", "MCDisassembler::Success", "MCDisassembler::Fail", ""); } diff --git a/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn b/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn --- a/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn @@ -27,13 +27,13 @@ "DAGISelMatcherEmitter.cpp", "DAGISelMatcherGen.cpp", "DAGISelMatcherOpt.cpp", + "DecoderEmitter.cpp", "DFAEmitter.cpp", "DFAPacketizerEmitter.cpp", "DirectiveEmitter.cpp", "DisassemblerEmitter.cpp", "ExegesisEmitter.cpp", "FastISelEmitter.cpp", - "FixedLenDecoderEmitter.cpp", "GICombinerEmitter.cpp", "GlobalISelEmitter.cpp", "InfoByHwMode.cpp",