[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;
|
SmallVector<OperandInfo, 16> Operands;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InstructionEncoding(const Record *EncodingDef, const CodeGenInstruction *Inst)
|
InstructionEncoding(const Record *EncodingDef,
|
||||||
: EncodingDef(EncodingDef), Inst(Inst) {
|
const CodeGenInstruction *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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the Record this encoding originates from.
|
/// Returns the Record this encoding originates from.
|
||||||
const Record *getRecord() const { return EncodingDef; }
|
const Record *getRecord() const { return EncodingDef; }
|
||||||
@ -197,9 +184,8 @@ public:
|
|||||||
ArrayRef<OperandInfo> getOperands() const { return Operands; }
|
ArrayRef<OperandInfo> getOperands() const { return Operands; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void populateVarLenEncoding(const VarLenInst &VLI);
|
void parseVarLenOperands(const VarLenInst &VLI);
|
||||||
void populateFixedLenEncoding(const BitsInit &Bits);
|
void parseFixedLenOperands(const BitsInit &Bits);
|
||||||
void populateEncoding();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<uint32_t> FixupList;
|
typedef std::vector<uint32_t> FixupList;
|
||||||
@ -1899,7 +1885,7 @@ OperandInfo getOpInfo(const Record *TypeRecord) {
|
|||||||
return OperandInfo(findOperandDecoderMethod(TypeRecord), HasCompleteDecoder);
|
return OperandInfo(findOperandDecoderMethod(TypeRecord), HasCompleteDecoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstructionEncoding::populateVarLenEncoding(const VarLenInst &VLI) {
|
void InstructionEncoding::parseVarLenOperands(const VarLenInst &VLI) {
|
||||||
SmallVector<int> TiedTo;
|
SmallVector<int> TiedTo;
|
||||||
|
|
||||||
for (const auto &[Idx, Op] : enumerate(Inst->Operands)) {
|
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;
|
const Record &Def = *Inst->TheDef;
|
||||||
|
|
||||||
// Gather the outputs/inputs of the instruction, so we can find their
|
// 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");
|
const RecordVal *InstField = EncodingDef->getValue("Inst");
|
||||||
if (const auto *DI = dyn_cast<DagInit>(InstField->getValue())) {
|
if (const auto *DI = dyn_cast<DagInit>(InstField->getValue())) {
|
||||||
VarLenInst VLI(DI, InstField);
|
VarLenInst VLI(DI, InstField);
|
||||||
BitWidth = VLI.size();
|
BitWidth = VLI.size();
|
||||||
// If the encoding has a custom decoder, don't bother parsing the operands.
|
// If the encoding has a custom decoder, don't bother parsing the operands.
|
||||||
if (DecoderMethod.empty())
|
if (DecoderMethod.empty())
|
||||||
populateVarLenEncoding(VLI);
|
parseVarLenOperands(VLI);
|
||||||
} else {
|
} else {
|
||||||
const auto *BI = cast<BitsInit>(InstField->getValue());
|
const auto *BI = cast<BitsInit>(InstField->getValue());
|
||||||
BitWidth = BI->getNumBits();
|
BitWidth = BI->getNumBits();
|
||||||
// If the encoding has a custom decoder, don't bother parsing the operands.
|
// If the encoding has a custom decoder, don't bother parsing the operands.
|
||||||
if (DecoderMethod.empty())
|
if (DecoderMethod.empty())
|
||||||
populateFixedLenEncoding(*BI);
|
parseFixedLenOperands(*BI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user