@@ -140,6 +140,12 @@ class InstructionEncoding {
140
140
// / The name of this encoding (for debugging purposes).
141
141
std::string Name;
142
142
143
+ // / The size of this encoding, in bits.
144
+ unsigned BitWidth;
145
+
146
+ // / Information about the operands' contribution to this encoding.
147
+ SmallVector<OperandInfo, 16 > Operands;
148
+
143
149
public:
144
150
InstructionEncoding (const Record *EncodingDef, const CodeGenInstruction *Inst)
145
151
: EncodingDef(EncodingDef), Inst(Inst) {
@@ -149,6 +155,8 @@ class InstructionEncoding {
149
155
if (EncodingDef != InstDef)
150
156
Name = (EncodingDef->getName () + Twine (' :' )).str ();
151
157
Name.append (InstDef->getName ());
158
+
159
+ BitWidth = populateEncoding ();
152
160
}
153
161
154
162
// / Returns the Record this encoding originates from.
@@ -159,6 +167,17 @@ class InstructionEncoding {
159
167
160
168
// / Returns the name of this encoding, for debugging purposes.
161
169
StringRef getName () const { return Name; }
170
+
171
+ // / Returns the size of this encoding, in bits.
172
+ unsigned getBitWidth () const { return BitWidth; }
173
+
174
+ // / Returns information about the operands' contribution to this encoding.
175
+ ArrayRef<OperandInfo> getOperands () const { return Operands; }
176
+
177
+ private:
178
+ void populateVarLenEncoding ();
179
+
180
+ unsigned populateEncoding ();
162
181
};
163
182
164
183
typedef std::vector<uint32_t > FixupList;
@@ -522,9 +541,6 @@ class FilterChooser {
522
541
// Vector of encoding IDs for this filter chooser to work on.
523
542
ArrayRef<unsigned > EncodingIDs;
524
543
525
- // Lookup table for the operand decoding of instructions.
526
- const std::map<unsigned , std::vector<OperandInfo>> &Operands;
527
-
528
544
// The selected filter, if any.
529
545
std::unique_ptr<Filter> BestFilter;
530
546
@@ -549,21 +565,19 @@ class FilterChooser {
549
565
550
566
public:
551
567
FilterChooser (ArrayRef<InstructionEncoding> Encodings,
552
- ArrayRef<unsigned > EncodingIDs,
553
- const std::map<unsigned , std::vector<OperandInfo>> &Ops,
554
- unsigned BW, const DecoderEmitter *E)
555
- : Encodings(Encodings), EncodingIDs(EncodingIDs), Operands(Ops),
568
+ ArrayRef<unsigned > EncodingIDs, unsigned BW,
569
+ const DecoderEmitter *E)
570
+ : Encodings(Encodings), EncodingIDs(EncodingIDs),
556
571
FilterBitValues (BW, BitValue::BIT_UNFILTERED), Parent(nullptr ),
557
572
BitWidth(BW), Emitter(E) {
558
573
doFilter ();
559
574
}
560
575
561
576
FilterChooser (ArrayRef<InstructionEncoding> Encodings,
562
577
ArrayRef<unsigned > EncodingIDs,
563
- const std::map<unsigned , std::vector<OperandInfo>> &Ops,
564
578
const std::vector<BitValue> &ParentFilterBitValues,
565
579
const FilterChooser &parent)
566
- : Encodings(Encodings), EncodingIDs(EncodingIDs), Operands(Ops),
580
+ : Encodings(Encodings), EncodingIDs(EncodingIDs),
567
581
FilterBitValues(ParentFilterBitValues), Parent(&parent),
568
582
BitWidth(parent.BitWidth), Emitter(parent.Emitter) {
569
583
doFilter ();
@@ -728,8 +742,8 @@ void Filter::recurse() {
728
742
729
743
// Delegates to an inferior filter chooser for further processing on this
730
744
// group of instructions whose segment values are variable.
731
- VariableFC = std::make_unique<FilterChooser>(
732
- Owner. Encodings , VariableIDs, Owner. Operands , BitValueArray, Owner);
745
+ VariableFC = std::make_unique<FilterChooser>(Owner. Encodings , VariableIDs,
746
+ BitValueArray, Owner);
733
747
}
734
748
735
749
// No need to recurse for a singleton filtered instruction.
@@ -750,9 +764,8 @@ void Filter::recurse() {
750
764
// Delegates to an inferior filter chooser for further processing on this
751
765
// category of instructions.
752
766
FilterChooserMap.try_emplace (
753
- FilterVal,
754
- std::make_unique<FilterChooser>(Owner.Encodings , EncodingIDs,
755
- Owner.Operands , BitValueArray, Owner));
767
+ FilterVal, std::make_unique<FilterChooser>(Owner.Encodings , EncodingIDs,
768
+ BitValueArray, Owner));
756
769
}
757
770
}
758
771
@@ -1235,7 +1248,7 @@ bool FilterChooser::emitDecoder(raw_ostream &OS, indent Indent,
1235
1248
unsigned EncodingID) const {
1236
1249
bool HasCompleteDecoder = true ;
1237
1250
1238
- for (const OperandInfo &Op : Operands. find (EncodingID)-> second ) {
1251
+ for (const OperandInfo &Op : Encodings[EncodingID]. getOperands () ) {
1239
1252
// If a custom instruction decoder was specified, use that.
1240
1253
if (Op.numFields () == 0 && !Op.Decoder .empty ()) {
1241
1254
HasCompleteDecoder = Op.HasCompleteDecoder ;
@@ -1849,9 +1862,7 @@ OperandInfo getOpInfo(const Record *TypeRecord) {
1849
1862
return OperandInfo (findOperandDecoderMethod (TypeRecord), HasCompleteDecoder);
1850
1863
}
1851
1864
1852
- static void parseVarLenInstOperand (const Record *EncodingDef,
1853
- std::vector<OperandInfo> &Operands,
1854
- const CodeGenInstruction *Inst) {
1865
+ void InstructionEncoding::populateVarLenEncoding () {
1855
1866
const RecordVal *RV = EncodingDef->getValue (" Inst" );
1856
1867
VarLenInst VLI (cast<DagInit>(RV->getValue ()), RV);
1857
1868
SmallVector<int > TiedTo;
@@ -1950,21 +1961,13 @@ static void addOneOperandFields(const Record *EncodingDef, const BitsInit &Bits,
1950
1961
}
1951
1962
}
1952
1963
1953
- static unsigned populateInstruction (
1954
- const CodeGenTarget &Target, const Record *EncodingDef,
1955
- const CodeGenInstruction *Inst, unsigned EncodingID,
1956
- std::map<unsigned , std::vector<OperandInfo>> &EncodingOperands,
1957
- bool IsVarLenInst) {
1964
+ unsigned InstructionEncoding::populateEncoding () {
1965
+ bool IsVarLenInst = isa<DagInit>(EncodingDef->getValueInit (" Inst" ));
1958
1966
const Record &Def = *Inst->TheDef ;
1959
- // If all the bit positions are not specified; do not decode this instruction.
1960
- // We are bound to fail! For proper disassembly, the well-known encoding bits
1961
- // of the instruction must be fully specified.
1962
1967
1963
1968
const BitsInit &Bits = getBitsField (*EncodingDef, " Inst" );
1964
- if (Bits.allInComplete ())
1965
- return 0 ;
1966
-
1967
- std::vector<OperandInfo> Operands;
1969
+ assert (!Bits.allInComplete () &&
1970
+ " Invalid encodings should have been filtered out" );
1968
1971
1969
1972
// If the instruction has specified a custom decoding hook, use that instead
1970
1973
// of trying to auto-generate the decoder.
@@ -1973,7 +1976,6 @@ static unsigned populateInstruction(
1973
1976
bool HasCompleteInstDecoder =
1974
1977
EncodingDef->getValueAsBit (" hasCompleteDecoder" );
1975
1978
Operands.push_back (OperandInfo (InstDecoder.str (), HasCompleteInstDecoder));
1976
- EncodingOperands[EncodingID] = std::move (Operands);
1977
1979
return Bits.getNumBits ();
1978
1980
}
1979
1981
@@ -2014,7 +2016,7 @@ static unsigned populateInstruction(
2014
2016
}
2015
2017
2016
2018
if (IsVarLenInst) {
2017
- parseVarLenInstOperand (EncodingDef, Operands, Inst );
2019
+ populateVarLenEncoding ( );
2018
2020
} else {
2019
2021
// For each operand, see if we can figure out where it is encoded.
2020
2022
for (const auto &Op : InOutOperands) {
@@ -2095,7 +2097,6 @@ static unsigned populateInstruction(
2095
2097
Operands.push_back (std::move (OpInfo));
2096
2098
}
2097
2099
}
2098
- EncodingOperands[EncodingID] = std::move (Operands);
2099
2100
2100
2101
#if 0
2101
2102
LLVM_DEBUG({
@@ -2606,22 +2607,16 @@ namespace {
2606
2607
emitInsertBits (OS);
2607
2608
emitCheck (OS);
2608
2609
2609
- std::map< unsigned , std::vector<OperandInfo>> Operands;
2610
+ // Do extra bookkeeping for variable-length encodings.
2610
2611
std::vector<unsigned > InstrLen;
2611
2612
bool IsVarLenInst = Target.hasVariableLengthEncodings ();
2612
- if (IsVarLenInst)
2613
- InstrLen.resize (Target.getInstructions ().size (), 0 );
2614
2613
unsigned MaxInstLen = 0 ;
2615
-
2616
- for (auto [EncodingID, Encoding] : enumerate(Encodings)) {
2617
- const Record *EncodingDef = Encoding.getRecord ();
2618
- const CodeGenInstruction *Inst = Encoding.getInstruction ();
2619
- unsigned BitWidth = populateInstruction (Target, EncodingDef, Inst,
2620
- EncodingID, Operands, IsVarLenInst);
2621
- assert (BitWidth && " Invalid encodings should have been filtered out" );
2622
- if (IsVarLenInst) {
2623
- MaxInstLen = std::max (MaxInstLen, BitWidth);
2624
- InstrLen[Target.getInstrIntValue (Inst->TheDef )] = BitWidth;
2614
+ if (IsVarLenInst) {
2615
+ InstrLen.resize (Target.getInstructions ().size (), 0 );
2616
+ for (const InstructionEncoding &Encoding : Encodings) {
2617
+ MaxInstLen = std::max (MaxInstLen, Encoding.getBitWidth ());
2618
+ InstrLen[Target.getInstrIntValue (Encoding.getInstruction ()->TheDef )] =
2619
+ Encoding.getBitWidth ();
2625
2620
}
2626
2621
}
2627
2622
@@ -2645,7 +2640,7 @@ namespace {
2645
2640
auto [DecoderNamespace, HwModeID, Size] = Key;
2646
2641
const unsigned BitWidth = IsVarLenInst ? MaxInstLen : 8 * Size;
2647
2642
// Emit the decoder for this (namespace, hwmode, width) combination.
2648
- FilterChooser FC (Encodings, EncodingIDs, Operands, BitWidth, this );
2643
+ FilterChooser FC (Encodings, EncodingIDs, BitWidth, this );
2649
2644
2650
2645
// The decode table is cleared for each top level decoder function. The
2651
2646
// predicates and decoders themselves, however, are shared across all
0 commit comments