Skip to content

Commit 592233a

Browse files
authored
[TableGen][SelectionDAG] Make CheckValueTypeMatcher use MVT::SimpleValueType (#99537)
The original `CheckValueTypeMatcher` stores StringRef as the member variable type, however it's more efficient to use use MVT::SimpleValueType since it prevents string comparison in isEqualImpl, it also reduce the memory consumption in each object.
1 parent 88e9bd8 commit 592233a

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

llvm/utils/TableGen/Common/DAGISelMatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void CheckChild2CondCodeMatcher::printImpl(raw_ostream &OS,
218218
}
219219

220220
void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
221-
OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
221+
OS.indent(indent) << "CheckValueType " << getEnumName(VT) << '\n';
222222
}
223223

224224
void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
@@ -409,7 +409,7 @@ bool CheckChildIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
409409

410410
bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
411411
if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
412-
return CVT->getTypeName() != getTypeName();
412+
return CVT->getVT() != getVT();
413413
return false;
414414
}
415415

llvm/utils/TableGen/Common/DAGISelMatcher.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,13 @@ class CheckChild2CondCodeMatcher : public Matcher {
684684
/// CheckValueTypeMatcher - This checks to see if the current node is a
685685
/// VTSDNode with the specified type, if not it fails to match.
686686
class CheckValueTypeMatcher : public Matcher {
687-
StringRef TypeName;
687+
MVT::SimpleValueType VT;
688688

689689
public:
690-
CheckValueTypeMatcher(StringRef type_name)
691-
: Matcher(CheckValueType), TypeName(type_name) {}
690+
CheckValueTypeMatcher(MVT::SimpleValueType SimpleVT)
691+
: Matcher(CheckValueType), VT(SimpleVT) {}
692692

693-
StringRef getTypeName() const { return TypeName; }
693+
MVT::SimpleValueType getVT() const { return VT; }
694694

695695
static bool classof(const Matcher *N) {
696696
return N->getKind() == CheckValueType;
@@ -699,7 +699,7 @@ class CheckValueTypeMatcher : public Matcher {
699699
private:
700700
void printImpl(raw_ostream &OS, unsigned indent) const override;
701701
bool isEqualImpl(const Matcher *M) const override {
702-
return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
702+
return cast<CheckValueTypeMatcher>(M)->VT == VT;
703703
}
704704
bool isContradictoryImpl(const Matcher *M) const override;
705705
};

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
697697
return 2;
698698

699699
case Matcher::CheckValueType:
700-
OS << "OPC_CheckValueType, MVT::"
701-
<< cast<CheckValueTypeMatcher>(N)->getTypeName() << ",\n";
700+
OS << "OPC_CheckValueType, "
701+
<< getEnumName(cast<CheckValueTypeMatcher>(N)->getVT()) << ",\n";
702702
return 2;
703703

704704
case Matcher::CheckComplexPat: {

llvm/utils/TableGen/DAGISelMatcherGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode &N) {
235235
if (N.hasName())
236236
return;
237237
// An unnamed ValueType as in (sext_inreg GPR:$foo, i8).
238-
return AddMatcher(new CheckValueTypeMatcher(LeafRec->getName()));
238+
return AddMatcher(new CheckValueTypeMatcher(llvm::getValueType(LeafRec)));
239239
}
240240

241241
if ( // Handle register references. Nothing to do here, they always match.

0 commit comments

Comments
 (0)