[llvm] 44d46c4 - [TableGen] Store CodeGenInstruction reference in EmitNodeMatcherCommon. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 12 20:44:51 PDT 2023
Author: Craig Topper
Date: 2023-04-12T20:44:36-07:00
New Revision: 44d46c4b3c1401c708b557e4d88d92b9bbfceb19
URL: https://github.com/llvm/llvm-project/commit/44d46c4b3c1401c708b557e4d88d92b9bbfceb19
DIFF: https://github.com/llvm/llvm-project/commit/44d46c4b3c1401c708b557e4d88d92b9bbfceb19.diff
LOG: [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.
Added:
Modified:
llvm/utils/TableGen/DAGISelMatcher.cpp
llvm/utils/TableGen/DAGISelMatcher.h
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
llvm/utils/TableGen/DAGISelMatcherGen.cpp
llvm/utils/TableGen/DAGISelMatcherOpt.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/DAGISelMatcher.cpp b/llvm/utils/TableGen/DAGISelMatcher.cpp
index c08c6a9a30a29..0609f006763bc 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 716cff6e2bdcb..037e778140cfe 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 @@ class EmitNodeXFormMatcher : public Matcher {
/// 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 c9e8f496a24c1..42bdca47a3dee 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 59e2ecb20c889..f5144aa2bb871 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 3a786558996c3..06bf7e2f447b3 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;
}
More information about the llvm-commits
mailing list