[TableGen][DecoderEmitter] Outline InstructionEncoding constructor (NFC) (#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.
This commit is contained in:
parent
62aaa96d6f
commit
b96d5c2452
@ -155,21 +155,8 @@ class InstructionEncoding {
|
||||
SmallVector<OperandInfo, 16> Operands;
|
||||
|
||||
public:
|
||||
InstructionEncoding(const Record *EncodingDef, const CodeGenInstruction *Inst)
|
||||
: EncodingDef(EncodingDef), Inst(Inst) {
|
||||
const Record *InstDef = Inst->TheDef;
|
||||
|
||||
// Give this encoding a name.
|
||||
if (EncodingDef != InstDef)
|
||||
Name = (EncodingDef->getName() + Twine(':')).str();
|
||||
Name.append(InstDef->getName());
|
||||
|
||||
DecoderMethod = EncodingDef->getValueAsString("DecoderMethod");
|
||||
if (!DecoderMethod.empty())
|
||||
HasCompleteDecoder = EncodingDef->getValueAsBit("hasCompleteDecoder");
|
||||
|
||||
populateEncoding();
|
||||
}
|
||||
InstructionEncoding(const Record *EncodingDef,
|
||||
const CodeGenInstruction *Inst);
|
||||
|
||||
/// Returns the Record this encoding originates from.
|
||||
const Record *getRecord() const { return EncodingDef; }
|
||||
@ -197,9 +184,8 @@ public:
|
||||
ArrayRef<OperandInfo> getOperands() const { return Operands; }
|
||||
|
||||
private:
|
||||
void populateVarLenEncoding(const VarLenInst &VLI);
|
||||
void populateFixedLenEncoding(const BitsInit &Bits);
|
||||
void populateEncoding();
|
||||
void parseVarLenOperands(const VarLenInst &VLI);
|
||||
void parseFixedLenOperands(const BitsInit &Bits);
|
||||
};
|
||||
|
||||
typedef std::vector<uint32_t> FixupList;
|
||||
@ -1899,7 +1885,7 @@ OperandInfo getOpInfo(const Record *TypeRecord) {
|
||||
return OperandInfo(findOperandDecoderMethod(TypeRecord), HasCompleteDecoder);
|
||||
}
|
||||
|
||||
void InstructionEncoding::populateVarLenEncoding(const VarLenInst &VLI) {
|
||||
void InstructionEncoding::parseVarLenOperands(const VarLenInst &VLI) {
|
||||
SmallVector<int> TiedTo;
|
||||
|
||||
for (const auto &[Idx, Op] : enumerate(Inst->Operands)) {
|
||||
@ -1996,7 +1982,7 @@ static void addOneOperandFields(const Record *EncodingDef, const BitsInit &Bits,
|
||||
}
|
||||
}
|
||||
|
||||
void InstructionEncoding::populateFixedLenEncoding(const BitsInit &Bits) {
|
||||
void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
|
||||
const Record &Def = *Inst->TheDef;
|
||||
|
||||
// Gather the outputs/inputs of the instruction, so we can find their
|
||||
@ -2110,20 +2096,33 @@ void InstructionEncoding::populateFixedLenEncoding(const BitsInit &Bits) {
|
||||
}
|
||||
}
|
||||
|
||||
void InstructionEncoding::populateEncoding() {
|
||||
InstructionEncoding::InstructionEncoding(const Record *EncodingDef,
|
||||
const CodeGenInstruction *Inst)
|
||||
: EncodingDef(EncodingDef), Inst(Inst) {
|
||||
const Record *InstDef = Inst->TheDef;
|
||||
|
||||
// Give this encoding a name.
|
||||
if (EncodingDef != InstDef)
|
||||
Name = (EncodingDef->getName() + Twine(':')).str();
|
||||
Name.append(InstDef->getName());
|
||||
|
||||
DecoderMethod = EncodingDef->getValueAsString("DecoderMethod");
|
||||
if (!DecoderMethod.empty())
|
||||
HasCompleteDecoder = EncodingDef->getValueAsBit("hasCompleteDecoder");
|
||||
|
||||
const RecordVal *InstField = EncodingDef->getValue("Inst");
|
||||
if (const auto *DI = dyn_cast<DagInit>(InstField->getValue())) {
|
||||
VarLenInst VLI(DI, InstField);
|
||||
BitWidth = VLI.size();
|
||||
// If the encoding has a custom decoder, don't bother parsing the operands.
|
||||
if (DecoderMethod.empty())
|
||||
populateVarLenEncoding(VLI);
|
||||
parseVarLenOperands(VLI);
|
||||
} else {
|
||||
const auto *BI = cast<BitsInit>(InstField->getValue());
|
||||
BitWidth = BI->getNumBits();
|
||||
// If the encoding has a custom decoder, don't bother parsing the operands.
|
||||
if (DecoderMethod.empty())
|
||||
populateFixedLenEncoding(*BI);
|
||||
parseFixedLenOperands(*BI);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user