[llvm] [TableGen][SelectionDAG] Make CheckValueTypeMatcher use MVT::SimpleValueType (PR #99537)
Brandon Wu via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 11:00:55 PDT 2024
https://github.com/4vtomat created https://github.com/llvm/llvm-project/pull/99537
The original `CheckValueTypeMatcher` stores StringRef as the member variable type, however it's more efficient since it prevents string comparison in isEqualImpl, it also reduce the memory consumption in each object.
>From 33925ca9dfa8d13a7d0e37739cbc0b765cac3908 Mon Sep 17 00:00:00 2001
From: Brandon Wu <brandon.wu at sifive.com>
Date: Thu, 18 Jul 2024 09:52:51 -0700
Subject: [PATCH] [TableGen][SelectionDAG] Make CheckValueTypeMatcher use
MVT::SimpleValueType
The original `CheckValueTypeMatcher` stores StringRef as the member
variable type, however it's more efficient since it prevents string
comparison in isEqualImpl, it also reduce the memory consumption in
each object.
---
llvm/utils/TableGen/Common/DAGISelMatcher.cpp | 4 ++--
llvm/utils/TableGen/Common/DAGISelMatcher.h | 10 +++++-----
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp | 4 ++--
llvm/utils/TableGen/DAGISelMatcherGen.cpp | 3 ++-
4 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
index 3298965ab41d7..71bbeaaba9a91 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.cpp
@@ -218,7 +218,7 @@ void CheckChild2CondCodeMatcher::printImpl(raw_ostream &OS,
}
void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
- OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
+ OS.indent(indent) << "CheckValueType " << getEnumName(VT) << '\n';
}
void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
@@ -409,7 +409,7 @@ bool CheckChildIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
- return CVT->getTypeName() != getTypeName();
+ return CVT->getVT() != getVT();
return false;
}
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.h b/llvm/utils/TableGen/Common/DAGISelMatcher.h
index d4fe513e2e967..1d78b93310f1c 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.h
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.h
@@ -684,13 +684,13 @@ class CheckChild2CondCodeMatcher : public Matcher {
/// CheckValueTypeMatcher - This checks to see if the current node is a
/// VTSDNode with the specified type, if not it fails to match.
class CheckValueTypeMatcher : public Matcher {
- StringRef TypeName;
+ MVT::SimpleValueType VT;
public:
- CheckValueTypeMatcher(StringRef type_name)
- : Matcher(CheckValueType), TypeName(type_name) {}
+ CheckValueTypeMatcher(MVT::SimpleValueType SimpleVT)
+ : Matcher(CheckValueType), VT(SimpleVT) {}
- StringRef getTypeName() const { return TypeName; }
+ MVT::SimpleValueType getVT() const { return VT; }
static bool classof(const Matcher *N) {
return N->getKind() == CheckValueType;
@@ -699,7 +699,7 @@ class CheckValueTypeMatcher : public Matcher {
private:
void printImpl(raw_ostream &OS, unsigned indent) const override;
bool isEqualImpl(const Matcher *M) const override {
- return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
+ return cast<CheckValueTypeMatcher>(M)->VT == VT;
}
bool isContradictoryImpl(const Matcher *M) const override;
};
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index ff508d6487333..229245ff40504 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -697,8 +697,8 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
return 2;
case Matcher::CheckValueType:
- OS << "OPC_CheckValueType, MVT::"
- << cast<CheckValueTypeMatcher>(N)->getTypeName() << ",\n";
+ OS << "OPC_CheckValueType, "
+ << getEnumName(cast<CheckValueTypeMatcher>(N)->getVT()) << ",\n";
return 2;
case Matcher::CheckComplexPat: {
diff --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
index 99babdf07316f..6c0b788ead907 100644
--- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -235,7 +235,8 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode &N) {
if (N.hasName())
return;
// An unnamed ValueType as in (sext_inreg GPR:$foo, i8).
- return AddMatcher(new CheckValueTypeMatcher(LeafRec->getName()));
+ return AddMatcher(new CheckValueTypeMatcher(
+ static_cast<MVT::SimpleValueType>(LeafRec->getValueAsInt("Value"))));
}
if ( // Handle register references. Nothing to do here, they always match.
More information about the llvm-commits
mailing list