Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions llvm/utils/TableGen/Common/InstructionEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
using namespace llvm;

std::pair<std::string, bool>
InstructionEncoding::findOperandDecoderMethod(const CodeGenTarget &Target,
const Record *Record) {
InstructionEncoding::findOperandDecoderMethod(const Record *Record) {
std::string Decoder;

const RecordVal *DecoderString = Record->getValue("DecoderMethod");
Expand All @@ -30,7 +29,7 @@ InstructionEncoding::findOperandDecoderMethod(const CodeGenTarget &Target,

if (Record->isSubClassOf("RegisterOperand"))
// Allows use of a DecoderMethod in referenced RegisterClass if set.
return findOperandDecoderMethod(Target, Record->getValueAsDef("RegClass"));
return findOperandDecoderMethod(Record->getValueAsDef("RegClass"));

if (Record->isSubClassOf("RegisterClass")) {
Decoder = "Decode" + Record->getName().str() + "RegisterClass";
Expand All @@ -44,8 +43,7 @@ InstructionEncoding::findOperandDecoderMethod(const CodeGenTarget &Target,
return {Decoder, true};
}

OperandInfo InstructionEncoding::getOpInfo(const CodeGenTarget &Target,
const Record *TypeRecord) {
OperandInfo InstructionEncoding::getOpInfo(const Record *TypeRecord) {
const RecordVal *HasCompleteDecoderVal =
TypeRecord->getValue("hasCompleteDecoder");
const BitInit *HasCompleteDecoderBit =
Expand All @@ -55,7 +53,7 @@ OperandInfo InstructionEncoding::getOpInfo(const CodeGenTarget &Target,
bool HasCompleteDecoder =
HasCompleteDecoderBit ? HasCompleteDecoderBit->getValue() : true;

return OperandInfo(findOperandDecoderMethod(Target, TypeRecord).first,
return OperandInfo(findOperandDecoderMethod(TypeRecord).first,
HasCompleteDecoder);
}

Expand Down Expand Up @@ -177,16 +175,15 @@ void InstructionEncoding::parseFixedLenEncoding(
}
}

void InstructionEncoding::parseVarLenOperands(const CodeGenTarget &Target,
const VarLenInst &VLI) {
void InstructionEncoding::parseVarLenOperands(const VarLenInst &VLI) {
SmallVector<int> TiedTo;

for (const auto &[Idx, Op] : enumerate(Inst->Operands)) {
if (Op.MIOperandInfo && Op.MIOperandInfo->getNumArgs() > 0)
for (auto *Arg : Op.MIOperandInfo->getArgs())
Operands.push_back(getOpInfo(Target, cast<DefInit>(Arg)->getDef()));
Operands.push_back(getOpInfo(cast<DefInit>(Arg)->getDef()));
else
Operands.push_back(getOpInfo(Target, Op.Rec));
Operands.push_back(getOpInfo(Op.Rec));

int TiedReg = Op.getTiedRegister();
TiedTo.push_back(-1);
Expand Down Expand Up @@ -321,8 +318,7 @@ static void addOneOperandFields(const Record *EncodingDef,
}
}

void InstructionEncoding::parseFixedLenOperands(const CodeGenTarget &Target,
const BitsInit &Bits) {
void InstructionEncoding::parseFixedLenOperands(const BitsInit &Bits) {
// Search for tied operands, so that we can correctly instantiate
// operands that are not explicitly represented in the encoding.
std::map<StringRef, StringRef> TiedNames;
Expand All @@ -348,7 +344,7 @@ void InstructionEncoding::parseFixedLenOperands(const CodeGenTarget &Target,
for (const CGIOperandList::OperandInfo &Op : Inst->Operands) {
// Lookup the decoder method and construct a new OperandInfo to hold our
// result.
OperandInfo OpInfo = getOpInfo(Target, Op.Rec);
OperandInfo OpInfo = getOpInfo(Op.Rec);

// If we have named sub-operands...
if (Op.MIOperandInfo && !Op.SubOpNames[0].empty()) {
Expand All @@ -367,7 +363,7 @@ void InstructionEncoding::parseFixedLenOperands(const CodeGenTarget &Target,
for (auto [SubOpName, SubOp] :
zip_equal(Op.SubOpNames, Op.MIOperandInfo->getArgs())) {
const Record *SubOpRec = cast<DefInit>(SubOp)->getDef();
OperandInfo SubOpInfo = getOpInfo(Target, SubOpRec);
OperandInfo SubOpInfo = getOpInfo(SubOpRec);
addOneOperandFields(EncodingDef, Bits, TiedNames, SubOpRec, SubOpName,
SubOpInfo);
Operands.push_back(std::move(SubOpInfo));
Expand Down Expand Up @@ -395,8 +391,7 @@ void InstructionEncoding::parseFixedLenOperands(const CodeGenTarget &Target,
}
}

InstructionEncoding::InstructionEncoding(const CodeGenTarget &Target,
const Record *EncodingDef,
InstructionEncoding::InstructionEncoding(const Record *EncodingDef,
const CodeGenInstruction *Inst)
: EncodingDef(EncodingDef), Inst(Inst) {
const Record *InstDef = Inst->TheDef;
Expand All @@ -417,13 +412,13 @@ InstructionEncoding::InstructionEncoding(const CodeGenTarget &Target,
parseVarLenEncoding(VLI);
// If the encoding has a custom decoder, don't bother parsing the operands.
if (DecoderMethod.empty())
parseVarLenOperands(Target, VLI);
parseVarLenOperands(VLI);
} else {
const auto *BI = cast<BitsInit>(InstField->getValue());
parseFixedLenEncoding(*BI);
// If the encoding has a custom decoder, don't bother parsing the operands.
if (DecoderMethod.empty())
parseFixedLenOperands(Target, *BI);
parseFixedLenOperands(*BI);
}

if (DecoderMethod.empty()) {
Expand Down
11 changes: 5 additions & 6 deletions llvm/utils/TableGen/Common/InstructionEncoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class InstructionEncoding {
SmallVector<OperandInfo, 16> Operands;

public:
InstructionEncoding(const CodeGenTarget &Target, const Record *EncodingDef,
InstructionEncoding(const Record *EncodingDef,
const CodeGenInstruction *Inst);

/// Returns the Record this encoding originates from.
Expand Down Expand Up @@ -141,17 +141,16 @@ class InstructionEncoding {
/// \returns the effective value of the DecoderMethod field. If DecoderMethod
/// is an explictly set value, return false for second.
static std::pair<std::string, bool>
findOperandDecoderMethod(const CodeGenTarget &Target, const Record *Record);
findOperandDecoderMethod(const Record *Record);

static OperandInfo getOpInfo(const CodeGenTarget &Target,
const Record *TypeRecord);
static OperandInfo getOpInfo(const Record *TypeRecord);

private:
void parseVarLenEncoding(const VarLenInst &VLI);
void parseFixedLenEncoding(const BitsInit &RecordInstBits);

void parseVarLenOperands(const CodeGenTarget &Target, const VarLenInst &VLI);
void parseFixedLenOperands(const CodeGenTarget &Target, const BitsInit &Bits);
void parseVarLenOperands(const VarLenInst &VLI);
void parseFixedLenOperands(const BitsInit &Bits);
};

} // namespace llvm
Expand Down
13 changes: 5 additions & 8 deletions llvm/utils/TableGen/DecoderEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,7 @@ void DecoderEmitter::emitRegClassByHwModeDecoders(

for (const Record *ClassByHwMode : RegClassByHwMode) {
// Ignore cases that had an explicit DecoderMethod set.
if (!InstructionEncoding::findOperandDecoderMethod(Target, ClassByHwMode)
.second)
if (!InstructionEncoding::findOperandDecoderMethod(ClassByHwMode).second)
continue;

const HwModeSelect &ModeSelect = CGH.getHwModeSelect(ClassByHwMode);
Expand All @@ -880,8 +879,7 @@ void DecoderEmitter::emitRegClassByHwModeDecoders(
OS << indent(2) << "case " << ModeID << ": // "
<< CGH.getModeName(ModeID, /*IncludeDefault=*/true) << '\n'
<< indent(4) << "return "
<< InstructionEncoding::findOperandDecoderMethod(Target, RegClassRec)
.first
<< InstructionEncoding::findOperandDecoderMethod(RegClassRec).first
<< "(Inst, Imm, Addr, Decoder);\n";
}
OS << indent(2) << R"(default:
Expand Down Expand Up @@ -1853,7 +1851,7 @@ void DecoderEmitter::parseInstructionEncodings() {
continue;
}
unsigned EncodingID = Encodings.size();
Encodings.emplace_back(Target, EncodingDef, Inst);
Encodings.emplace_back(EncodingDef, Inst);
EncodingIDsByHwMode[HwModeID].push_back(EncodingID);
}
continue; // Ignore encoding specified by Instruction itself.
Expand All @@ -1865,7 +1863,7 @@ void DecoderEmitter::parseInstructionEncodings() {
}

unsigned EncodingID = Encodings.size();
Encodings.emplace_back(Target, InstDef, Inst);
Encodings.emplace_back(InstDef, Inst);

// This instruction is encoded the same on all HwModes.
// According to user needs, add it to all, some, or only the default HwMode.
Expand All @@ -1888,8 +1886,7 @@ void DecoderEmitter::parseInstructionEncodings() {
continue;
}
unsigned EncodingID = Encodings.size();
Encodings.emplace_back(Target, EncodingDef,
&Target.getInstruction(InstDef));
Encodings.emplace_back(EncodingDef, &Target.getInstruction(InstDef));
EncodingIDsByHwMode[DefaultMode].push_back(EncodingID);
}

Expand Down