diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp index f64467a0f35e..c5b35ee59f94 100644 --- a/llvm/utils/TableGen/DecoderEmitter.cpp +++ b/llvm/utils/TableGen/DecoderEmitter.cpp @@ -533,10 +533,10 @@ public: protected: // Populates the insn given the uid. - void insnWithID(insn_t &Insn, unsigned Opcode) const { + insn_t insnWithID(unsigned Opcode) const { const Record *EncodingDef = AllInstructions[Opcode].EncodingDef; const BitsInit &Bits = getBitsField(*EncodingDef, "Inst"); - Insn.resize(std::max(BitWidth, Bits.getNumBits()), BitValue::BIT_UNSET); + insn_t Insn(std::max(BitWidth, Bits.getNumBits()), BitValue::BIT_UNSET); // We may have a SoftFail bitmask, which specifies a mask where an encoding // may differ from the value in "Inst" and yet still be valid, but the // disassembler should return SoftFail instead of Success. @@ -550,6 +550,7 @@ protected: else Insn[i] = BitValue(Bits, i); } + return Insn; } // Populates the field of the insn given the start position and the number of @@ -582,7 +583,7 @@ protected: // This returns a list of undecoded bits of an instructions, for example, // Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be // decoded bits in order to verify that the instruction matches the Opcode. - unsigned getIslands(std::vector &Islands, const insn_t &Insn) const; + std::vector getIslands(const insn_t &Insn) const; // Emits code to check the Predicates member of an instruction are true. // Returns true if predicate matches were emitted, false otherwise. @@ -658,10 +659,8 @@ Filter::Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits) LastOpcFiltered = {0, 0}; for (const auto &OpcPair : Owner.Opcodes) { - insn_t Insn; - // Populates the insn given the uid. - Owner.insnWithID(Insn, OpcPair.EncodingID); + insn_t Insn = Owner.insnWithID(OpcPair.EncodingID); // Scans the segment for possibly well-specified encoding bits. auto [Ok, Field] = Owner.fieldFromInsn(Insn, StartBit, NumBits); @@ -1162,8 +1161,9 @@ void FilterChooser::dumpStack(raw_ostream &OS, const char *prefix) const { // This returns a list of undecoded bits of an instructions, for example, // Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be // decoded bits in order to verify that the instruction matches the Opcode. -unsigned FilterChooser::getIslands(std::vector &Islands, - const insn_t &Insn) const { +std::vector +FilterChooser::getIslands(const insn_t &Insn) const { + std::vector Islands; uint64_t FieldVal; unsigned StartBit; @@ -1203,7 +1203,7 @@ unsigned FilterChooser::getIslands(std::vector &Islands, if (State == 2) Islands.push_back({StartBit, BitWidth - StartBit, FieldVal}); - return Islands.size(); + return Islands; } bool FilterChooser::emitBinaryParser(raw_ostream &OS, indent Indent, @@ -1452,12 +1452,10 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo, // Emits table entries to decode the singleton. void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo, EncodingIDAndOpcode Opc) const { - std::vector Islands; - insn_t Insn; - insnWithID(Insn, Opc.EncodingID); + insn_t Insn = insnWithID(Opc.EncodingID); // Look for islands of undecoded bits of the singleton. - getIslands(Islands, Insn); + std::vector Islands = getIslands(Insn); // Emit the predicate table entry if one is needed. emitPredicateTableEntry(TableInfo, Opc.EncodingID); @@ -1569,13 +1567,11 @@ bool FilterChooser::filterProcessor(bool AllowMixed, bool Greedy) { assert(numInstructions == 3); for (const auto &Opcode : Opcodes) { - std::vector Islands; - insn_t Insn; - - insnWithID(Insn, Opcode.EncodingID); + insn_t Insn = insnWithID(Opcode.EncodingID); // Look for islands of undecoded bits of any instruction. - if (getIslands(Islands, Insn) > 0) { + std::vector Islands = getIslands(Insn); + if (!Islands.empty()) { // Found an instruction with island(s). Now just assign a filter. runSingleFilter(Islands[0].StartBit, Islands[0].NumBits); return true; @@ -1611,9 +1607,7 @@ bool FilterChooser::filterProcessor(bool AllowMixed, bool Greedy) { bitAttrs[BitIndex] = ATTR_FILTERED; for (const auto &OpcPair : Opcodes) { - insn_t insn; - - insnWithID(insn, OpcPair.EncodingID); + insn_t insn = insnWithID(OpcPair.EncodingID); for (BitIndex = 0; BitIndex < BitWidth; ++BitIndex) { switch (bitAttrs[BitIndex]) {