[llvm] ef455e6 - [TableGen] Replace all lingering uses of getName with getEnumName
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 20:12:26 PDT 2024
Author: Jessica Clarke
Date: 2024-10-30T03:12:23Z
New Revision: ef455e6b16334128c008fc57a4d8ace701934e80
URL: https://github.com/llvm/llvm-project/commit/ef455e6b16334128c008fc57a4d8ace701934e80
DIFF: https://github.com/llvm/llvm-project/commit/ef455e6b16334128c008fc57a4d8ace701934e80.diff
LOG: [TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
Added:
Modified:
llvm/utils/TableGen/Common/CodeGenTarget.cpp
llvm/utils/TableGen/Common/CodeGenTarget.h
llvm/utils/TableGen/FastISelEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/Common/CodeGenTarget.cpp b/llvm/utils/TableGen/Common/CodeGenTarget.cpp
index b358518c4290b0..4e75db689a0b57 100644
--- a/llvm/utils/TableGen/Common/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenTarget.cpp
@@ -47,19 +47,6 @@ MVT::SimpleValueType llvm::getValueType(const Record *Rec) {
return (MVT::SimpleValueType)Rec->getValueAsInt("Value");
}
-StringRef llvm::getName(MVT::SimpleValueType T) {
- switch (T) {
- case MVT::Other:
- return "UNKNOWN";
- case MVT::iPTR:
- return "TLI.getPointerTy()";
- case MVT::iPTRAny:
- return "TLI.getPointerTy()";
- default:
- return getEnumName(T);
- }
-}
-
StringRef llvm::getEnumName(MVT::SimpleValueType T) {
// clang-format off
switch (T) {
diff --git a/llvm/utils/TableGen/Common/CodeGenTarget.h b/llvm/utils/TableGen/Common/CodeGenTarget.h
index c7b44f7028eb5b..8bcb2f677a00b0 100644
--- a/llvm/utils/TableGen/Common/CodeGenTarget.h
+++ b/llvm/utils/TableGen/Common/CodeGenTarget.h
@@ -46,7 +46,6 @@ class CodeGenSubRegIndex;
/// record corresponds to.
MVT::SimpleValueType getValueType(const Record *Rec);
-StringRef getName(MVT::SimpleValueType T);
StringRef getEnumName(MVT::SimpleValueType T);
/// getQualifiedName - Return the name of the specified record, with a
diff --git a/llvm/utils/TableGen/FastISelEmitter.cpp b/llvm/utils/TableGen/FastISelEmitter.cpp
index 17198c85f06009..2052222cae5e5f 100644
--- a/llvm/utils/TableGen/FastISelEmitter.cpp
+++ b/llvm/utils/TableGen/FastISelEmitter.cpp
@@ -718,19 +718,20 @@ void FastISelMap::printFunctionDefinitions(raw_ostream &OS) {
const PredMap &PM = RI.second;
OS << "unsigned fastEmit_" << getLegalCName(Opcode) << "_"
- << getLegalCName(std::string(getName(VT))) << "_"
- << getLegalCName(std::string(getName(RetVT))) << "_";
+ << getLegalCName(std::string(getEnumName(VT))) << "_"
+ << getLegalCName(std::string(getEnumName(RetVT))) << "_";
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
OS << "(";
Operands.PrintParameters(OS);
OS << ") {\n";
- emitInstructionCode(OS, Operands, PM, std::string(getName(RetVT)));
+ emitInstructionCode(OS, Operands, PM,
+ std::string(getEnumName(RetVT)));
}
// Emit one function for the type that demultiplexes on return type.
OS << "unsigned fastEmit_" << getLegalCName(Opcode) << "_"
- << getLegalCName(std::string(getName(VT))) << "_";
+ << getLegalCName(std::string(getEnumName(VT))) << "_";
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
OS << "(MVT RetVT";
if (!Operands.empty())
@@ -739,10 +740,10 @@ void FastISelMap::printFunctionDefinitions(raw_ostream &OS) {
OS << ") {\nswitch (RetVT.SimpleTy) {\n";
for (const auto &RI : RM) {
MVT::SimpleValueType RetVT = RI.first;
- OS << " case " << getName(RetVT) << ": return fastEmit_"
+ OS << " case " << getEnumName(RetVT) << ": return fastEmit_"
<< getLegalCName(Opcode) << "_"
- << getLegalCName(std::string(getName(VT))) << "_"
- << getLegalCName(std::string(getName(RetVT))) << "_";
+ << getLegalCName(std::string(getEnumName(VT))) << "_"
+ << getLegalCName(std::string(getEnumName(RetVT))) << "_";
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
OS << "(";
Operands.PrintArguments(OS);
@@ -753,7 +754,7 @@ void FastISelMap::printFunctionDefinitions(raw_ostream &OS) {
} else {
// Non-variadic return type.
OS << "unsigned fastEmit_" << getLegalCName(Opcode) << "_"
- << getLegalCName(std::string(getName(VT))) << "_";
+ << getLegalCName(std::string(getEnumName(VT))) << "_";
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
OS << "(MVT RetVT";
if (!Operands.empty())
@@ -761,7 +762,7 @@ void FastISelMap::printFunctionDefinitions(raw_ostream &OS) {
Operands.PrintParameters(OS);
OS << ") {\n";
- OS << " if (RetVT.SimpleTy != " << getName(RM.begin()->first)
+ OS << " if (RetVT.SimpleTy != " << getEnumName(RM.begin()->first)
<< ")\n return 0;\n";
const PredMap &PM = RM.begin()->second;
@@ -781,7 +782,7 @@ void FastISelMap::printFunctionDefinitions(raw_ostream &OS) {
OS << " switch (VT.SimpleTy) {\n";
for (const auto &TI : TM) {
MVT::SimpleValueType VT = TI.first;
- std::string TypeName = std::string(getName(VT));
+ std::string TypeName = std::string(getEnumName(VT));
OS << " case " << TypeName << ": return fastEmit_"
<< getLegalCName(Opcode) << "_" << getLegalCName(TypeName) << "_";
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
More information about the llvm-commits
mailing list