diff options
author | Craig Topper <craig.topper@sifive.com> | 2023-04-12 20:13:02 -0700 |
---|---|---|
committer | Craig Topper <craig.topper@sifive.com> | 2023-04-12 20:44:36 -0700 |
commit | 44d46c4b3c1401c708b557e4d88d92b9bbfceb19 (patch) | |
tree | 1dd84cf56daee28fe258a55a3326353020b1b142 | |
parent | 4bf9ca5eec24a4379fc7021c0aa1e810e32c50a6 (diff) | |
download | llvm-44d46c4b3c1401c708b557e4d88d92b9bbfceb19.zip llvm-44d46c4b3c1401c708b557e4d88d92b9bbfceb19.tar.gz llvm-44d46c4b3c1401c708b557e4d88d92b9bbfceb19.tar.bz2 |
[TableGen] Store CodeGenInstruction reference in EmitNodeMatcherCommon. NFC
Instead of storing a string containing the instruction name, store a
reference to the instruction. We can use that reference to print the
instruction name when we emit the table.
The only slightly annoying part is that we have to find the
CodeGenInstruction for IMPLICIT_DEF. GlobalISel is doing
a similar thing.
-rw-r--r-- | llvm/utils/TableGen/DAGISelMatcher.cpp | 10 | ||||
-rw-r--r-- | llvm/utils/TableGen/DAGISelMatcher.h | 53 | ||||
-rw-r--r-- | llvm/utils/TableGen/DAGISelMatcherEmitter.cpp | 5 | ||||
-rw-r--r-- | llvm/utils/TableGen/DAGISelMatcherGen.cpp | 13 | ||||
-rw-r--r-- | llvm/utils/TableGen/DAGISelMatcherOpt.cpp | 6 |
5 files changed, 43 insertions, 44 deletions
diff --git a/llvm/utils/TableGen/DAGISelMatcher.cpp b/llvm/utils/TableGen/DAGISelMatcher.cpp index c08c6a9..0609f00 100644 --- a/llvm/utils/TableGen/DAGISelMatcher.cpp +++ b/llvm/utils/TableGen/DAGISelMatcher.cpp @@ -8,6 +8,7 @@ #include "DAGISelMatcher.h" #include "CodeGenDAGPatterns.h" +#include "CodeGenInstruction.h" #include "CodeGenRegisters.h" #include "CodeGenTarget.h" #include "llvm/Support/raw_ostream.h" @@ -291,7 +292,7 @@ void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const { void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const { OS.indent(indent); OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ") - << OpcodeName << ": <todo flags> "; + << CGI.Namespace << "::" << CGI.TheDef->getName() << ": <todo flags> "; for (unsigned i = 0, e = VTs.size(); i != e; ++i) OS << ' ' << getEnumName(VTs[i]); @@ -316,10 +317,9 @@ bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const { bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const { const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m); - return M->OpcodeName == OpcodeName && M->VTs == VTs && - M->Operands == Operands && M->HasChain == HasChain && - M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue && - M->HasMemRefs == HasMemRefs && + return &M->CGI == &CGI && M->VTs == VTs && M->Operands == Operands && + M->HasChain == HasChain && M->HasInGlue == HasInGlue && + M->HasOutGlue == HasOutGlue && M->HasMemRefs == HasMemRefs && M->NumFixedArityOperands == NumFixedArityOperands; } diff --git a/llvm/utils/TableGen/DAGISelMatcher.h b/llvm/utils/TableGen/DAGISelMatcher.h index 716cff6..037e778 100644 --- a/llvm/utils/TableGen/DAGISelMatcher.h +++ b/llvm/utils/TableGen/DAGISelMatcher.h @@ -23,6 +23,7 @@ namespace llvm { struct CodeGenRegister; class CodeGenDAGPatterns; + class CodeGenInstruction; class Matcher; class PatternToMatch; class raw_ostream; @@ -997,7 +998,7 @@ private: /// EmitNodeMatcherCommon - Common class shared between EmitNode and /// MorphNodeTo. class EmitNodeMatcherCommon : public Matcher { - std::string OpcodeName; + const CodeGenInstruction &CGI; const SmallVector<MVT::SimpleValueType, 3> VTs; const SmallVector<unsigned, 6> Operands; bool HasChain, HasInGlue, HasOutGlue, HasMemRefs; @@ -1007,18 +1008,17 @@ class EmitNodeMatcherCommon : public Matcher { /// operands in the root of the pattern. The rest are appended to this node. int NumFixedArityOperands; public: - EmitNodeMatcherCommon(const std::string &opcodeName, + EmitNodeMatcherCommon(const CodeGenInstruction &cgi, ArrayRef<MVT::SimpleValueType> vts, - ArrayRef<unsigned> operands, - bool hasChain, bool hasInGlue, bool hasOutGlue, - bool hasmemrefs, + ArrayRef<unsigned> operands, bool hasChain, + bool hasInGlue, bool hasOutGlue, bool hasmemrefs, int numfixedarityoperands, bool isMorphNodeTo) - : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName), - VTs(vts.begin(), vts.end()), Operands(operands.begin(), operands.end()), - HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue), - HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {} + : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), CGI(cgi), + VTs(vts.begin(), vts.end()), Operands(operands.begin(), operands.end()), + HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue), + HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {} - const std::string &getOpcodeName() const { return OpcodeName; } + const CodeGenInstruction &getInstruction() const { return CGI; } unsigned getNumVTs() const { return VTs.size(); } MVT::SimpleValueType getVT(unsigned i) const { @@ -1056,16 +1056,15 @@ class EmitNodeMatcher : public EmitNodeMatcherCommon { void anchor() override; unsigned FirstResultSlot; public: - EmitNodeMatcher(const std::string &opcodeName, + EmitNodeMatcher(const CodeGenInstruction &cgi, ArrayRef<MVT::SimpleValueType> vts, - ArrayRef<unsigned> operands, - bool hasChain, bool hasInGlue, bool hasOutGlue, - bool hasmemrefs, - int numfixedarityoperands, unsigned firstresultslot) - : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain, - hasInGlue, hasOutGlue, hasmemrefs, - numfixedarityoperands, false), - FirstResultSlot(firstresultslot) {} + ArrayRef<unsigned> operands, bool hasChain, bool hasInGlue, + bool hasOutGlue, bool hasmemrefs, int numfixedarityoperands, + unsigned firstresultslot) + : EmitNodeMatcherCommon(cgi, vts, operands, hasChain, hasInGlue, + hasOutGlue, hasmemrefs, numfixedarityoperands, + false), + FirstResultSlot(firstresultslot) {} unsigned getFirstResultSlot() const { return FirstResultSlot; } @@ -1079,17 +1078,15 @@ class MorphNodeToMatcher : public EmitNodeMatcherCommon { void anchor() override; const PatternToMatch &Pattern; public: - MorphNodeToMatcher(const std::string &opcodeName, + MorphNodeToMatcher(const CodeGenInstruction &cgi, ArrayRef<MVT::SimpleValueType> vts, - ArrayRef<unsigned> operands, - bool hasChain, bool hasInGlue, bool hasOutGlue, - bool hasmemrefs, + ArrayRef<unsigned> operands, bool hasChain, bool hasInGlue, + bool hasOutGlue, bool hasmemrefs, int numfixedarityoperands, const PatternToMatch &pattern) - : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain, - hasInGlue, hasOutGlue, hasmemrefs, - numfixedarityoperands, true), - Pattern(pattern) { - } + : EmitNodeMatcherCommon(cgi, vts, operands, hasChain, hasInGlue, + hasOutGlue, hasmemrefs, numfixedarityoperands, + true), + Pattern(pattern) {} const PatternToMatch &getPattern() const { return Pattern; } diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp index c9e8f49..42bdca4 100644 --- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp +++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "CodeGenDAGPatterns.h" +#include "CodeGenInstruction.h" #include "CodeGenRegisters.h" #include "CodeGenTarget.h" #include "DAGISelMatcher.h" @@ -775,7 +776,9 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx, if (CompressVTs) OS << EN->getNumVTs(); - OS << ", TARGET_VAL(" << EN->getOpcodeName() << "), 0"; + const CodeGenInstruction &CGI = EN->getInstruction(); + OS << ", TARGET_VAL(" << CGI.Namespace << "::" << CGI.TheDef->getName() + << "), 0"; if (EN->hasChain()) OS << "|OPFL_Chain"; if (EN->hasInGlue()) OS << "|OPFL_GlueInput"; diff --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp index 59e2ecb..f5144aa 100644 --- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp +++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp @@ -698,8 +698,9 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N, if (Def->getName() == "undef_tied_input") { MVT::SimpleValueType ResultVT = N->getSimpleType(0); auto IDOperandNo = NextRecordedOperandNo++; - AddMatcher(new EmitNodeMatcher("TargetOpcode::IMPLICIT_DEF", - ResultVT, std::nullopt, false, false, + Record *ImpDef = Def->getRecords().getDef("IMPLICIT_DEF"); + CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(ImpDef); + AddMatcher(new EmitNodeMatcher(II, ResultVT, std::nullopt, false, false, false, false, -1, IDOperandNo)); ResultOps.push_back(IDOperandNo); return; @@ -981,11 +982,9 @@ EmitResultInstructionAsOperand(const TreePatternNode *N, assert((!ResultVTs.empty() || TreeHasOutGlue || NodeHasChain) && "Node has no result"); - AddMatcher(new EmitNodeMatcher(II.Namespace.str()+"::"+II.TheDef->getName().str(), - ResultVTs, InstOps, - NodeHasChain, TreeHasInGlue, TreeHasOutGlue, - NodeHasMemRefs, NumFixedArityOperands, - NextRecordedOperandNo)); + AddMatcher(new EmitNodeMatcher(II, ResultVTs, InstOps, NodeHasChain, + TreeHasInGlue, TreeHasOutGlue, NodeHasMemRefs, + NumFixedArityOperands, NextRecordedOperandNo)); // The non-chain and non-glue results of the newly emitted node get recorded. for (unsigned i = 0, e = ResultVTs.size(); i != e; ++i) { diff --git a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp index 3a78655..06bf7e2 100644 --- a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp +++ b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp @@ -125,9 +125,9 @@ static void ContractNodes(std::unique_ptr<Matcher> &MatcherPtr, const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList(); const SmallVectorImpl<unsigned> &Operands = EN->getOperandList(); MatcherPtr.reset(new MorphNodeToMatcher( - EN->getOpcodeName(), VTs, Operands, EN->hasChain(), EN->hasInGlue(), - EN->hasOutGlue(), EN->hasMemRefs(), EN->getNumFixedArityOperands(), - Pattern)); + EN->getInstruction(), VTs, Operands, EN->hasChain(), + EN->hasInGlue(), EN->hasOutGlue(), EN->hasMemRefs(), + EN->getNumFixedArityOperands(), Pattern)); return; } |