Skip to content

Commit 13dd650

Browse files
committed
[TableGen][DecoderEmitter] Rename some variables for clarity (NFC)
1 parent c2eb895 commit 13dd650

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ class FilterChooser {
486486
protected:
487487
friend class Filter;
488488

489-
// Vector of codegen instructions to choose our filter.
490-
ArrayRef<EncodingAndInst> AllInstructions;
489+
// Vector of encodings to choose our filter.
490+
ArrayRef<EncodingAndInst> Encodings;
491491

492-
// Vector of uid's for this filter chooser to work on.
492+
// Vector of encoding IDs for this filter chooser to work on.
493493
ArrayRef<unsigned> EncodingIDs;
494494

495495
// Lookup table for the operand decoding of instructions.
@@ -518,20 +518,22 @@ class FilterChooser {
518518
};
519519

520520
public:
521-
FilterChooser(ArrayRef<EncodingAndInst> Insts, ArrayRef<unsigned> EncodingIDs,
521+
FilterChooser(ArrayRef<EncodingAndInst> Encodings,
522+
ArrayRef<unsigned> EncodingIDs,
522523
const std::map<unsigned, std::vector<OperandInfo>> &Ops,
523524
unsigned BW, const DecoderEmitter *E)
524-
: AllInstructions(Insts), EncodingIDs(EncodingIDs), Operands(Ops),
525+
: Encodings(Encodings), EncodingIDs(EncodingIDs), Operands(Ops),
525526
FilterBitValues(BW, BitValue::BIT_UNFILTERED), Parent(nullptr),
526527
BitWidth(BW), Emitter(E) {
527528
doFilter();
528529
}
529530

530-
FilterChooser(ArrayRef<EncodingAndInst> Insts, ArrayRef<unsigned> EncodingIDs,
531+
FilterChooser(ArrayRef<EncodingAndInst> Encodings,
532+
ArrayRef<unsigned> EncodingIDs,
531533
const std::map<unsigned, std::vector<OperandInfo>> &Ops,
532534
const std::vector<BitValue> &ParentFilterBitValues,
533535
const FilterChooser &parent)
534-
: AllInstructions(Insts), EncodingIDs(EncodingIDs), Operands(Ops),
536+
: Encodings(Encodings), EncodingIDs(EncodingIDs), Operands(Ops),
535537
FilterBitValues(ParentFilterBitValues), Parent(&parent),
536538
BitWidth(parent.BitWidth), Emitter(parent.Emitter) {
537539
doFilter();
@@ -544,8 +546,8 @@ class FilterChooser {
544546

545547
protected:
546548
// Populates the insn given the uid.
547-
insn_t insnWithID(unsigned Opcode) const {
548-
const Record *EncodingDef = AllInstructions[Opcode].EncodingDef;
549+
insn_t insnWithID(unsigned EncodingID) const {
550+
const Record *EncodingDef = Encodings[EncodingID].EncodingDef;
549551
const BitsInit &Bits = getBitsField(*EncodingDef, "Inst");
550552
insn_t Insn(std::max(BitWidth, Bits.getNumBits()), BitValue::BIT_UNSET);
551553
// We may have a SoftFail bitmask, which specifies a mask where an encoding
@@ -584,15 +586,17 @@ class FilterChooser {
584586

585587
// Emits code to check the Predicates member of an instruction are true.
586588
// Returns true if predicate matches were emitted, false otherwise.
587-
bool emitPredicateMatch(raw_ostream &OS, unsigned Opc) const;
589+
bool emitPredicateMatch(raw_ostream &OS, unsigned EncodingID) const;
588590
bool emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
589591
raw_ostream &OS) const;
590592

591-
bool doesOpcodeNeedPredicate(unsigned Opc) const;
593+
bool doesOpcodeNeedPredicate(unsigned EncodingID) const;
592594
unsigned getPredicateIndex(DecoderTableInfo &TableInfo, StringRef P) const;
593-
void emitPredicateTableEntry(DecoderTableInfo &TableInfo, unsigned Opc) const;
595+
void emitPredicateTableEntry(DecoderTableInfo &TableInfo,
596+
unsigned EncodingID) const;
594597

595-
void emitSoftFailTableEntry(DecoderTableInfo &TableInfo, unsigned Opc) const;
598+
void emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
599+
unsigned EncodingID) const;
596600

597601
// Emits table entries to decode the singleton.
598602
void emitSingletonTableEntry(DecoderTableInfo &TableInfo,
@@ -605,9 +609,9 @@ class FilterChooser {
605609
bool emitBinaryParser(raw_ostream &OS, indent Indent,
606610
const OperandInfo &OpInfo) const;
607611

608-
bool emitDecoder(raw_ostream &OS, indent Indent, unsigned Opc) const;
612+
bool emitDecoder(raw_ostream &OS, indent Indent, unsigned EncodingID) const;
609613
std::pair<unsigned, bool> getDecoderIndex(DecoderSet &Decoders,
610-
unsigned Opc) const;
614+
unsigned EncodingID) const;
611615

612616
// Assign a single filter and run with it.
613617
void runSingleFilter(unsigned startBit, unsigned numBit);
@@ -694,9 +698,8 @@ void Filter::recurse() {
694698

695699
// Delegates to an inferior filter chooser for further processing on this
696700
// group of instructions whose segment values are variable.
697-
VariableFC =
698-
std::make_unique<FilterChooser>(Owner.AllInstructions, VariableIDs,
699-
Owner.Operands, BitValueArray, Owner);
701+
VariableFC = std::make_unique<FilterChooser>(
702+
Owner.Encodings, VariableIDs, Owner.Operands, BitValueArray, Owner);
700703
}
701704

702705
// No need to recurse for a singleton filtered instruction.
@@ -718,7 +721,7 @@ void Filter::recurse() {
718721
// category of instructions.
719722
FilterChooserMap.try_emplace(
720723
FilterVal,
721-
std::make_unique<FilterChooser>(Owner.AllInstructions, EncodingIDs,
724+
std::make_unique<FilterChooser>(Owner.Encodings, EncodingIDs,
722725
Owner.Operands, BitValueArray, Owner));
723726
}
724727
}
@@ -1197,10 +1200,10 @@ bool FilterChooser::emitBinaryParser(raw_ostream &OS, indent Indent,
11971200
}
11981201

11991202
bool FilterChooser::emitDecoder(raw_ostream &OS, indent Indent,
1200-
unsigned Opc) const {
1203+
unsigned EncodingID) const {
12011204
bool HasCompleteDecoder = true;
12021205

1203-
for (const auto &Op : Operands.find(Opc)->second) {
1206+
for (const OperandInfo &Op : Operands.find(EncodingID)->second) {
12041207
// If a custom instruction decoder was specified, use that.
12051208
if (Op.numFields() == 0 && !Op.Decoder.empty()) {
12061209
HasCompleteDecoder = Op.HasCompleteDecoder;
@@ -1216,15 +1219,16 @@ bool FilterChooser::emitDecoder(raw_ostream &OS, indent Indent,
12161219
return HasCompleteDecoder;
12171220
}
12181221

1219-
std::pair<unsigned, bool> FilterChooser::getDecoderIndex(DecoderSet &Decoders,
1220-
unsigned Opc) const {
1222+
std::pair<unsigned, bool>
1223+
FilterChooser::getDecoderIndex(DecoderSet &Decoders,
1224+
unsigned EncodingID) const {
12211225
// Build up the predicate string.
12221226
SmallString<256> Decoder;
12231227
// FIXME: emitDecoder() function can take a buffer directly rather than
12241228
// a stream.
12251229
raw_svector_ostream S(Decoder);
12261230
indent Indent(UseFnTableInDecodeToMCInst ? 2 : 4);
1227-
bool HasCompleteDecoder = emitDecoder(S, Indent, Opc);
1231+
bool HasCompleteDecoder = emitDecoder(S, Indent, EncodingID);
12281232

12291233
// Using the full decoder string as the key value here is a bit
12301234
// heavyweight, but is effective. If the string comparisons become a
@@ -1273,9 +1277,10 @@ bool FilterChooser::emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
12731277
return true;
12741278
}
12751279

1276-
bool FilterChooser::emitPredicateMatch(raw_ostream &OS, unsigned Opc) const {
1280+
bool FilterChooser::emitPredicateMatch(raw_ostream &OS,
1281+
unsigned EncodingID) const {
12771282
const ListInit *Predicates =
1278-
AllInstructions[Opc].EncodingDef->getValueAsListInit("Predicates");
1283+
Encodings[EncodingID].EncodingDef->getValueAsListInit("Predicates");
12791284
bool IsFirstEmission = true;
12801285
for (unsigned i = 0; i < Predicates->size(); ++i) {
12811286
const Record *Pred = Predicates->getElementAsRecord(i);
@@ -1295,9 +1300,9 @@ bool FilterChooser::emitPredicateMatch(raw_ostream &OS, unsigned Opc) const {
12951300
return !Predicates->empty();
12961301
}
12971302

1298-
bool FilterChooser::doesOpcodeNeedPredicate(unsigned Opc) const {
1303+
bool FilterChooser::doesOpcodeNeedPredicate(unsigned EncodingID) const {
12991304
const ListInit *Predicates =
1300-
AllInstructions[Opc].EncodingDef->getValueAsListInit("Predicates");
1305+
Encodings[EncodingID].EncodingDef->getValueAsListInit("Predicates");
13011306
for (unsigned i = 0; i < Predicates->size(); ++i) {
13021307
const Record *Pred = Predicates->getElementAsRecord(i);
13031308
if (!Pred->getValue("AssemblerMatcherPredicate"))
@@ -1325,16 +1330,16 @@ unsigned FilterChooser::getPredicateIndex(DecoderTableInfo &TableInfo,
13251330
}
13261331

13271332
void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
1328-
unsigned Opc) const {
1329-
if (!doesOpcodeNeedPredicate(Opc))
1333+
unsigned EncodingID) const {
1334+
if (!doesOpcodeNeedPredicate(EncodingID))
13301335
return;
13311336

13321337
// Build up the predicate string.
13331338
SmallString<256> Predicate;
13341339
// FIXME: emitPredicateMatch() functions can take a buffer directly rather
13351340
// than a stream.
13361341
raw_svector_ostream PS(Predicate);
1337-
emitPredicateMatch(PS, Opc);
1342+
emitPredicateMatch(PS, EncodingID);
13381343

13391344
// Figure out the index into the predicate table for the predicate just
13401345
// computed.
@@ -1353,8 +1358,8 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
13531358
}
13541359

13551360
void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
1356-
unsigned Opc) const {
1357-
const Record *EncodingDef = AllInstructions[Opc].EncodingDef;
1361+
unsigned EncodingID) const {
1362+
const Record *EncodingDef = Encodings[EncodingID].EncodingDef;
13581363
const RecordVal *RV = EncodingDef->getValue("SoftFail");
13591364
const BitsInit *SFBits = RV ? dyn_cast<BitsInit>(RV->getValue()) : nullptr;
13601365

@@ -1380,7 +1385,7 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
13801385
} else {
13811386
// The bit is not set; this must be an error!
13821387
errs() << "SoftFail Conflict: bit SoftFail{" << i << "} in "
1383-
<< AllInstructions[Opc] << " is set but Inst{" << i
1388+
<< Encodings[EncodingID] << " is set but Inst{" << i
13841389
<< "} is unset!\n"
13851390
<< " - You can only mark a bit as SoftFail if it is fully defined"
13861391
<< " (1/0 - not '?') in Inst\n";
@@ -1453,7 +1458,7 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
14531458
: MCD::OPC_TryDecode);
14541459
TableInfo.Table.push_back(DecoderOp);
14551460
NumEncodingsSupported++;
1456-
const Record *InstDef = AllInstructions[EncodingID].Inst->TheDef;
1461+
const Record *InstDef = Encodings[EncodingID].Inst->TheDef;
14571462
TableInfo.Table.insertULEB128(Emitter->getTarget().getInstrIntValue(InstDef));
14581463
TableInfo.Table.insertULEB128(DIdx);
14591464

@@ -1748,7 +1753,7 @@ void FilterChooser::doFilter() {
17481753

17491754
// Dump encodings.
17501755
for (unsigned EncodingID : EncodingIDs) {
1751-
const EncodingAndInst &Enc = AllInstructions[EncodingID];
1756+
const EncodingAndInst &Enc = Encodings[EncodingID];
17521757
errs() << Indent;
17531758
dumpBits(errs(), getBitsField(*Enc.EncodingDef, "Inst"), BitWidth);
17541759
errs() << " " << Enc << '\n';
@@ -1919,7 +1924,7 @@ static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits,
19191924

19201925
static unsigned
19211926
populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
1922-
const CodeGenInstruction &CGI, unsigned Opc,
1927+
const CodeGenInstruction &CGI, unsigned EncodingID,
19231928
std::map<unsigned, std::vector<OperandInfo>> &Operands,
19241929
bool IsVarLenInst) {
19251930
const Record &Def = *CGI.TheDef;
@@ -1941,7 +1946,7 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
19411946
EncodingDef.getValueAsBit("hasCompleteDecoder");
19421947
InsnOperands.push_back(
19431948
OperandInfo(InstDecoder.str(), HasCompleteInstDecoder));
1944-
Operands[Opc] = std::move(InsnOperands);
1949+
Operands[EncodingID] = std::move(InsnOperands);
19451950
return Bits.getNumBits();
19461951
}
19471952

@@ -2063,7 +2068,7 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
20632068
InsnOperands.push_back(std::move(OpInfo));
20642069
}
20652070
}
2066-
Operands[Opc] = std::move(InsnOperands);
2071+
Operands[EncodingID] = std::move(InsnOperands);
20672072

20682073
#if 0
20692074
LLVM_DEBUG({

0 commit comments

Comments
 (0)