Skip to content

Commit b96d5c2

Browse files
authored
[TableGen][DecoderEmitter] Outline InstructionEncoding constructor (NFC) (llvm#154673)
It is going to grow, so it makes sense to move its definition out of class. Instead, inline `populateInstruction()` into it. Also, rename a couple of methods to better convey their meaning.
1 parent 62aaa96 commit b96d5c2

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,8 @@ class InstructionEncoding {
155155
SmallVector<OperandInfo, 16> Operands;
156156

157157
public:
158-
InstructionEncoding(const Record *EncodingDef, const CodeGenInstruction *Inst)
159-
: EncodingDef(EncodingDef), Inst(Inst) {
160-
const Record *InstDef = Inst->TheDef;
161-
162-
// Give this encoding a name.
163-
if (EncodingDef != InstDef)
164-
Name = (EncodingDef->getName() + Twine(':')).str();
165-
Name.append(InstDef->getName());
166-
167-
DecoderMethod = EncodingDef->getValueAsString("DecoderMethod");
168-
if (!DecoderMethod.empty())
169-
HasCompleteDecoder = EncodingDef->getValueAsBit("hasCompleteDecoder");
170-
171-
populateEncoding();
172-
}
158+
InstructionEncoding(const Record *EncodingDef,
159+
const CodeGenInstruction *Inst);
173160

174161
/// Returns the Record this encoding originates from.
175162
const Record *getRecord() const { return EncodingDef; }
@@ -197,9 +184,8 @@ class InstructionEncoding {
197184
ArrayRef<OperandInfo> getOperands() const { return Operands; }
198185

199186
private:
200-
void populateVarLenEncoding(const VarLenInst &VLI);
201-
void populateFixedLenEncoding(const BitsInit &Bits);
202-
void populateEncoding();
187+
void parseVarLenOperands(const VarLenInst &VLI);
188+
void parseFixedLenOperands(const BitsInit &Bits);
203189
};
204190

205191
typedef std::vector<uint32_t> FixupList;
@@ -1899,7 +1885,7 @@ OperandInfo getOpInfo(const Record *TypeRecord) {
18991885
return OperandInfo(findOperandDecoderMethod(TypeRecord), HasCompleteDecoder);
19001886
}
19011887

1902-
void InstructionEncoding::populateVarLenEncoding(const VarLenInst &VLI) {
1888+
void InstructionEncoding::parseVarLenOperands(const VarLenInst &VLI) {
19031889
SmallVector<int> TiedTo;
19041890

19051891
for (const auto &[Idx, Op] : enumerate(Inst->Operands)) {
@@ -1996,7 +1982,7 @@ static void addOneOperandFields(const Record *EncodingDef, const BitsInit &Bits,
19961982
}
19971983
}
19981984

1999-
void InstructionEncoding::populateFixedLenEncoding(const BitsInit &Bits) {
1985+
void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
20001986
const Record &Def = *Inst->TheDef;
20011987

20021988
// Gather the outputs/inputs of the instruction, so we can find their
@@ -2110,20 +2096,33 @@ void InstructionEncoding::populateFixedLenEncoding(const BitsInit &Bits) {
21102096
}
21112097
}
21122098

2113-
void InstructionEncoding::populateEncoding() {
2099+
InstructionEncoding::InstructionEncoding(const Record *EncodingDef,
2100+
const CodeGenInstruction *Inst)
2101+
: EncodingDef(EncodingDef), Inst(Inst) {
2102+
const Record *InstDef = Inst->TheDef;
2103+
2104+
// Give this encoding a name.
2105+
if (EncodingDef != InstDef)
2106+
Name = (EncodingDef->getName() + Twine(':')).str();
2107+
Name.append(InstDef->getName());
2108+
2109+
DecoderMethod = EncodingDef->getValueAsString("DecoderMethod");
2110+
if (!DecoderMethod.empty())
2111+
HasCompleteDecoder = EncodingDef->getValueAsBit("hasCompleteDecoder");
2112+
21142113
const RecordVal *InstField = EncodingDef->getValue("Inst");
21152114
if (const auto *DI = dyn_cast<DagInit>(InstField->getValue())) {
21162115
VarLenInst VLI(DI, InstField);
21172116
BitWidth = VLI.size();
21182117
// If the encoding has a custom decoder, don't bother parsing the operands.
21192118
if (DecoderMethod.empty())
2120-
populateVarLenEncoding(VLI);
2119+
parseVarLenOperands(VLI);
21212120
} else {
21222121
const auto *BI = cast<BitsInit>(InstField->getValue());
21232122
BitWidth = BI->getNumBits();
21242123
// If the encoding has a custom decoder, don't bother parsing the operands.
21252124
if (DecoderMethod.empty())
2126-
populateFixedLenEncoding(*BI);
2125+
parseFixedLenOperands(*BI);
21272126
}
21282127
}
21292128

0 commit comments

Comments
 (0)