-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[NFC][TableGen] Adopt CodeGenInstruction::getName()
#156968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+85
−97
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69cff62
to
452d06e
Compare
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-llvm-globalisel Author: Rahul Joshi (jurahul) ChangesPatch is 33.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/156968.diff 15 Files Affected:
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index bfd158614ae39..a373d2e2014b1 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -1545,7 +1545,7 @@ void AsmMatcherInfo::buildInfo() {
// If the tblgen -match-prefix option is specified (for tblgen hackers),
// filter the set of instructions we consider.
- if (!StringRef(CGI->TheDef->getName()).starts_with(MatchPrefix))
+ if (!StringRef(CGI->getName()).starts_with(MatchPrefix))
continue;
// Ignore "codegen only" instructions.
@@ -1578,8 +1578,7 @@ void AsmMatcherInfo::buildInfo() {
// If the tblgen -match-prefix option is specified (for tblgen hackers),
// filter the set of instruction aliases we consider, based on the target
// instruction.
- if (!StringRef(Alias->ResultInst->TheDef->getName())
- .starts_with(MatchPrefix))
+ if (!StringRef(Alias->ResultInst->getName()).starts_with(MatchPrefix))
continue;
StringRef V = Alias->TheDef->getValueAsString("AsmVariantName");
@@ -3562,7 +3561,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
char(MI->Mnemonic.size()) + MI->Mnemonic.lower();
OS << " { " << *StringTable.GetStringOffset(LenMnemonic) << " /* "
<< MI->Mnemonic << " */, " << Target.getInstNamespace()
- << "::" << MI->getResultInst()->TheDef->getName() << ", "
+ << "::" << MI->getResultInst()->getName() << ", "
<< MI->ConversionFnKind << ", ";
// Write the required features mask.
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index cbe645778fa3f..b9e6f38257bb6 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -129,11 +129,10 @@ static void EmitInstructions(std::vector<AsmWriterInst> &Insts, raw_ostream &O,
}
}
- O << " case " << FirstInst.CGI->Namespace
- << "::" << FirstInst.CGI->TheDef->getName() << ":\n";
+ O << " case " << FirstInst.CGI->Namespace << "::" << FirstInst.CGI->getName()
+ << ":\n";
for (const AsmWriterInst &AWI : SimilarInsts)
- O << " case " << AWI.CGI->Namespace << "::" << AWI.CGI->TheDef->getName()
- << ":\n";
+ O << " case " << AWI.CGI->Namespace << "::" << AWI.CGI->getName() << ":\n";
for (unsigned i = 0, e = FirstInst.Operands.size(); i != e; ++i) {
if (i != DifferingOperand) {
// If the operand is the same for all instructions, just print it.
@@ -145,12 +144,12 @@ static void EmitInstructions(std::vector<AsmWriterInst> &Insts, raw_ostream &O,
O << " default: llvm_unreachable(\"Unexpected opcode.\");\n";
std::vector<std::pair<std::string, AsmWriterOperand>> OpsToPrint;
OpsToPrint.emplace_back(FirstInst.CGI->Namespace.str() +
- "::" + FirstInst.CGI->TheDef->getName().str(),
+ "::" + FirstInst.CGI->getName().str(),
FirstInst.Operands[i]);
for (const AsmWriterInst &AWI : SimilarInsts) {
OpsToPrint.emplace_back(AWI.CGI->Namespace.str() +
- "::" + AWI.CGI->TheDef->getName().str(),
+ "::" + AWI.CGI->getName().str(),
AWI.Operands[i]);
}
std::reverse(OpsToPrint.begin(), OpsToPrint.end());
@@ -188,11 +187,11 @@ void AsmWriterEmitter::FindUniqueOperandCommands(
if (I != UniqueOperandCommands.end()) {
size_t idx = I - UniqueOperandCommands.begin();
InstrsForCase[idx] += ", ";
- InstrsForCase[idx] += Inst.CGI->TheDef->getName();
+ InstrsForCase[idx] += Inst.CGI->getName();
InstIdxs[idx].push_back(i);
} else {
UniqueOperandCommands.push_back(std::move(Command));
- InstrsForCase.push_back(Inst.CGI->TheDef->getName().str());
+ InstrsForCase.push_back(Inst.CGI->getName().str());
InstIdxs.emplace_back();
InstIdxs.back().push_back(i);
@@ -451,7 +450,7 @@ void AsmWriterEmitter::EmitGetMnemonic(
<< "[] = {\n";
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
O << " " << ((OpcodeInfo[i] >> Shift) & Mask) << "U,\t// "
- << NumberedInstructions[i]->TheDef->getName() << "\n";
+ << NumberedInstructions[i]->getName() << "\n";
}
O << " };\n\n";
// Emit string to combine the individual table lookups.
@@ -1317,7 +1316,7 @@ AsmWriterEmitter::AsmWriterEmitter(const RecordKeeper &R)
NumberedInstructions = Target.getInstructions();
for (const auto &[Idx, I] : enumerate(NumberedInstructions)) {
- if (!I->AsmString.empty() && I->TheDef->getName() != "PHI")
+ if (!I->AsmString.empty() && I->getName() != "PHI")
Instructions.emplace_back(*I, Idx, Variant);
}
}
diff --git a/llvm/utils/TableGen/Common/AsmWriterInst.cpp b/llvm/utils/TableGen/Common/AsmWriterInst.cpp
index 3629247751d2f..97430a1eec8a1 100644
--- a/llvm/utils/TableGen/Common/AsmWriterInst.cpp
+++ b/llvm/utils/TableGen/Common/AsmWriterInst.cpp
@@ -94,7 +94,7 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
PrintFatalError(
CGI.TheDef->getLoc(),
"Non-supported escaped character found in instruction '" +
- CGI.TheDef->getName() + "'!");
+ CGI.getName() + "'!");
}
LastEmitted = DollarPos + 2;
continue;
@@ -135,7 +135,7 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
PrintFatalError(
CGI.TheDef->getLoc(),
"Reached end of string before terminating curly brace in '" +
- CGI.TheDef->getName() + "'");
+ CGI.getName() + "'");
// Look for a modifier string.
if (AsmString[VarEnd] == ':') {
@@ -144,7 +144,7 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
PrintFatalError(
CGI.TheDef->getLoc(),
"Reached end of string before terminating curly brace in '" +
- CGI.TheDef->getName() + "'");
+ CGI.getName() + "'");
std::string::size_type ModifierStart = VarEnd;
while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
@@ -152,20 +152,20 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
Modifier = AsmString.substr(ModifierStart, VarEnd - ModifierStart);
if (Modifier.empty())
PrintFatalError(CGI.TheDef->getLoc(),
- "Bad operand modifier name in '" +
- CGI.TheDef->getName() + "'");
+ "Bad operand modifier name in '" + CGI.getName() +
+ "'");
}
if (AsmString[VarEnd] != '}')
PrintFatalError(
CGI.TheDef->getLoc(),
"Variable name beginning with '{' did not end with '}' in '" +
- CGI.TheDef->getName() + "'");
+ CGI.getName() + "'");
++VarEnd;
}
if (VarName.empty() && Modifier.empty())
PrintFatalError(CGI.TheDef->getLoc(),
- "Stray '$' in '" + CGI.TheDef->getName() +
+ "Stray '$' in '" + CGI.getName() +
"' asm string, maybe you want $$?");
if (VarName.empty()) {
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
index b07ea9e9d5caf..a47ab7667d891 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
@@ -134,7 +134,7 @@ struct InstRegexOp : public SetTheory::Operator {
// The generic opcodes are unsorted, handle them manually.
for (auto *Inst : Generics) {
- StringRef InstName = Inst->TheDef->getName();
+ StringRef InstName = Inst->getName();
if (InstName.starts_with(Prefix) &&
(!Regexpr || Regexpr->match(InstName.substr(Prefix.size())))) {
Elts.insert(Inst->TheDef);
@@ -147,11 +147,10 @@ struct InstRegexOp : public SetTheory::Operator {
// sorted by name. Find the sub-ranges that start with our prefix.
struct Comp {
bool operator()(const CodeGenInstruction *LHS, StringRef RHS) {
- return LHS->TheDef->getName() < RHS;
+ return LHS->getName() < RHS;
}
bool operator()(StringRef LHS, const CodeGenInstruction *RHS) {
- return LHS < RHS->TheDef->getName() &&
- !RHS->TheDef->getName().starts_with(LHS);
+ return LHS < RHS->getName() && !RHS->getName().starts_with(LHS);
}
};
auto Range1 =
@@ -162,7 +161,7 @@ struct InstRegexOp : public SetTheory::Operator {
// For these ranges we know that instruction names start with the prefix.
// Check if there's a regex that needs to be checked.
const auto HandleNonGeneric = [&](const CodeGenInstruction *Inst) {
- StringRef InstName = Inst->TheDef->getName();
+ StringRef InstName = Inst->getName();
if (!Regexpr || Regexpr->match(InstName.substr(Prefix.size()))) {
Elts.insert(Inst->TheDef);
NumMatches++;
@@ -862,12 +861,12 @@ void CodeGenSchedModels::collectSchedClasses() {
dbgs()
<< "\n+++ ITINERARIES and/or MACHINE MODELS (collectSchedClasses) +++\n");
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
- StringRef InstName = Inst->TheDef->getName();
+ StringRef InstName = Inst->getName();
unsigned SCIdx = getSchedClassIdx(*Inst);
if (!SCIdx) {
LLVM_DEBUG({
if (!Inst->hasNoSchedulingInfo)
- dbgs() << "No machine model for " << Inst->TheDef->getName() << '\n';
+ dbgs() << "No machine model for " << Inst->getName() << '\n';
});
continue;
}
@@ -916,7 +915,7 @@ void CodeGenSchedModels::collectSchedClasses() {
if (!llvm::is_contained(ProcIndices, 0)) {
for (const CodeGenProcModel &PM : ProcModels) {
if (!llvm::is_contained(ProcIndices, PM.Index))
- dbgs() << "No machine model for " << Inst->TheDef->getName()
+ dbgs() << "No machine model for " << Inst->getName()
<< " on processor " << PM.ModelName << '\n';
}
}
@@ -1932,7 +1931,7 @@ void CodeGenSchedModels::checkCompleteness() {
if (Inst->TheDef->isValueUnset("SchedRW")) {
PrintError(Inst->TheDef->getLoc(),
"No schedule information for instruction '" +
- Inst->TheDef->getName() + "' in SchedMachineModel '" +
+ Inst->getName() + "' in SchedMachineModel '" +
ProcModel.ModelDef->getName() + "'");
Complete = false;
}
@@ -1953,7 +1952,7 @@ void CodeGenSchedModels::checkCompleteness() {
if (I == InstRWs.end()) {
PrintError(Inst->TheDef->getLoc(), "'" + ProcModel.ModelName +
"' lacks information for '" +
- Inst->TheDef->getName() + "'");
+ Inst->getName() + "'");
Complete = false;
}
}
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
index 3543bb5a55c64..255974624e8f0 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
@@ -284,7 +284,7 @@ void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, indent Indent) const {
void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, indent Indent) const {
OS << Indent;
OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
- << CGI.Namespace << "::" << CGI.TheDef->getName() << ": <todo flags> ";
+ << CGI.Namespace << "::" << CGI.getName() << ": <todo flags> ";
for (MVT::SimpleValueType VT : VTs)
OS << ' ' << getEnumName(VT);
diff --git a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
index 42c1cc91a3c1e..623fef973f989 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
@@ -1455,9 +1455,8 @@ RecordAndValue
InstructionOpcodeMatcher::getInstValue(const CodeGenInstruction *I) const {
const auto VI = OpcodeValues.find(I);
if (VI != OpcodeValues.end())
- return {MatchTable::NamedValue(2, I->Namespace, I->TheDef->getName()),
- VI->second};
- return MatchTable::NamedValue(2, I->Namespace, I->TheDef->getName());
+ return {MatchTable::NamedValue(2, I->Namespace, I->getName()), VI->second};
+ return MatchTable::NamedValue(2, I->Namespace, I->getName());
}
void InstructionOpcodeMatcher::initOpcodeValuesMap(
@@ -1474,9 +1473,8 @@ RecordAndValue InstructionOpcodeMatcher::getValue() const {
const CodeGenInstruction *I = Insts[0];
const auto VI = OpcodeValues.find(I);
if (VI != OpcodeValues.end())
- return {MatchTable::NamedValue(2, I->Namespace, I->TheDef->getName()),
- VI->second};
- return MatchTable::NamedValue(2, I->Namespace, I->TheDef->getName());
+ return {MatchTable::NamedValue(2, I->Namespace, I->getName()), VI->second};
+ return MatchTable::NamedValue(2, I->Namespace, I->getName());
}
void InstructionOpcodeMatcher::emitPredicateOpcodes(MatchTable &Table,
@@ -1503,17 +1501,17 @@ bool InstructionOpcodeMatcher::isHigherPriorityThan(
// using instruction frequency information to improve compile time.
if (const InstructionOpcodeMatcher *BO =
dyn_cast<InstructionOpcodeMatcher>(&B))
- return Insts[0]->TheDef->getName() < BO->Insts[0]->TheDef->getName();
+ return Insts[0]->getName() < BO->Insts[0]->getName();
return false;
}
bool InstructionOpcodeMatcher::isConstantInstruction() const {
- return Insts.size() == 1 && Insts[0]->TheDef->getName() == "G_CONSTANT";
+ return Insts.size() == 1 && Insts[0]->getName() == "G_CONSTANT";
}
StringRef InstructionOpcodeMatcher::getOpcode() const {
- return Insts[0]->TheDef->getName();
+ return Insts[0]->getName();
}
bool InstructionOpcodeMatcher::isVariadicNumOperands() const {
@@ -2245,7 +2243,7 @@ void BuildMIAction::emitActionOpcodes(MatchTable &Table,
<< MatchTable::Comment("RecycleInsnID")
<< MatchTable::ULEB128Value(RecycleInsnID)
<< MatchTable::Comment("Opcode")
- << MatchTable::NamedValue(2, I->Namespace, I->TheDef->getName())
+ << MatchTable::NamedValue(2, I->Namespace, I->getName())
<< MatchTable::LineBreak;
if (!I->ImplicitDefs.empty() || !I->ImplicitUses.empty()) {
@@ -2292,7 +2290,7 @@ void BuildMIAction::emitActionOpcodes(MatchTable &Table,
}
Table << MatchTable::Comment("Opcode")
- << MatchTable::NamedValue(2, I->Namespace, I->TheDef->getName())
+ << MatchTable::NamedValue(2, I->Namespace, I->getName())
<< MatchTable::LineBreak;
for (const auto &Renderer : OperandRenderers)
diff --git a/llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp b/llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp
index 07db6baef84a0..c503c9a47b4ff 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp
@@ -168,8 +168,7 @@ void Pattern::printImpl(raw_ostream &OS, bool PrintName,
void AnyOpcodePattern::print(raw_ostream &OS, bool PrintName) const {
printImpl(OS, PrintName, [&OS, this]() {
OS << "["
- << join(map_range(Insts,
- [](const auto *I) { return I->TheDef->getName(); }),
+ << join(map_range(Insts, [](const auto *I) { return I->getName(); }),
", ")
<< "]";
});
@@ -366,7 +365,7 @@ void MIFlagsInfo::addCopyFlag(StringRef InstName) { CopyF.insert(InstName); }
//===- CodeGenInstructionPattern ------------------------------------------===//
bool CodeGenInstructionPattern::is(StringRef OpcodeName) const {
- return I.TheDef->getName() == OpcodeName;
+ return I.getName() == OpcodeName;
}
bool CodeGenInstructionPattern::isVariadic() const {
@@ -416,9 +415,7 @@ MIFlagsInfo &CodeGenInstructionPattern::getOrCreateMIFlagsInfo() {
return *FI;
}
-StringRef CodeGenInstructionPattern::getInstName() const {
- return I.TheDef->getName();
-}
+StringRef CodeGenInstructionPattern::getInstName() const { return I.getName(); }
void CodeGenInstructionPattern::printExtras(raw_ostream &OS) const {
if (isIntrinsic())
diff --git a/llvm/utils/TableGen/CompressInstEmitter.cpp b/llvm/utils/TableGen/CompressInstEmitter.cpp
index 89c175bd40df8..f4ab1455c03b3 100644
--- a/llvm/utils/TableGen/CompressInstEmitter.cpp
+++ b/llvm/utils/TableGen/CompressInstEmitter.cpp
@@ -237,7 +237,7 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
// Source instructions can have at most 1 tied operand.
if (IsSourceInst && (OpNo - DAGOpNo > 1))
PrintFatalError(Rec->getLoc(),
- "Input operands for Inst '" + Inst.TheDef->getName() +
+ "Input operands for Inst '" + Inst.getName() +
"' and input Dag operand count mismatch");
continue;
@@ -249,7 +249,7 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
OpndRec = cast<DefInit>(Opnd.MIOperandInfo->getArg(SubOp))->getDef();
if (DAGOpNo >= Dag->getNumArgs())
- PrintFatalError(Rec->getLoc(), "Inst '" + Inst.TheDef->getName() +
+ PrintFatalError(Rec->getLoc(), "Inst '" + Inst.getName() +
"' and Dag operand count mismatch");
if (const auto *DI = dyn_cast<DefInit>(Dag->getArg(DAGOpNo))) {
@@ -328,7 +328,7 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
// We shouldn't have extra Dag operands.
if (DAGOpNo != Dag->getNumArgs())
- PrintFatalError(Rec->getLoc(), "Inst '" + Inst.TheDef->getName() +
+ PrintFatalError(Rec->getLoc(), "Inst '" + Inst.getName() +
"' and Dag operand count mismatch");
}
@@ -590,8 +590,8 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
llvm::stable_sort(CompressPatterns, [EType](const CompressPat &LHS,
const CompressPat &RHS) {
if (EType == EmitterType::Compress || EType == EmitterType::CheckCompress)
- return (LHS.Source.TheDef->getName() < RHS.Source.TheDef->getName());
- return (LHS.Dest.TheDef->getName() < RHS.Dest.TheDef->getName());
+ return (LHS.Source.getName() < RHS.Source.getName());
+ return (LHS.Dest.getName() < RHS.Dest.getName());
});
// A list of MCOperandPredicates for all operands in use, and the reverse map.
@@ -678,7 +678,7 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
CompressOrCheck ? CompressPat.DestOperandMap
: CompressPat.SourceOperandMap;
- CurOp = Source.TheDef->getName();
+ CurOp = Source.getName();
// Check current and previous opcode to decide to continue or end a case.
if (CurOp != PrevOp) {
if (!PrevOp.empty()) {
@@ -768,7 +768,7 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
CodeStream.indent(6) << "// " << Dest.AsmString << "\n";
if (CompressOrUncompress)
CodeStream.indent(6) << "OutInst.setOpcode(" << TargetName
- << "::" << Dest.TheDef->getName() << ");\n";
+ << "::" << Dest.getName() << ");\n";
OpNo = 0;
for (const auto &DestOperand : Dest.Operands) {
CodeStream.indent(6) << "// Operand: " << DestOperand.Name << "\n";
diff --git a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
index f62b26587cf4b..83dc34896e6f6 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
@@ -1662,8 +1662,7 @@ bool CombineRuleBuilder::emitMatchPattern(CodeExpansions &CE,
const bool IsUsingCustom...
[truncated]
|
arsenm
approved these changes
Sep 4, 2025
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.