diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -2798,7 +2798,8 @@ class NativeCodeCallVoid : NativeCodeCall; -def ConstantLikeMatcher : NativeCodeCall<"success(matchPattern($_self->getResult(0), m_Constant(&$0)))">; +def ConstantLikeMatcher : NativeCodeCall<"::mlir::success(" + "::mlir::matchPattern($_self->getResult(0), ::mlir::m_Constant(&$0)))">; //===----------------------------------------------------------------------===// // Rewrite directives diff --git a/mlir/test/mlir-tblgen/rewriter-static-matcher.td b/mlir/test/mlir-tblgen/rewriter-static-matcher.td --- a/mlir/test/mlir-tblgen/rewriter-static-matcher.td +++ b/mlir/test/mlir-tblgen/rewriter-static-matcher.td @@ -42,13 +42,13 @@ // CHECK: static ::mlir::LogicalResult [[$ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( // CHECK-NEXT: {{.*::mlir::Attribute attr}} // CHECK: static ::mlir::LogicalResult [[$DAG_MATCHER:static_dag_matcher.*]]( -// CHECK: if(failed([[$ATTR_CONSTRAINT]] -// CHECK: if(failed([[$TYPE_CONSTRAINT]] +// CHECK: if(::mlir::failed([[$ATTR_CONSTRAINT]] +// CHECK: if(::mlir::failed([[$TYPE_CONSTRAINT]] -// CHECK: if(failed([[$DAG_MATCHER]](rewriter, op1, tblgen_ops +// CHECK: if(::mlir::failed([[$DAG_MATCHER]](rewriter, op1, tblgen_ops def : Pat<(AOp (BOp I32Attr:$attr, I32:$int)), (AOp $int)>; -// CHECK: if(failed([[$DAG_MATCHER]](rewriter, op1, tblgen_ops +// CHECK: if(::mlir::failed([[$DAG_MATCHER]](rewriter, op1, tblgen_ops def : Pat<(COp $_, (BOp I32Attr:$attr, I32:$int)), (COp $attr, $int)>; diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -392,7 +392,8 @@ void PatternEmitter::emitStaticMatchCall(DagNode tree, StringRef opName) { std::string funcName = staticMatcherHelper.getMatcherName(tree); - os << formatv("if(failed({0}(rewriter, {1}, tblgen_ops", funcName, opName); + os << formatv("if(::mlir::failed({0}(rewriter, {1}, tblgen_ops", funcName, + opName); // TODO(chiahungduan): Add a lookupBoundSymbols() to do the subtree lookup in // one pass. @@ -423,8 +424,8 @@ void PatternEmitter::emitStaticVerifierCall(StringRef funcName, StringRef opName, StringRef arg, StringRef failureStr) { - os << formatv("if(failed({0}(rewriter, {1}, {2}, {3}))) {{\n", funcName, - opName, arg, failureStr); + os << formatv("if(::mlir::failed({0}(rewriter, {1}, {2}, {3}))) {{\n", + funcName, opName, arg, failureStr); os.scope().os << "return ::mlir::failure();\n"; os << "}\n"; } @@ -463,13 +464,13 @@ if (argTree.isEither()) PrintFatalError(loc, "NativeCodeCall cannot have `either` operands"); - os << "Value " << argName << ";\n"; + os << "::mlir::Value " << argName << ";\n"; } else { auto leaf = tree.getArgAsLeaf(i); if (leaf.isAttrMatcher() || leaf.isConstantAttr()) { - os << "Attribute " << argName << ";\n"; + os << "::mlir::Attribute " << argName << ";\n"; } else { - os << "Value " << argName << ";\n"; + os << "::mlir::Value " << argName << ";\n"; } } @@ -490,8 +491,8 @@ tgfmt(fmt, &fmtCtx.addSubst("_loc", locToUse).withSelf(opName.str()), static_cast>(capture))); - emitMatchCheck(opName, formatv("!failed({0})", nativeCodeCall), - formatv("\"{0} return failure\"", nativeCodeCall)); + emitMatchCheck(opName, formatv("!::mlir::failed({0})", nativeCodeCall), + formatv("\"{0} return ::mlir::failure\"", nativeCodeCall)); for (int i = 0, e = tree.getNumArgs() - tail.numDirectives; i != e; ++i) { auto name = tree.getArgName(i); @@ -699,8 +700,9 @@ llvm::raw_string_ostream tblgenOps(codeBuffer); std::string lambda = formatv("eitherLambda{0}", depth); - os << formatv("auto {0} = [&](OperandRange v0, OperandRange v1) {{\n", - lambda); + os << formatv( + "auto {0} = [&](::mlir::OperandRange v0, ::mlir::OperandRange v1) {{\n", + lambda); os.indent(); @@ -744,11 +746,11 @@ os << formatv("auto eitherOperand1 = {0}.getODSOperands({1});\n", opName, operandIndex - 1); - os << formatv("if(failed({0}(eitherOperand0, eitherOperand1)) && " - "failed({0}(eitherOperand1, " + os << formatv("if(::mlir::failed({0}(eitherOperand0, eitherOperand1)) && " + "::mlir::failed({0}(eitherOperand1, " "eitherOperand0)))\n", lambda); - os.indent() << "return failure();\n"; + os.indent() << "return ::mlir::failure();\n"; os.unindent().unindent() << "}\n"; } @@ -802,7 +804,7 @@ // through. if (!StringRef(matcher.getConditionTemplate()).contains("!$_self") && StringRef(matcher.getConditionTemplate()).contains("$_self")) { - os << "if (!tblgen_attr) return failure();\n"; + os << "if (!tblgen_attr) return ::mlir::failure();\n"; } } emitStaticVerifierCall(