[llvm] [TableGen] Remove unused Target from InstructionEncoding methods (NFC) (PR #159833)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 19 13:55:26 PDT 2025
https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/159833
>From 77242877118554c7debb00715d27055897173a18 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Fri, 19 Sep 2025 21:57:12 +0300
Subject: [PATCH 1/2] [TableGen] Remove unused Target from InstructionEncoding
methods (NFC)
---
.../TableGen/Common/InstructionEncoding.cpp | 31 ++++++++-----------
.../TableGen/Common/InstructionEncoding.h | 11 +++----
llvm/utils/TableGen/DecoderEmitter.cpp | 12 +++----
3 files changed, 23 insertions(+), 31 deletions(-)
diff --git a/llvm/utils/TableGen/Common/InstructionEncoding.cpp b/llvm/utils/TableGen/Common/InstructionEncoding.cpp
index c6c006b527b05..7260ee3d9b534 100644
--- a/llvm/utils/TableGen/Common/InstructionEncoding.cpp
+++ b/llvm/utils/TableGen/Common/InstructionEncoding.cpp
@@ -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");
@@ -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";
@@ -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 =
@@ -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);
}
@@ -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);
@@ -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;
@@ -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()) {
@@ -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));
@@ -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;
@@ -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()) {
diff --git a/llvm/utils/TableGen/Common/InstructionEncoding.h b/llvm/utils/TableGen/Common/InstructionEncoding.h
index 412f93402170c..d9e70edb0b04e 100644
--- a/llvm/utils/TableGen/Common/InstructionEncoding.h
+++ b/llvm/utils/TableGen/Common/InstructionEncoding.h
@@ -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.
@@ -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
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 10863343d4625..ff8d8a804125b 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -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);
@@ -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:
@@ -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.
@@ -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.
@@ -1888,7 +1886,7 @@ void DecoderEmitter::parseInstructionEncodings() {
continue;
}
unsigned EncodingID = Encodings.size();
- Encodings.emplace_back(Target, EncodingDef,
+ Encodings.emplace_back(EncodingDef,
&Target.getInstruction(InstDef));
EncodingIDsByHwMode[DefaultMode].push_back(EncodingID);
}
>From 41889d5b82c39954a2de1f6611fc2acfeeb54a63 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Fri, 19 Sep 2025 21:59:53 +0300
Subject: [PATCH 2/2] formatting
---
llvm/utils/TableGen/DecoderEmitter.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index ff8d8a804125b..990bbb973e21d 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -1886,8 +1886,7 @@ void DecoderEmitter::parseInstructionEncodings() {
continue;
}
unsigned EncodingID = Encodings.size();
- Encodings.emplace_back(EncodingDef,
- &Target.getInstruction(InstDef));
+ Encodings.emplace_back(EncodingDef, &Target.getInstruction(InstDef));
EncodingIDsByHwMode[DefaultMode].push_back(EncodingID);
}
More information about the llvm-commits
mailing list