Lines Matching +full:update +full:- +full:fc +full:- +full:fixup
1 //===---------------- DecoderEmitter.cpp - Decoder Generator --------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
53 #define DEBUG_TYPE "decoder-emitter"
64 "suppress-per-hwmode-duplicates",
65 cl::desc("Suppress duplication of instrs into per-HwMode decoder tables"),
75 "Extract HwModes-specific instructions into new DecoderTables, "
151 if (Value.EncodingDef != Value.Inst->TheDef) in operator <<()
152 OS << Value.EncodingDef->getName() << ":"; in operator <<()
153 OS << Value.Inst->TheDef->getName(); in operator <<()
177 // run - Output the code emitter
208 return ValueNotSet(V) ? -1 : (V == BIT_FALSE ? 0 : 1); in Value()
213 return bit->getValue() ? BIT_TRUE : BIT_FALSE; in bitFromBits()
221 for (unsigned index = bits.getNumBits(); index > 0; --index) { in dumpBits()
222 switch (bitFromBits(bits, index - 1)) { in dumpBits()
240 if (BitsInit *Bits = dyn_cast<BitsInit>(RV->getValue())) in getBitsField()
244 VarLenInst VLI = VarLenInst(cast<DagInit>(RV->getValue()), RV); in getBitsField()
249 for (unsigned Idx = 0U; Idx < BI->getNumBits(); ++Idx) { in getBitsField()
250 Bits.push_back(BI->getBit(Idx)); in getBitsField()
268 static const uint64_t NO_FIXED_SEGMENTS_SENTINEL = -1ULL;
272 /// Filter - Filter works with FilterChooser to produce the decoding tree for
300 /// the conclusion that there is a conflict. VST4q8a is a vst4 to double-spaced
301 /// even registers, while VST4q8b is a vst4 to double-spaced odd registers.
316 // Map of well-known segment value to the set of uid's with that value.
319 // Set of uid's with non-constant segment values.
322 // Map of well-known segment value to its delegate.
349 return *(FilterChooserMap.find(NO_FIXED_SEGMENTS_SENTINEL)->second); in getVariableFC()
381 /// FilterChooser - FilterChooser chooses the best filter among a set of Filters
384 /// Decoding proceeds from the top down. Based on the well-known encoding bits
390 /// into sub-tasks and delegates them to its inferior FilterChoosers for further
438 FilterBitValues(BW, BIT_UNFILTERED), Parent(nullptr), BestIndex(-1), in FilterChooser()
449 FilterBitValues(ParentFilterBitValues), Parent(&parent), BestIndex(-1), in FilterChooser()
470 const RecordVal *RV = EncodingDef->getValue("SoftFail"); in insnWithID()
471 const BitsInit *SFBits = RV ? dyn_cast<BitsInit>(RV->getValue()) : nullptr; in insnWithID()
483 const Record *InstDef = AllInstructions[Opcode].Inst->TheDef; in emitNameWithID()
485 OS << EncodingDef->getName() << ":"; in emitNameWithID()
486 OS << InstDef->getName(); in emitNameWithID()
494 // bits are well-known. The second value is the potentially populated field.
498 /// dumpFilterArray - dumpFilterArray prints out debugging info for the given
503 /// dumpStack - dumpStack traverses the filter chooser chain and calls
508 assert(BestIndex != -1 && "BestIndex not set"); in bestFilter()
518 // Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
563 // FilterProcessor scans the well-known encoding bits of the instructions and
574 // emitTableEntries - Emit state machine entries to decode our share of
597 assert(StartBit + NumBits - 1 < Owner->BitWidth); in Filter()
602 for (const auto &OpcPair : Owner->Opcodes) { in Filter()
606 Owner->insnWithID(Insn, OpcPair.EncodingID); in Filter()
608 // Scans the segment for possibly well-specified encoding bits. in Filter()
609 auto [Ok, Field] = Owner->fieldFromInsn(Insn, StartBit, NumBits); in Filter()
612 // The encoding bits are well-known. Lets add the uid of the in Filter()
636 std::vector<bit_value_t> BitValueArray(Owner->FilterBitValues); in recurse()
647 std::make_unique<FilterChooser>(Owner->AllInstructions, in recurse()
648 VariableInstructions, Owner->Operands, in recurse()
674 Owner->AllInstructions, Inst.second, in recurse()
675 Owner->Operands, BitValueArray, *Owner))); in recurse()
685 // Calculate the distance from the byte following the fixup entry byte in resolveTableFixups()
686 // to the destination. The Target is calculated from after the 16-bit in resolveTableFixups()
690 uint32_t Delta = DestIdx - FixupIdx - 3; in resolveTableFixups()
691 // Our NumToSkip entries are 24-bits. Make sure our table isn't too in resolveTableFixups()
712 // A new filter entry begins a new scope for fixup resolution. in emitTableEntry()
720 // Field value -1 implies a non-empty set of variable instructions. in emitTableEntry()
732 PrevFilter = 0; // Don't re-process the filter's fallthrough. in emitTableEntry()
749 // The case may fallthrough, which happens if the remaining well-known in emitTableEntry()
751 Filter.second->emitTableEntries(TableInfo); in emitTableEntry()
753 // Now that we've emitted the body of the handler, update the NumToSkip in emitTableEntry()
757 uint32_t NumToSkip = Table.size() - PrevFilter - 3; in emitTableEntry()
766 // Any remaining unresolved fixups bubble up to the parent fixup scope. in emitTableEntry()
767 assert(TableInfo.FixupStack.size() > 1 && "fixup stack underflow!"); in emitTableEntry()
768 FixupScopeList::iterator Source = TableInfo.FixupStack.end() - 1; in emitTableEntry()
769 FixupScopeList::iterator Dest = Source - 1; in emitTableEntry()
824 // Emit 24-bit numtoskip value to OS, returning the NumToSkip value. in emitTable()
846 uint64_t Pos = I - Table.begin(); in emitTable()
867 OS << (Start + Len - 1) << "-"; in emitTable()
877 // 24-bit numtoskip value. in emitTable()
880 OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n"; in emitTable()
888 // 8-bit length. in emitTable()
894 // 24-bit numtoskip value. in emitTable()
897 OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n"; in emitTable()
905 // 24-bit numtoskip value. in emitTable()
908 OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n"; in emitTable()
930 auto EncodingID = EncI->second; in emitTable()
939 // 24-bit numtoskip value. in emitTable()
944 << ", skip to: " << ((I - Table.begin()) + NumToSkip) << "\n"; in emitTable()
988 Indentation -= 2; in emitTable()
1024 Indentation -= 2; in emitPredicateFunction()
1042 // It would be better for emitBinaryParser to use a 64-bit tmp whenever in emitDecoderFunction()
1043 // possible but fall back to an InsnType-sized tmp for truly large fields. in emitDecoderFunction()
1057 Indentation -= 2; in emitDecoderFunction()
1066 // bits are well-known. The second value is the potentially populated field.
1083 /// dumpFilterArray - dumpFilterArray prints out debugging info for the given
1087 for (unsigned bitIndex = BitWidth; bitIndex > 0; bitIndex--) { in dumpFilterArray()
1088 switch (filter[bitIndex - 1]) { in dumpFilterArray()
1105 /// dumpStack - dumpStack traverses the filter chooser chain and calls
1112 dumpFilterArray(o, current->FilterBitValues); in dumpStack()
1114 current = current->Parent; in dumpStack()
1120 // Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
1133 // 2: Island (well-known bit value needed for decoding) in getIslands()
1144 if (Filtered || Val == -1) in getIslands()
1154 if (Filtered || Val == -1) { in getIslands()
1156 EndBits.push_back(i - 1); in getIslands()
1169 EndBits.push_back(BitWidth - 1); in getIslands()
1223 for (const auto &Op : Operands.find(Opc)->second) { in emitDecoder()
1262 return (unsigned)(P - Decoders.begin()); in getDecoderIndex()
1269 if (!D->getDef()->isSubClassOf("SubtargetFeature")) in emitPredicateMatchAux()
1271 OS << "Bits[" << Emitter->PredicateNamespace << "::" << D->getAsString() in emitPredicateMatchAux()
1276 std::string Op = D->getOperator()->getAsString(); in emitPredicateMatchAux()
1277 if (Op == "not" && D->getNumArgs() == 1) { in emitPredicateMatchAux()
1279 return emitPredicateMatchAux(*D->getArg(0), true, OS); in emitPredicateMatchAux()
1281 if ((Op == "any_of" || Op == "all_of") && D->getNumArgs() > 0) { in emitPredicateMatchAux()
1282 bool Paren = D->getNumArgs() > 1 && std::exchange(ParenIfBinOp, true); in emitPredicateMatchAux()
1286 for (auto *Arg : D->getArgs()) { in emitPredicateMatchAux()
1302 AllInstructions[Opc].EncodingDef->getValueAsListInit("Predicates"); in emitPredicateMatch()
1304 for (unsigned i = 0; i < Predicates->size(); ++i) { in emitPredicateMatch()
1305 Record *Pred = Predicates->getElementAsRecord(i); in emitPredicateMatch()
1306 if (!Pred->getValue("AssemblerMatcherPredicate")) in emitPredicateMatch()
1309 if (!isa<DagInit>(Pred->getValue("AssemblerCondDag")->getValue())) in emitPredicateMatch()
1314 if (emitPredicateMatchAux(*Pred->getValueAsDag("AssemblerCondDag"), in emitPredicateMatch()
1315 Predicates->size() > 1, o)) in emitPredicateMatch()
1316 PrintFatalError(Pred->getLoc(), "Invalid AssemblerCondDag!"); in emitPredicateMatch()
1319 return !Predicates->empty(); in emitPredicateMatch()
1324 AllInstructions[Opc].EncodingDef->getValueAsListInit("Predicates"); in doesOpcodeNeedPredicate()
1325 for (unsigned i = 0; i < Predicates->size(); ++i) { in doesOpcodeNeedPredicate()
1326 Record *Pred = Predicates->getElementAsRecord(i); in doesOpcodeNeedPredicate()
1327 if (!Pred->getValue("AssemblerMatcherPredicate")) in doesOpcodeNeedPredicate()
1330 if (isa<DagInit>(Pred->getValue("AssemblerCondDag")->getValue())) in doesOpcodeNeedPredicate()
1348 return (unsigned)(P - TableInfo.Predicates.begin()); in getPredicateIndex()
1385 const RecordVal *RV = EncodingDef->getValue("SoftFail"); in emitSoftFailTableEntry()
1386 BitsInit *SFBits = RV ? dyn_cast<BitsInit>(RV->getValue()) : nullptr; in emitSoftFailTableEntry()
1390 BitsInit *InstBits = EncodingDef->getValueAsBitsInit("Inst"); in emitSoftFailTableEntry()
1415 << " - You can only mark a bit as SoftFail if it is fully defined" in emitSoftFailTableEntry()
1416 << " (1/0 - not '?') in Inst\n"; in emitSoftFailTableEntry()
1464 for (unsigned I = Size; I != 0; --I) { in emitSingletonTableEntry()
1465 unsigned NumBits = EndBits[I - 1] - StartBits[I - 1] + 1; in emitSingletonTableEntry()
1469 encodeULEB128(StartBits[I - 1], Buffer); in emitSingletonTableEntry()
1474 encodeULEB128(FieldVals[I - 1], Buffer); in emitSingletonTableEntry()
1480 // The fixup is always 24-bits, so go ahead and allocate the space in emitSingletonTableEntry()
1524 // Allocate the space for the fixup. in emitSingletonTableEntry()
1564 Filters.emplace_back(*this, StartBit, BitIndex - StartBit, true); in reportRegion()
1566 Filters.emplace_back(*this, StartBit, BitIndex - StartBit, false); in reportRegion()
1569 // FilterProcessor scans the well-known encoding bits of the instructions and
1574 BestIndex = -1; in filterProcessor()
1599 runSingleFilter(StartBits[0], EndBits[0] - StartBits[0] + 1, true); in filterProcessor()
1615 // (NONE) ------- [01] -> (ALL_SET) in filterProcessor()
1616 // (NONE) ------- _ ----> (ALL_UNSET) in filterProcessor()
1617 // (ALL_SET) ---- [01] -> (ALL_SET) in filterProcessor()
1618 // (ALL_SET) ---- _ ----> (MIXED) in filterProcessor()
1619 // (ALL_UNSET) -- [01] -> (MIXED) in filterProcessor()
1620 // (ALL_UNSET) -- _ ----> (ALL_UNSET) in filterProcessor()
1621 // (MIXED) ------ . ----> (MIXED) in filterProcessor()
1622 // (FILTERED)---- . ----> (FILTERED) in filterProcessor()
1664 // lowest-to-highest. in filterProcessor()
1670 // (NONE) ----- F --> (NONE) in filterProcessor()
1671 // (NONE) ----- S --> (ALL_SET) ; and set region start in filterProcessor()
1672 // (NONE) ----- U --> (NONE) in filterProcessor()
1673 // (NONE) ----- M --> (MIXED) ; and set region start in filterProcessor()
1674 // (ALL_SET) -- F --> (NONE) ; and report an ALL_SET region in filterProcessor()
1675 // (ALL_SET) -- S --> (ALL_SET) in filterProcessor()
1676 // (ALL_SET) -- U --> (NONE) ; and report an ALL_SET region in filterProcessor()
1677 // (ALL_SET) -- M --> (MIXED) ; and report an ALL_SET region in filterProcessor()
1678 // (MIXED) ---- F --> (NONE) ; and report a MIXED region in filterProcessor()
1679 // (MIXED) ---- S --> (ALL_SET) ; and report a MIXED region in filterProcessor()
1680 // (MIXED) ---- U --> (NONE) ; and report a MIXED region in filterProcessor()
1681 // (MIXED) ---- M --> (MIXED) in filterProcessor()
1816 // no single instruction for the maximum ATTR_MIXED region Inst{14-4} has a in doFilter()
1817 // well-known encoding pattern. In such case, we backtrack and scan for the in doFilter()
1823 // Set the BestIndex to -1 to indicate so. in doFilter()
1824 BestIndex = -1; in doFilter()
1827 // emitTableEntries - Emit state machine entries to decode our share of
1839 if (BestIndex != -1) { in emitTableEntries()
1870 RecordVal *DecoderString = Record->getValue("DecoderMethod"); in findOperandDecoderMethod()
1872 DecoderString ? dyn_cast<StringInit>(DecoderString->getValue()) : nullptr; in findOperandDecoderMethod()
1874 Decoder = std::string(String->getValue()); in findOperandDecoderMethod()
1879 if (Record->isSubClassOf("RegisterOperand")) in findOperandDecoderMethod()
1881 return findOperandDecoderMethod(Record->getValueAsDef("RegClass")); in findOperandDecoderMethod()
1883 if (Record->isSubClassOf("RegisterClass")) { in findOperandDecoderMethod()
1884 Decoder = "Decode" + Record->getName().str() + "RegisterClass"; in findOperandDecoderMethod()
1885 } else if (Record->isSubClassOf("PointerLikeRegClass")) { in findOperandDecoderMethod()
1887 utostr(Record->getValueAsInt("RegClassKind")); in findOperandDecoderMethod()
1896 RecordVal *HasCompleteDecoderVal = TypeRecord->getValue("hasCompleteDecoder"); in getOpInfo()
1899 ? dyn_cast<BitInit>(HasCompleteDecoderVal->getValue()) in getOpInfo()
1902 HasCompleteDecoderBit ? HasCompleteDecoderBit->getValue() : true; in getOpInfo()
1912 VarLenInst VLI(cast<DagInit>(RV->getValue()), RV); in parseVarLenInstOperand()
1916 if (Op.MIOperandInfo && Op.MIOperandInfo->getNumArgs() > 0) in parseVarLenInstOperand()
1917 for (auto *Arg : Op.MIOperandInfo->getArgs()) in parseVarLenInstOperand()
1918 Operands.push_back(getOpInfo(cast<DefInit>(Arg)->getDef())); in parseVarLenInstOperand()
1923 TiedTo.push_back(-1); in parseVarLenInstOperand()
1924 if (TiedReg != -1) { in parseVarLenInstOperand()
1936 OpName = SI->getValue(); in parseVarLenInstOperand()
1938 OpName = cast<StringInit>(DI->getArg(0))->getValue(); in parseVarLenInstOperand()
1939 Offset = cast<IntInit>(DI->getArg(2))->getValue(); in parseVarLenInstOperand()
1952 if (TiedReg != -1) { in parseVarLenInstOperand()
1973 /// constant-valued bit values, and OpInfo.Fields with the ranges of bits to
1981 if (const BitsInit *OpBits = dyn_cast<BitsInit>(EncodedValue->getValue())) in addOneOperandFields()
1982 for (unsigned I = 0; I < OpBits->getNumBits(); ++I) in addOneOperandFields()
1983 if (const BitInit *OpBit = dyn_cast<BitInit>(OpBits->getBit(I))) in addOneOperandFields()
1984 if (OpBit->getValue()) in addOneOperandFields()
1993 Var = dyn_cast<VarInit>(BJ->getBitVar()); in addOneOperandFields()
1995 Offset = BJ->getBitNum(); in addOneOperandFields()
1996 else if (BJ->getBitNum() != Offset + J - I) in addOneOperandFields()
2001 if (!Var || (Var->getName() != OpName && in addOneOperandFields()
2002 Var->getName() != TiedNames[std::string(OpName)])) in addOneOperandFields()
2008 OpInfo.addField(I, J - I, Offset); in addOneOperandFields()
2019 // We are bound to fail! For proper disassembly, the well-known encoding bits in populateInstruction()
2029 // of trying to auto-generate the decoder. in populateInstruction()
2050 for (const auto &[Idx, Arg] : enumerate(Out->getArgs())) in populateInstruction()
2051 InOutOperands.push_back(std::pair(Arg, Out->getArgNameStr(Idx))); in populateInstruction()
2052 for (const auto &[Idx, Arg] : enumerate(In->getArgs())) in populateInstruction()
2053 InOutOperands.push_back(std::pair(Arg, In->getArgNameStr(Idx))); in populateInstruction()
2087 // First, find the operand type ("OpInit"), and sub-op names in populateInstruction()
2091 OpInit = SubArgDag->getOperator(); in populateInstruction()
2092 Record *OpTypeRec = cast<DefInit>(OpInit)->getDef(); in populateInstruction()
2093 // Lookup the sub-operands from the operand type record (note that only in populateInstruction()
2095 DagInit *SubOps = OpTypeRec->isSubClassOf("Operand") in populateInstruction()
2096 ? OpTypeRec->getValueAsDag("MIOperandInfo") in populateInstruction()
2103 // If we have named sub-operands... in populateInstruction()
2105 // Then there should not be a custom decoder specified on the top-level in populateInstruction()
2110 OpInit->getAsString() + in populateInstruction()
2112 "sub-operands."); in populateInstruction()
2116 // Decode each of the sub-ops separately. in populateInstruction()
2117 assert(SubOps && SubArgDag->getNumArgs() == SubOps->getNumArgs()); in populateInstruction()
2118 for (const auto &[I, Arg] : enumerate(SubOps->getArgs())) { in populateInstruction()
2119 StringRef SubOpName = SubArgDag->getArgNameStr(I); in populateInstruction()
2120 OperandInfo SubOpInfo = getOpInfo(cast<DefInit>(Arg)->getDef()); in populateInstruction()
2129 // Otherwise, if we have an operand with sub-operands, but they aren't in populateInstruction()
2132 // If it's a single sub-operand, and no custom decoder, use the decoder in populateInstruction()
2133 // from the one sub-operand. in populateInstruction()
2134 if (SubOps->getNumArgs() == 1) in populateInstruction()
2135 OpInfo = getOpInfo(cast<DefInit>(SubOps->getArg(0))->getDef()); in populateInstruction()
2137 // If we have multiple sub-ops, there'd better have a custom in populateInstruction()
2139 if (SubOps->getNumArgs() > 1) { in populateInstruction()
2181 // emitFieldFromInstruction - Emit the templated helper function
2189 // InsnType must either be integral or an APInt-like object that must: in emitFieldFromInstruction()
2190 // * be default-constructible and copy-constructible in emitFieldFromInstruction()
2204 assert(startBit + numBits <= 64 && "Cannot support >64-bit extractions!"); in emitFieldFromInstruction()
2209 fieldMask = (InsnType)(-1LL); in emitFieldFromInstruction()
2211 fieldMask = (((InsnType)1 << numBits) - 1) << startBit; in emitFieldFromInstruction()
2224 // emitInsertBits - Emit the templated helper function insertBits().
2244 // emitDecodeInstruction - Emit the templated helper function
2265 ptrdiff_t Loc = Ptr - DecodeTable; in emitDecodeInstruction()
2285 // NumToSkip is a plain 24-bit integer. in emitDecodeInstruction()
2295 << " continuing at " << (Ptr - DecodeTable) << "\n"); in emitDecodeInstruction()
2311 // NumToSkip is a plain 24-bit integer. in emitDecodeInstruction()
2329 // NumToSkip is a plain 24-bit integer. in emitDecodeInstruction()
2368 // NumToSkip is a plain 24-bit integer. in emitDecodeInstruction()
2390 LLVM_DEBUG(dbgs() << "FAIL: continuing at " << (Ptr - DecodeTable) << "\n"); in emitDecodeInstruction()
2420 // callers are expected to early-exit in that condition. (Note, the '&' operator
2441 if (P.second->isSubClassOf("InstructionEncoding")) { in collectHwModesReferencedForEncodings()
2443 std::string(P.second->getValueAsString("DecoderNamespace")); in collectHwModesReferencedForEncodings()
2466 const Record *InstDef = Instr->TheDef; in handleHwModesUnrelatedEncodings()
2476 std::string(InstDef->getValueAsString("DecoderNamespace")); in handleHwModesUnrelatedEncodings()
2479 for (StringRef HwModeName : It->second) in handleHwModesUnrelatedEncodings()
2518 // First, collect all encoding-related HwModes referenced by the target. in run()
2531 const Record *InstDef = NumberedInstruction->TheDef; in run()
2532 if (const RecordVal *RV = InstDef->getValue("EncodingInfos")) { in run()
2533 if (DefInit *DI = dyn_cast_or_null<DefInit>(RV->getValue())) { in run()
2534 EncodingInfoByHwMode EBM(DI->getDef(), HWM); in run()
2556 &Target.getInstruction(NumberedAlias->getValueAsDef("AliasOf"))); in run()
2568 const Record *Def = Inst->TheDef; in run()
2569 unsigned Size = EncodingDef->getValueAsInt("Size"); in run()
2570 if (Def->getValueAsString("Namespace") == "TargetOpcode" || in run()
2571 Def->getValueAsBit("isPseudo") || in run()
2572 Def->getValueAsBit("isAsmParserOnly") || in run()
2573 Def->getValueAsBit("isCodeGenOnly")) { in run()
2595 std::string(EncodingDef->getValueAsString("DecoderNamespace")); in run()
2611 FilterChooser FC(NumberedEncodingsRef, Opc.second, Operands, in run() local
2621 FC.emitTableEntries(TableInfo); in run()
2624 assert(TableInfo.FixupStack.size() == 1 && "fixup stack phasing error!"); in run()
2633 emitTable(OS, TableInfo.Table, 0, FC.getBitWidth(), Opc.first.first, in run()