[llvm] 1415e2b - [TableGen] Merge EmitIntegerMatcher and EmitStringIntegerMatcher. NFC (#173940)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 31 10:25:57 PST 2025
Author: Craig Topper
Date: 2025-12-31T10:25:53-08:00
New Revision: 1415e2bf70f5a9ee5868c777ed4d1bc42660c6fe
URL: https://github.com/llvm/llvm-project/commit/1415e2bf70f5a9ee5868c777ed4d1bc42660c6fe
DIFF: https://github.com/llvm/llvm-project/commit/1415e2bf70f5a9ee5868c777ed4d1bc42660c6fe.diff
LOG: [TableGen] Merge EmitIntegerMatcher and EmitStringIntegerMatcher. NFC (#173940)
Allow an EmitIntegerMatcher to have an optional string value to make
it equivalent to EmitStringIntegerMatcher.
Added:
Modified:
llvm/utils/TableGen/Common/DAGISelMatcher.cpp
llvm/utils/TableGen/Common/DAGISelMatcher.h
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
llvm/utils/TableGen/DAGISelMatcherGen.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
index 6f03989a805bf..768e80f39a028 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
@@ -248,11 +248,6 @@ void EmitIntegerMatcher::printImpl(raw_ostream &OS, indent Indent) const {
OS << Indent << "EmitInteger " << Val << " VT=" << getEnumName(VT) << '\n';
}
-void EmitStringIntegerMatcher::printImpl(raw_ostream &OS, indent Indent) const {
- OS << Indent << "EmitStringInteger " << Val << " VT=" << getEnumName(VT)
- << '\n';
-}
-
void EmitRegisterMatcher::printImpl(raw_ostream &OS, indent Indent) const {
OS << Indent << "EmitRegister ";
if (Reg)
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.h b/llvm/utils/TableGen/Common/DAGISelMatcher.h
index 093da829b8966..192d5c47d3489 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.h
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.h
@@ -86,7 +86,6 @@ class Matcher {
// Node creation/emisssion.
EmitInteger, // Create a TargetConstant
- EmitStringInteger, // Create a TargetConstant from a string.
EmitRegister, // Create a register.
EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
EmitMergeInputChains, // Merge together a chains for an input.
@@ -829,6 +828,8 @@ class CheckFoldableChainNodeMatcher : public Matcher {
/// EmitIntegerMatcher - This creates a new TargetConstant.
class EmitIntegerMatcher : public Matcher {
+ // Optional string to give the value a symbolic name for readability.
+ std::string Str;
int64_t Val;
MVT VT;
@@ -839,7 +840,11 @@ class EmitIntegerMatcher : public Matcher {
: Matcher(EmitInteger),
Val(SignExtend64(val, MVT(vt).getFixedSizeInBits())), VT(vt),
ResultNo(resultNo) {}
+ EmitIntegerMatcher(const std::string &str, int64_t val, MVT vt,
+ unsigned resultNo)
+ : Matcher(EmitInteger), Str(str), Val(val), VT(vt), ResultNo(resultNo) {}
+ const std::string &getString() const { return Str; }
int64_t getValue() const { return Val; }
MVT getVT() const { return VT; }
unsigned getResultNo() const { return ResultNo; }
@@ -850,39 +855,8 @@ class EmitIntegerMatcher : public Matcher {
void printImpl(raw_ostream &OS, indent Indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<EmitIntegerMatcher>(M)->Val == Val &&
- cast<EmitIntegerMatcher>(M)->VT == VT;
- }
-};
-
-/// EmitStringIntegerMatcher - A target constant whose value is represented
-/// by a string.
-class EmitStringIntegerMatcher : public Matcher {
- std::string Str;
- int64_t Val;
- MVT VT;
-
- unsigned ResultNo;
-
-public:
- EmitStringIntegerMatcher(const std::string &str, int64_t val, MVT vt,
- unsigned resultNo)
- : Matcher(EmitStringInteger), Str(str), Val(val), VT(vt),
- ResultNo(resultNo) {}
-
- const std::string &getString() const { return Str; }
- int64_t getValue() const { return Val; }
- MVT getVT() const { return VT; }
- unsigned getResultNo() const { return ResultNo; }
-
- static bool classof(const Matcher *N) {
- return N->getKind() == EmitStringInteger;
- }
-
-private:
- void printImpl(raw_ostream &OS, indent Indent) const override;
- bool isEqualImpl(const Matcher *M) const override {
- return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
- cast<EmitStringIntegerMatcher>(M)->VT == VT;
+ cast<EmitIntegerMatcher>(M)->VT == VT &&
+ cast<EmitIntegerMatcher>(M)->Str == Str;
}
};
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index a224dca5e5b91..76ea30f0986bb 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -793,56 +793,39 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
return 1;
case Matcher::EmitInteger: {
- int64_t Val = cast<EmitIntegerMatcher>(N)->getValue();
- MVT VT = cast<EmitIntegerMatcher>(N)->getVT();
- unsigned OpBytes;
+ const auto *IM = cast<EmitIntegerMatcher>(N);
+ int64_t Val = IM->getValue();
+ const std::string &Str = IM->getString();
+ MVT VT = IM->getVT();
+ unsigned TypeBytes = 0;
switch (VT.SimpleTy) {
case MVT::i8:
case MVT::i16:
case MVT::i32:
case MVT::i64:
- OpBytes = 1;
OS << "OPC_EmitIntegerI" << VT.getSizeInBits() << ", ";
break;
default:
OS << "OPC_EmitInteger, ";
if (!OmitComments)
OS << "/*" << getEnumName(VT) << "*/";
- OpBytes = EmitVBRValue(VT.SimpleTy, OS) + 1;
- break;
- }
- unsigned Bytes = OpBytes + EmitSignedVBRValue(Val, OS);
- if (!OmitComments)
- OS << " // " << Val << " #" << cast<EmitIntegerMatcher>(N)->getResultNo();
- OS << '\n';
- return Bytes;
- }
- case Matcher::EmitStringInteger: {
- const auto *SIM = cast<EmitStringIntegerMatcher>(N);
- int64_t Val = SIM->getValue();
- const std::string &Str = SIM->getString();
- MVT VT = SIM->getVT();
- unsigned TypeBytes = 0;
- switch (VT.SimpleTy) {
- case MVT::i32:
- OS << "OPC_EmitIntegerI" << VT.getSizeInBits() << ", ";
- break;
- default:
- OS << "OPC_EmitInteger, ";
- if (!OmitComments)
- OS << "/*" << getEnumName(VT) << "*/";
- TypeBytes = EmitVBRValue(VT.SimpleTy, OS) + 1;
+ TypeBytes = EmitVBRValue(VT.SimpleTy, OS);
break;
}
// If the value is 63 or smaller, use the string directly. Otherwise, use
// a VBR.
unsigned ValBytes = 1;
- if (Val <= 63)
+ if (!Str.empty() && Val <= 63)
OS << Str << ',';
else
ValBytes = EmitSignedVBRValue(Val, OS);
- if (!OmitComments)
- OS << " // #" << SIM->getResultNo() << " = " << Str;
+ if (!OmitComments) {
+ OS << " // #" << IM->getResultNo() << " = ";
+ if (!Str.empty())
+ OS << Str;
+ else
+ OS << Val;
+ }
OS << '\n';
return 1 + TypeBytes + ValBytes;
}
@@ -1343,8 +1326,6 @@ static StringRef getOpcodeString(Matcher::KindTy Kind) {
return "OPC_CheckImmAllZerosV";
case Matcher::EmitInteger:
return "OPC_EmitInteger";
- case Matcher::EmitStringInteger:
- return "OPC_EmitStringInteger";
case Matcher::EmitRegister:
return "OPC_EmitRegister";
case Matcher::EmitConvertToTarget:
diff --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
index 264fd063d2e29..dd4aefad02af7 100644
--- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -706,8 +706,8 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
const CodeGenRegisterClass &RC =
CGP.getTargetInfo().getRegisterClass(Def);
std::string Name = RC.getQualifiedIdName();
- AddMatcher(new EmitStringIntegerMatcher(Name, RC.EnumValue, MVT::i32,
- NextRecordedOperandNo));
+ AddMatcher(new EmitIntegerMatcher(Name, RC.EnumValue, MVT::i32,
+ NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
@@ -717,8 +717,8 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
const CodeGenRegBank &RB = CGP.getTargetInfo().getRegBank();
const CodeGenSubRegIndex *I = RB.findSubRegIdx(Def);
std::string Name = getQualifiedName(Def);
- AddMatcher(new EmitStringIntegerMatcher(Name, I->EnumValue, MVT::i32,
- NextRecordedOperandNo));
+ AddMatcher(new EmitIntegerMatcher(Name, I->EnumValue, MVT::i32,
+ NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
More information about the llvm-commits
mailing list