forked from OSchip/llvm-project
Match the op via isa instead of string compare.
* Match using isa - This limits the rewrite pattern to ops defined in op registry but that is probably better end state (esp. for additional verification). PiperOrigin-RevId: 227598946
This commit is contained in:
parent
5c869951ac
commit
c396c044e6
|
@ -49,6 +49,9 @@ public:
|
|||
// Returns the class name of the op.
|
||||
StringRef cppClassName();
|
||||
|
||||
// Returns the class name of the op with namespace added.
|
||||
std::string qualifiedCppClassName();
|
||||
|
||||
// Operations attribute accessors.
|
||||
struct Attribute {
|
||||
llvm::StringInit *name;
|
||||
|
|
|
@ -44,6 +44,9 @@ StringRef Operator::getOperationName() const {
|
|||
}
|
||||
|
||||
StringRef Operator::cppClassName() { return getSplitDefName().back(); }
|
||||
std::string Operator::qualifiedCppClassName() {
|
||||
return llvm::join(getSplitDefName(), "::");
|
||||
}
|
||||
|
||||
StringRef Operator::getArgName(int index) const {
|
||||
DagInit *argumentValues = def.getValueAsDag("arguments");
|
||||
|
|
|
@ -137,14 +137,9 @@ static void matchOp(DagInit *tree, int depth, raw_ostream &os) {
|
|||
if (depth != 0) {
|
||||
// Skip if there is no defining instruction (e.g., arguments to function).
|
||||
os.indent(indent) << formatv("if (!op{0}) return matchFailure();\n", depth);
|
||||
// TODO(jpienaar): This is bad, we should not be checking strings here, we
|
||||
// should be matching using mOp (and helpers). Currently doing this to allow
|
||||
// for TF ops that aren't registed. Fix it.
|
||||
os.indent(indent) << formatv(
|
||||
"if (op{0}->getName().getStringRef() != \"{1}\")",
|
||||
depth, op.getOperationName())
|
||||
<< "\n";
|
||||
os.indent(indent + 2) << "return matchFailure();\n";
|
||||
"if (!op{0}->isa<{1}>()) return matchFailure();\n", depth,
|
||||
op.qualifiedCppClassName());
|
||||
}
|
||||
for (int i = 0, e = tree->getNumArgs(); i != e; ++i) {
|
||||
auto arg = tree->getArg(i);
|
||||
|
|
Loading…
Reference in New Issue