Skip to content

Commit 8666ffd

Browse files
committed
[TableGen][DecoderEmitter] Rename some variables (NFC)
And change references to pointers, to make the future diff smaller.
1 parent bf6d52a commit 8666ffd

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,15 +1849,14 @@ OperandInfo getOpInfo(const Record *TypeRecord) {
18491849
return OperandInfo(findOperandDecoderMethod(TypeRecord), HasCompleteDecoder);
18501850
}
18511851

1852-
static void parseVarLenInstOperand(const Record &Def,
1852+
static void parseVarLenInstOperand(const Record *EncodingDef,
18531853
std::vector<OperandInfo> &Operands,
1854-
const CodeGenInstruction &CGI) {
1855-
1856-
const RecordVal *RV = Def.getValue("Inst");
1854+
const CodeGenInstruction *Inst) {
1855+
const RecordVal *RV = EncodingDef->getValue("Inst");
18571856
VarLenInst VLI(cast<DagInit>(RV->getValue()), RV);
18581857
SmallVector<int> TiedTo;
18591858

1860-
for (const auto &[Idx, Op] : enumerate(CGI.Operands)) {
1859+
for (const auto &[Idx, Op] : enumerate(Inst->Operands)) {
18611860
if (Op.MIOperandInfo && Op.MIOperandInfo->getNumArgs() > 0)
18621861
for (auto *Arg : Op.MIOperandInfo->getArgs())
18631862
Operands.push_back(getOpInfo(cast<DefInit>(Arg)->getDef()));
@@ -1885,15 +1884,15 @@ static void parseVarLenInstOperand(const Record &Def,
18851884
}
18861885

18871886
if (!OpName.empty()) {
1888-
auto OpSubOpPair = CGI.Operands.parseOperandName(OpName);
1889-
unsigned OpIdx = CGI.Operands.getFlattenedOperandNumber(OpSubOpPair);
1887+
auto OpSubOpPair = Inst->Operands.parseOperandName(OpName);
1888+
unsigned OpIdx = Inst->Operands.getFlattenedOperandNumber(OpSubOpPair);
18901889
Operands[OpIdx].addField(CurrBitPos, EncodingSegment.BitWidth, Offset);
18911890
if (!EncodingSegment.CustomDecoder.empty())
18921891
Operands[OpIdx].Decoder = EncodingSegment.CustomDecoder.str();
18931892

18941893
int TiedReg = TiedTo[OpSubOpPair.first];
18951894
if (TiedReg != -1) {
1896-
unsigned OpIdx = CGI.Operands.getFlattenedOperandNumber(
1895+
unsigned OpIdx = Inst->Operands.getFlattenedOperandNumber(
18971896
{TiedReg, OpSubOpPair.second});
18981897
Operands[OpIdx].addField(CurrBitPos, EncodingSegment.BitWidth, Offset);
18991898
}
@@ -1914,12 +1913,12 @@ static void debugDumpRecord(const Record &Rec) {
19141913
/// For an operand field named OpName: populate OpInfo.InitValue with the
19151914
/// constant-valued bit values, and OpInfo.Fields with the ranges of bits to
19161915
/// insert from the decoded instruction.
1917-
static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits,
1916+
static void addOneOperandFields(const Record *EncodingDef, const BitsInit &Bits,
19181917
std::map<StringRef, StringRef> &TiedNames,
19191918
StringRef OpName, OperandInfo &OpInfo) {
19201919
// Some bits of the operand may be required to be 1 depending on the
19211920
// instruction's encoding. Collect those bits.
1922-
if (const RecordVal *EncodedValue = EncodingDef.getValue(OpName))
1921+
if (const RecordVal *EncodedValue = EncodingDef->getValue(OpName))
19231922
if (const BitsInit *OpBits = dyn_cast<BitsInit>(EncodedValue->getValue()))
19241923
for (unsigned I = 0; I < OpBits->getNumBits(); ++I)
19251924
if (const BitInit *OpBit = dyn_cast<BitInit>(OpBits->getBit(I)))
@@ -1951,31 +1950,30 @@ static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits,
19511950
}
19521951
}
19531952

1954-
static unsigned
1955-
populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
1956-
const CodeGenInstruction &CGI, unsigned EncodingID,
1957-
std::map<unsigned, std::vector<OperandInfo>> &Operands,
1958-
bool IsVarLenInst) {
1959-
const Record &Def = *CGI.TheDef;
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) {
1958+
const Record &Def = *Inst->TheDef;
19601959
// If all the bit positions are not specified; do not decode this instruction.
19611960
// We are bound to fail! For proper disassembly, the well-known encoding bits
19621961
// of the instruction must be fully specified.
19631962

1964-
const BitsInit &Bits = getBitsField(EncodingDef, "Inst");
1963+
const BitsInit &Bits = getBitsField(*EncodingDef, "Inst");
19651964
if (Bits.allInComplete())
19661965
return 0;
19671966

1968-
std::vector<OperandInfo> InsnOperands;
1967+
std::vector<OperandInfo> Operands;
19691968

19701969
// If the instruction has specified a custom decoding hook, use that instead
19711970
// of trying to auto-generate the decoder.
1972-
StringRef InstDecoder = EncodingDef.getValueAsString("DecoderMethod");
1971+
StringRef InstDecoder = EncodingDef->getValueAsString("DecoderMethod");
19731972
if (!InstDecoder.empty()) {
19741973
bool HasCompleteInstDecoder =
1975-
EncodingDef.getValueAsBit("hasCompleteDecoder");
1976-
InsnOperands.push_back(
1977-
OperandInfo(InstDecoder.str(), HasCompleteInstDecoder));
1978-
Operands[EncodingID] = std::move(InsnOperands);
1974+
EncodingDef->getValueAsBit("hasCompleteDecoder");
1975+
Operands.push_back(OperandInfo(InstDecoder.str(), HasCompleteInstDecoder));
1976+
EncodingOperands[EncodingID] = std::move(Operands);
19791977
return Bits.getNumBits();
19801978
}
19811979

@@ -1997,15 +1995,15 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
19971995
// Search for tied operands, so that we can correctly instantiate
19981996
// operands that are not explicitly represented in the encoding.
19991997
std::map<StringRef, StringRef> TiedNames;
2000-
for (const auto &Op : CGI.Operands) {
1998+
for (const auto &Op : Inst->Operands) {
20011999
for (const auto &[J, CI] : enumerate(Op.Constraints)) {
20022000
if (!CI.isTied())
20032001
continue;
20042002
std::pair<unsigned, unsigned> SO =
2005-
CGI.Operands.getSubOperandNumber(CI.getTiedOperand());
2006-
StringRef TiedName = CGI.Operands[SO.first].SubOpNames[SO.second];
2003+
Inst->Operands.getSubOperandNumber(CI.getTiedOperand());
2004+
StringRef TiedName = Inst->Operands[SO.first].SubOpNames[SO.second];
20072005
if (TiedName.empty())
2008-
TiedName = CGI.Operands[SO.first].Name;
2006+
TiedName = Inst->Operands[SO.first].Name;
20092007
StringRef MyName = Op.SubOpNames[J];
20102008
if (MyName.empty())
20112009
MyName = Op.Name;
@@ -2016,7 +2014,7 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
20162014
}
20172015

20182016
if (IsVarLenInst) {
2019-
parseVarLenInstOperand(EncodingDef, InsnOperands, CGI);
2017+
parseVarLenInstOperand(EncodingDef, Operands, Inst);
20202018
} else {
20212019
// For each operand, see if we can figure out where it is encoded.
20222020
for (const auto &Op : InOutOperands) {
@@ -2047,7 +2045,7 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
20472045
// Then there should not be a custom decoder specified on the top-level
20482046
// type.
20492047
if (!OpInfo.Decoder.empty()) {
2050-
PrintError(EncodingDef.getLoc(),
2048+
PrintError(EncodingDef,
20512049
"DecoderEmitter: operand \"" + OpName + "\" has type \"" +
20522050
OpInit->getAsString() +
20532051
"\" with a custom DecoderMethod, but also named "
@@ -2063,7 +2061,7 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
20632061

20642062
addOneOperandFields(EncodingDef, Bits, TiedNames, SubOpName,
20652063
SubOpInfo);
2066-
InsnOperands.push_back(std::move(SubOpInfo));
2064+
Operands.push_back(std::move(SubOpInfo));
20672065
}
20682066
continue;
20692067
}
@@ -2079,11 +2077,11 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
20792077
// If we have multiple sub-ops, there'd better have a custom
20802078
// decoder. (Otherwise we don't know how to populate them properly...)
20812079
if (SubOps->getNumArgs() > 1) {
2082-
PrintError(EncodingDef.getLoc(),
2080+
PrintError(EncodingDef,
20832081
"DecoderEmitter: operand \"" + OpName +
20842082
"\" uses MIOperandInfo with multiple ops, but doesn't "
20852083
"have a custom decoder!");
2086-
debugDumpRecord(EncodingDef);
2084+
debugDumpRecord(*EncodingDef);
20872085
continue;
20882086
}
20892087
}
@@ -2094,10 +2092,10 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
20942092
// instruction! (This is a longstanding bug, which will be addressed in an
20952093
// upcoming change.)
20962094
if (OpInfo.numFields() > 0)
2097-
InsnOperands.push_back(std::move(OpInfo));
2095+
Operands.push_back(std::move(OpInfo));
20982096
}
20992097
}
2100-
Operands[EncodingID] = std::move(InsnOperands);
2098+
EncodingOperands[EncodingID] = std::move(Operands);
21012099

21022100
#if 0
21032101
LLVM_DEBUG({
@@ -2107,8 +2105,8 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
21072105
errs() << '\n';
21082106

21092107
// Dumps the list of operand info.
2110-
for (unsigned i = 0, e = CGI.Operands.size(); i != e; ++i) {
2111-
const CGIOperandList::OperandInfo &Info = CGI.Operands[i];
2108+
for (unsigned i = 0, e = Inst->Operands.size(); i != e; ++i) {
2109+
const CGIOperandList::OperandInfo &Info = Inst->Operands[i];
21122110
const std::string &OperandName = Info.Name;
21132111
const Record &OperandDef = *Info.Rec;
21142112

@@ -2618,7 +2616,7 @@ namespace {
26182616
for (auto [EncodingID, Encoding] : enumerate(Encodings)) {
26192617
const Record *EncodingDef = Encoding.getRecord();
26202618
const CodeGenInstruction *Inst = Encoding.getInstruction();
2621-
unsigned BitWidth = populateInstruction(Target, *EncodingDef, *Inst,
2619+
unsigned BitWidth = populateInstruction(Target, EncodingDef, Inst,
26222620
EncodingID, Operands, IsVarLenInst);
26232621
assert(BitWidth && "Invalid encodings should have been filtered out");
26242622
if (IsVarLenInst) {

0 commit comments

Comments
 (0)