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. // //===----------------------------------------------------------------------===// @@ -51,7 +51,8 @@ namespace { STATISTIC(NumEncodings, "Number of encodings considered"); -STATISTIC(NumEncodingsLackingDisasm, "Number of encodings without disassembler info"); +STATISTIC(NumEncodingsLackingDisasm, + "Number of encodings without disassembler info"); STATISTIC(NumInstructions, "Number of instructions considered"); STATISTIC(NumEncodingsSupported, "Number of encodings supported"); STATISTIC(NumEncodingsOmitted, "Number of encodings omitted"); @@ -59,7 +60,7 @@ struct EncodingField { unsigned Base, Width, Offset; EncodingField(unsigned B, unsigned W, unsigned O) - : Base(B), Width(W), Offset(O) { } + : Base(B), Width(W), Offset(O) {} }; struct OperandInfo { @@ -80,7 +81,7 @@ typedef std::vector::const_iterator const_iterator; const_iterator begin() const { return Fields.begin(); } - const_iterator end() const { return Fields.end(); } + const_iterator end() const { return Fields.end(); } }; typedef std::vector DecoderTable; @@ -122,19 +123,18 @@ 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, - std::string GPrefix = "if (", - std::string GPostfix = " == MCDisassembler::Fail)", - std::string ROK = "MCDisassembler::Success", - std::string RFail = "MCDisassembler::Fail", - std::string L = "") + DecoderEmitter(RecordKeeper &R, std::string PredicateNamespace, + std::string GPrefix = "if (", + std::string GPostfix = " == MCDisassembler::Fail)", + std::string ROK = "MCDisassembler::Success", + std::string RFail = "MCDisassembler::Fail", std::string L = "") : RK(R), Target(R), PredicateNamespace(std::move(PredicateNamespace)), GuardPrefix(std::move(GPrefix)), GuardPostfix(std::move(GPostfix)), ReturnOK(std::move(ROK)), ReturnFail(std::move(RFail)), @@ -149,8 +149,7 @@ void emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, unsigned Indentation) const; - void emitDecoderFunction(formatted_raw_ostream &OS, - DecoderSet &Decoders, + void emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, unsigned Indentation) const; // run - Output the code emitter @@ -184,9 +183,7 @@ return (V == BIT_TRUE || V == BIT_FALSE); } -static bool ValueNotSet(bit_value_t V) { - return (V == BIT_UNSET); -} +static bool ValueNotSet(bit_value_t V) { return (V == BIT_UNSET); } static int Value(bit_value_t V) { return ValueNotSet(V) ? -1 : (V == BIT_FALSE ? 0 : 1); @@ -291,14 +288,14 @@ /// version and return the Opcode since the two have the same Asm format string. class Filter { protected: - const FilterChooser *Owner;// points to the FilterChooser who owns this filter + const FilterChooser + *Owner; // points to the FilterChooser who owns this filter unsigned StartBit; // the starting bit position - unsigned NumBits; // number of bits to filter - bool Mixed; // a mixed region contains both set and unset bits + unsigned NumBits; // number of bits to filter + bool Mixed; // a mixed region contains both set and unset bits // Map of well-known segment value to the set of uid's with that value. - std::map> - FilteredInstructions; + std::map> FilteredInstructions; // Set of uid's with non-constant segment values. std::vector VariableInstructions; @@ -411,13 +408,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) { @@ -482,7 +479,7 @@ /// dumpFilterArray - dumpFilterArray prints out debugging info for the given /// filter array as a series of chars. void dumpFilterArray(raw_ostream &o, - const std::vector & filter) const; + const std::vector &filter) const; /// dumpStack - dumpStack traverses the filter chooser chain and calls /// dumpFilterArray on each filter chooser up to the top level one. @@ -513,11 +510,9 @@ bool doesOpcodeNeedPredicate(unsigned Opc) const; unsigned getPredicateIndex(DecoderTableInfo &TableInfo, StringRef P) const; - void emitPredicateTableEntry(DecoderTableInfo &TableInfo, - unsigned Opc) const; + void emitPredicateTableEntry(DecoderTableInfo &TableInfo, unsigned Opc) const; - void emitSoftFailTableEntry(DecoderTableInfo &TableInfo, - unsigned Opc) const; + void emitSoftFailTableEntry(DecoderTableInfo &TableInfo, unsigned Opc) const; // Emits table entries to decode the singleton. void emitSingletonTableEntry(DecoderTableInfo &TableInfo, @@ -569,16 +564,15 @@ /////////////////////////// Filter::Filter(Filter &&f) - : Owner(f.Owner), StartBit(f.StartBit), NumBits(f.NumBits), Mixed(f.Mixed), - FilteredInstructions(std::move(f.FilteredInstructions)), - VariableInstructions(std::move(f.VariableInstructions)), - FilterChooserMap(std::move(f.FilterChooserMap)), NumFiltered(f.NumFiltered), - LastOpcFiltered(f.LastOpcFiltered) { -} + : Owner(f.Owner), StartBit(f.StartBit), NumBits(f.NumBits), Mixed(f.Mixed), + FilteredInstructions(std::move(f.FilteredInstructions)), + VariableInstructions(std::move(f.VariableInstructions)), + FilterChooserMap(std::move(f.FilterChooserMap)), + NumFiltered(f.NumFiltered), LastOpcFiltered(f.LastOpcFiltered) {} Filter::Filter(FilterChooser &owner, unsigned startBit, unsigned numBits, bool mixed) - : Owner(&owner), StartBit(startBit), NumBits(numBits), Mixed(mixed) { + : Owner(&owner), StartBit(startBit), NumBits(numBits), Mixed(mixed) { assert(StartBit + NumBits - 1 < Owner->BitWidth); NumFiltered = 0; @@ -607,8 +601,8 @@ } } - assert((FilteredInstructions.size() + VariableInstructions.size() > 0) - && "Filter returns no instruction categories"); + assert((FilteredInstructions.size() + VariableInstructions.size() > 0) && + "Filter returns no instruction categories"); } // Divides the decoding task into sub tasks and delegates them to the @@ -628,9 +622,11 @@ // Delegates to an inferior filter chooser for further processing on this // group of instructions whose segment values are variable. - FilterChooserMap.insert(std::make_pair(NO_FIXED_SEGMENTS_SENTINEL, + FilterChooserMap.insert(std::make_pair( + NO_FIXED_SEGMENTS_SENTINEL, std::make_unique(Owner->AllInstructions, - VariableInstructions, Owner->Operands, BitValueArray, *Owner))); + VariableInstructions, Owner->Operands, + BitValueArray, *Owner))); } // No need to recurse for a singleton filtered instruction. @@ -655,8 +651,8 @@ // category of instructions. FilterChooserMap.insert(std::make_pair( Inst.first, std::make_unique( - Owner->AllInstructions, Inst.second, - Owner->Operands, BitValueArray, *Owner))); + Owner->AllInstructions, Inst.second, Owner->Operands, + BitValueArray, *Owner))); } } @@ -664,8 +660,7 @@ uint32_t DestIdx) { // Any NumToSkip fixups in the current scope can resolve to the // current location. - for (FixupList::const_reverse_iterator I = Fixups.rbegin(), - E = Fixups.rend(); + for (FixupList::const_reverse_iterator I = Fixups.rbegin(), E = Fixups.rend(); I != E; ++I) { // Calculate the distance from the byte following the fixup entry byte // to the destination. The Target is calculated from after the 16-bit @@ -709,7 +704,7 @@ // Resolve any NumToSkip fixups in the current scope. resolveTableFixups(Table, CurScope, Table.size()); CurScope.clear(); - PrevFilter = 0; // Don't re-process the filter's fallthrough. + PrevFilter = 0; // Don't re-process the filter's fallthrough. } else { Table.push_back(MCD::OPC_FilterValue); // Encode and emit the value to filter against. @@ -735,7 +730,8 @@ // two as to account for the width of the NumToSkip field itself. if (PrevFilter) { uint32_t NumToSkip = Table.size() - PrevFilter - 3; - assert(NumToSkip < (1u << 24) && "disassembler decoding table too large!"); + assert(NumToSkip < (1u << 24) && + "disassembler decoding table too large!"); Table[PrevFilter] = (uint8_t)NumToSkip; Table[PrevFilter + 1] = (uint8_t)(NumToSkip >> 8); Table[PrevFilter + 2] = (uint8_t)(NumToSkip >> 16); @@ -771,13 +767,11 @@ ////////////////////////////////// // Emit the decoder state machine table. -void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, - DecoderTable &Table, - unsigned Indentation, - unsigned BitWidth, - StringRef Namespace) const { +void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table, + unsigned Indentation, unsigned BitWidth, + StringRef Namespace) const { OS.indent(Indentation) << "static const uint8_t DecoderTable" << Namespace - << BitWidth << "[] = {\n"; + << BitWidth << "[] = {\n"; Indentation += 2; @@ -786,7 +780,7 @@ DecoderTable::const_iterator I = Table.begin(); DecoderTable::const_iterator E = Table.end(); while (I != E) { - assert (I < E && "incomplete decode table entry!"); + assert(I < E && "incomplete decode table entry!"); uint64_t Pos = I - Table.begin(); OS << "/* " << Pos << " */"; @@ -799,8 +793,8 @@ ++I; unsigned Start = *I++; unsigned Len = *I++; - OS.indent(Indentation) << "MCD::OPC_ExtractField, " << Start << ", " - << Len << ", // Inst{"; + OS.indent(Indentation) + << "MCD::OPC_ExtractField, " << Start << ", " << Len << ", // Inst{"; if (Len > 1) OS << (Start + Len - 1) << "-"; OS << Start << "} ...\n"; @@ -831,8 +825,8 @@ ++I; unsigned Start = *I++; unsigned Len = *I++; - OS.indent(Indentation) << "MCD::OPC_CheckField, " << Start << ", " - << Len << ", ";// << Val << ", " << NumToSkip << ",\n"; + OS.indent(Indentation) << "MCD::OPC_CheckField, " << Start << ", " << Len + << ", "; // << Val << ", " << NumToSkip << ",\n"; // ULEB128 encoded field value. for (; *I >= 128; ++I) OS << (unsigned)*I << ", "; @@ -877,12 +871,12 @@ // Extract the ULEB128 encoded Opcode to a buffer. uint8_t Buffer[16], *p = Buffer; while ((*p++ = *I++) >= 128) - assert((p - Buffer) <= (ptrdiff_t)sizeof(Buffer) - && "ULEB128 value too large!"); + assert((p - Buffer) <= (ptrdiff_t)sizeof(Buffer) && + "ULEB128 value too large!"); // Decode the Opcode value. unsigned Opc = decodeULEB128(Buffer); - OS.indent(Indentation) << "MCD::OPC_" << (IsTry ? "Try" : "") - << "Decode, "; + OS.indent(Indentation) + << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, "; for (p = Buffer; *p >= 128; ++p) OS << (unsigned)*p << ", "; OS << (unsigned)*p << ", "; @@ -960,8 +954,8 @@ OS.indent(Indentation) << "};\n\n"; } -void FixedLenDecoderEmitter::emitInstrLenTable( - formatted_raw_ostream &OS, std::vector &InstrLen) const { +void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS, + std::vector &InstrLen) const { OS << "static const uint8_t InstrLenTable[] = {\n"; for (unsigned &Len : InstrLen) { OS << Len << ",\n"; @@ -969,21 +963,22 @@ OS << "};\n\n"; } -void FixedLenDecoderEmitter:: -emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, - unsigned Indentation) const { +void DecoderEmitter::emitPredicateFunction(formatted_raw_ostream &OS, + PredicateSet &Predicates, + unsigned Indentation) const { // The predicate function is just a big switch statement based on the // input predicate index. OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, " - << "const FeatureBitset &Bits) {\n"; + << "const FeatureBitset &Bits) {\n"; Indentation += 2; if (!Predicates.empty()) { OS.indent(Indentation) << "switch (Idx) {\n"; - OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n"; + OS.indent(Indentation) + << "default: llvm_unreachable(\"Invalid index!\");\n"; unsigned Index = 0; for (const auto &Predicate : Predicates) { OS.indent(Indentation) << "case " << Index++ << ":\n"; - OS.indent(Indentation+2) << "return (" << Predicate << ");\n"; + OS.indent(Indentation + 2) << "return (" << Predicate << ");\n"; } OS.indent(Indentation) << "}\n"; } else { @@ -994,14 +989,14 @@ OS.indent(Indentation) << "}\n\n"; } -void FixedLenDecoderEmitter:: -emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, - unsigned Indentation) const { +void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS, + DecoderSet &Decoders, + unsigned Indentation) const { // The decoder function is just a big switch statement based on the // input decoder index. OS.indent(Indentation) << "template \n"; OS.indent(Indentation) << "static DecodeStatus decodeToMCInst(DecodeStatus S," - << " unsigned Idx, InsnType insn, MCInst &MI,\n"; + << " unsigned Idx, InsnType insn, MCInst &MI,\n"; OS.indent(Indentation) << " uint64_t " << "Address, const MCDisassembler *Decoder, bool &DecodeComplete) {\n"; @@ -1020,7 +1015,7 @@ for (const auto &Decoder : Decoders) { OS.indent(Indentation) << "case " << Index++ << ":\n"; OS << Decoder; - OS.indent(Indentation+2) << "return S;\n"; + OS.indent(Indentation + 2) << "return S;\n"; } OS.indent(Indentation) << "}\n"; Indentation -= 2; @@ -1049,8 +1044,8 @@ /// dumpFilterArray - dumpFilterArray prints out debugging info for the given /// filter array as a series of chars. -void FilterChooser::dumpFilterArray(raw_ostream &o, - const std::vector &filter) const { +void FilterChooser::dumpFilterArray( + raw_ostream &o, const std::vector &filter) const { for (unsigned bitIndex = BitWidth; bitIndex > 0; bitIndex--) { switch (filter[bitIndex - 1]) { case BIT_UNFILTERED: @@ -1104,7 +1099,8 @@ int64_t Val = Value(Insn[i]); bool Filtered = PositionFiltered(i); switch (State) { - default: llvm_unreachable("Unreachable code!"); + default: + llvm_unreachable("Unreachable code!"); case 0: case 1: if (Filtered || Val == -1) @@ -1172,10 +1168,11 @@ if (Decoder != "") { OpHasCompleteDecoder = OpInfo.HasCompleteDecoder; o.indent(Indentation) << Emitter->GuardPrefix << Decoder - << "(MI, tmp, Address, Decoder)" - << Emitter->GuardPostfix - << " { " << (OpHasCompleteDecoder ? "" : "DecodeComplete = false; ") - << "return MCDisassembler::Fail; }\n"; + << "(MI, tmp, Address, Decoder)" + << Emitter->GuardPostfix << " { " + << (OpHasCompleteDecoder ? "" + : "DecodeComplete = false; ") + << "return MCDisassembler::Fail; }\n"; } else { OpHasCompleteDecoder = true; o.indent(Indentation) << "MI.addOperand(MCOperand::createImm(tmp));\n"; @@ -1190,11 +1187,11 @@ // If a custom instruction decoder was specified, use that. if (Op.numFields() == 0 && !Op.Decoder.empty()) { HasCompleteDecoder = Op.HasCompleteDecoder; - OS.indent(Indentation) << Emitter->GuardPrefix << Op.Decoder - << "(MI, insn, Address, Decoder)" - << Emitter->GuardPostfix - << " { " << (HasCompleteDecoder ? "" : "DecodeComplete = false; ") - << "return MCDisassembler::Fail; }\n"; + OS.indent(Indentation) + << Emitter->GuardPrefix << Op.Decoder + << "(MI, insn, Address, Decoder)" << Emitter->GuardPostfix << " { " + << (HasCompleteDecoder ? "" : "DecodeComplete = false; ") + << "return MCDisassembler::Fail; }\n"; break; } @@ -1205,8 +1202,7 @@ } } -unsigned FilterChooser::getDecoderIndex(DecoderSet &Decoders, - unsigned Opc, +unsigned FilterChooser::getDecoderIndex(DecoderSet &Decoders, unsigned Opc, bool &HasCompleteDecoder) const { // Build up the predicate string. SmallString<256> Decoder; @@ -1346,7 +1342,8 @@ const RecordVal *RV = AllInstructions[Opc].EncodingDef->getValue("SoftFail"); BitsInit *SFBits = RV ? dyn_cast(RV->getValue()) : nullptr; - if (!SFBits) return; + if (!SFBits) + return; BitsInit *InstBits = AllInstructions[Opc].EncodingDef->getValueAsBitsInit("Inst"); @@ -1356,7 +1353,8 @@ bit_value_t B = bitFromBits(*SFBits, i); bit_value_t IB = bitFromBits(*InstBits, i); - if (B != BIT_TRUE) continue; + if (B != BIT_TRUE) + continue; switch (IB) { case BIT_FALSE: @@ -1422,13 +1420,13 @@ // Check any additional encoding fields needed. for (unsigned I = Size; I != 0; --I) { - unsigned NumBits = EndBits[I-1] - StartBits[I-1] + 1; + unsigned NumBits = EndBits[I - 1] - StartBits[I - 1] + 1; TableInfo.Table.push_back(MCD::OPC_CheckField); - TableInfo.Table.push_back(StartBits[I-1]); + TableInfo.Table.push_back(StartBits[I - 1]); TableInfo.Table.push_back(NumBits); uint8_t Buffer[16], *p; - encodeULEB128(FieldVals[I-1], Buffer); - for (p = Buffer; *p >= 128 ; ++p) + encodeULEB128(FieldVals[I - 1], Buffer); + for (p = Buffer; *p >= 128; ++p) TableInfo.Table.push_back(*p); TableInfo.Table.push_back(*p); // Push location for NumToSkip backpatching. @@ -1457,12 +1455,12 @@ // decoder method indicates that additional processing should be done to see // if there is any other instruction that also matches the bitpattern and // can decode it. - TableInfo.Table.push_back(HasCompleteDecoder ? MCD::OPC_Decode : - MCD::OPC_TryDecode); + TableInfo.Table.push_back(HasCompleteDecoder ? MCD::OPC_Decode + : MCD::OPC_TryDecode); NumEncodingsSupported++; uint8_t Buffer[16], *p; encodeULEB128(Opc.Opcode, Buffer); - for (p = Buffer; *p >= 128 ; ++p) + for (p = Buffer; *p >= 128; ++p) TableInfo.Table.push_back(*p); TableInfo.Table.push_back(*p); @@ -1824,8 +1822,8 @@ std::string Decoder; RecordVal *DecoderString = Record->getValue("DecoderMethod"); - StringInit *String = DecoderString ? - dyn_cast(DecoderString->getValue()) : nullptr; + StringInit *String = + DecoderString ? dyn_cast(DecoderString->getValue()) : nullptr; if (String) { Decoder = std::string(String->getValue()); if (!Decoder.empty()) @@ -1839,7 +1837,7 @@ Decoder = "Decode" + Record->getName().str() + "RegisterClass"; } else if (Record->isSubClassOf("PointerLikeRegClass")) { Decoder = "DecodePointerLikeRegClass" + - utostr(Record->getValueAsInt("RegClassKind")); + utostr(Record->getValueAsInt("RegClassKind")); } return Decoder; @@ -1934,7 +1932,8 @@ // of trying to auto-generate the decoder. StringRef InstDecoder = EncodingDef.getValueAsString("DecoderMethod"); if (InstDecoder != "") { - bool HasCompleteInstDecoder = EncodingDef.getValueAsBit("hasCompleteDecoder"); + bool HasCompleteInstDecoder = + EncodingDef.getValueAsBit("hasCompleteDecoder"); InsnOperands.push_back( OperandInfo(std::string(InstDecoder), HasCompleteInstDecoder)); Operands[Opc] = InsnOperands; @@ -1948,9 +1947,9 @@ // Gather the outputs/inputs of the instruction, so we can find their // positions in the encoding. This assumes for now that they appear in the // MCInst in the order that they're listed. - std::vector> InOutOperands; - DagInit *Out = Def.getValueAsDag("OutOperandList"); - DagInit *In = Def.getValueAsDag("InOperandList"); + std::vector> InOutOperands; + DagInit *Out = Def.getValueAsDag("OutOperandList"); + DagInit *In = Def.getValueAsDag("InOperandList"); for (unsigned i = 0; i < Out->getNumArgs(); ++i) InOutOperands.push_back( std::make_pair(Out->getArg(i), Out->getArgNameStr(i))); @@ -1965,7 +1964,7 @@ int tiedTo = CGI.Operands[i].getTiedRegister(); if (tiedTo != -1) { std::pair SO = - CGI.Operands.getSubOperandNumber(tiedTo); + CGI.Operands.getSubOperandNumber(tiedTo); TiedNames[std::string(InOutOperands[i].second)] = std::string(InOutOperands[SO.first].second); TiedNames[std::string(InOutOperands[SO.first].second)] = @@ -2518,7 +2517,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"; @@ -2582,7 +2581,8 @@ NumberedEncodings.emplace_back(NumberedInstruction->TheDef, NumberedInstruction, HwModeName); } - for (const auto &NumberedAlias : RK.getAllDerivedDefinitions("AdditionalEncoding")) + for (const auto &NumberedAlias : + RK.getAllDerivedDefinitions("AdditionalEncoding")) NumberedEncodings.emplace_back( NumberedAlias, &Target.getInstruction(NumberedAlias->getValueAsDef("AliasOf"))); @@ -2643,8 +2643,8 @@ DecoderTableInfo TableInfo; for (const auto &Opc : OpcMap) { // Emit the decoder for this namespace+width combination. - ArrayRef NumberedEncodingsRef( - NumberedEncodings.data(), NumberedEncodings.size()); + ArrayRef NumberedEncodingsRef(NumberedEncodings.data(), + NumberedEncodings.size()); FilterChooser FC(NumberedEncodingsRef, Opc.second, Operands, IsVarLenInst ? MaxInstLen : 8 * Opc.first.second, this); @@ -2690,13 +2690,13 @@ namespace llvm { -void EmitFixedLenDecoder(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, - ROK, RFail, L).run(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) { + DecoderEmitter(RK, PredicateNamespace, GPrefix, GPostfix, ROK, RFail, L) + .run(OS); } } // end namespace llvm 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,12 +95,11 @@ namespace llvm { -extern void EmitFixedLenDecoder(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); +extern 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); void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { CodeGenTarget Target(Records); @@ -125,9 +124,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,17 +139,16 @@ if (PredicateNamespace == "Thumb") PredicateNamespace = "ARM"; - EmitFixedLenDecoder(Records, OS, PredicateNamespace, - "if (!Check(S, ", "))", - "S", "MCDisassembler::Fail", - " MCDisassembler::DecodeStatus S = " - "MCDisassembler::Success;\n(void)S;"); + EmitDecoder(Records, OS, PredicateNamespace, "if (!Check(S, ", "))", "S", + "MCDisassembler::Fail", + " MCDisassembler::DecodeStatus S = " + "MCDisassembler::Success;\n(void)S;"); return; } - EmitFixedLenDecoder(Records, OS, std::string(Target.getName()), "if (", - " == MCDisassembler::Fail)", "MCDisassembler::Success", - "MCDisassembler::Fail", ""); + EmitDecoder(Records, OS, std::string(Target.getName()), "if (", + " == MCDisassembler::Fail)", "MCDisassembler::Success", + "MCDisassembler::Fail", ""); } } // end namespace llvm 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",