[Mlir-commits] [mlir] d56ef5e - [mlir-tblgen] Fix non-deterministic generating static verifier in DRR.

Chia-hung Duan llvmlistbot at llvm.org
Mon Feb 28 10:41:30 PST 2022


Author: Chia-hung Duan
Date: 2022-02-28T18:36:22Z
New Revision: d56ef5ed20c5c1380c2d97e970c8fc4d4166bdb8

URL: https://github.com/llvm/llvm-project/commit/d56ef5ed20c5c1380c2d97e970c8fc4d4166bdb8
DIFF: https://github.com/llvm/llvm-project/commit/d56ef5ed20c5c1380c2d97e970c8fc4d4166bdb8.diff

LOG: [mlir-tblgen] Fix non-deterministic generating static verifier in DRR.

Use SetVector instead of DenseSet to ensure we always generate the same
name for the same function. This issue is found in
https://github.com/llvm/llvm-project/issues/53768.

Reviewed By: quinnp, rdzhabarov

Differential Revision: https://reviews.llvm.org/D120514

Added: 
    

Modified: 
    mlir/include/mlir/TableGen/CodeGenHelpers.h
    mlir/tools/mlir-tblgen/CodeGenHelpers.cpp
    mlir/tools/mlir-tblgen/RewriterGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/TableGen/CodeGenHelpers.h b/mlir/include/mlir/TableGen/CodeGenHelpers.h
index db753f55cdf0f..d4d3294ea2a6f 100644
--- a/mlir/include/mlir/TableGen/CodeGenHelpers.h
+++ b/mlir/include/mlir/TableGen/CodeGenHelpers.h
@@ -114,7 +114,7 @@ class StaticVerifierFunctionEmitter {
   ///
   /// Constraints that do not meet the restriction that they can only reference
   /// `$_self`, `$_op`, and `$_builder` are not uniqued.
-  void emitPatternConstraints(const DenseSet<DagLeaf> &constraints);
+  void emitPatternConstraints(const ArrayRef<DagLeaf> constraints);
 
   /// Get the name of the static function used for the given type constraint.
   /// These functions are used for operand and result constraints and have the
@@ -178,7 +178,7 @@ class StaticVerifierFunctionEmitter {
   /// Collect and unique all the constraints used by operations.
   void collectOpConstraints(ArrayRef<llvm::Record *> opDefs);
   /// Collect and unique all pattern constraints.
-  void collectPatternConstraints(const DenseSet<DagLeaf> &constraints);
+  void collectPatternConstraints(ArrayRef<DagLeaf> constraints);
 
   /// The output stream.
   raw_ostream &os;

diff  --git a/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp b/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp
index 973d50dab7ef3..7fb6d953b47f9 100644
--- a/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp
+++ b/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp
@@ -62,7 +62,7 @@ void StaticVerifierFunctionEmitter::emitOpConstraints(
 }
 
 void StaticVerifierFunctionEmitter::emitPatternConstraints(
-    const llvm::DenseSet<DagLeaf> &constraints) {
+    const llvm::ArrayRef<DagLeaf> constraints) {
   collectPatternConstraints(constraints);
   emitPatternConstraints();
 }
@@ -332,7 +332,7 @@ void StaticVerifierFunctionEmitter::collectOpConstraints(
 }
 
 void StaticVerifierFunctionEmitter::collectPatternConstraints(
-    const llvm::DenseSet<DagLeaf> &constraints) {
+    const llvm::ArrayRef<DagLeaf> constraints) {
   for (auto &leaf : constraints) {
     assert(leaf.isOperandMatcher() || leaf.isAttrMatcher());
     collectConstraint(

diff  --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp
index b8d875f2bfc48..9310810e86633 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -322,7 +322,7 @@ class StaticMatcherHelper {
   int staticMatcherCounter = 0;
 
   // The DagLeaf which contains type or attr constraint.
-  DenseSet<DagLeaf> constraints;
+  SetVector<DagLeaf> constraints;
 
   // Static type/attribute verification function emitter.
   StaticVerifierFunctionEmitter staticVerifierEmitter;
@@ -1713,7 +1713,7 @@ void StaticMatcherHelper::populateStaticMatchers(raw_ostream &os) {
 }
 
 void StaticMatcherHelper::populateStaticConstraintFunctions(raw_ostream &os) {
-  staticVerifierEmitter.emitPatternConstraints(constraints);
+  staticVerifierEmitter.emitPatternConstraints(constraints.getArrayRef());
 }
 
 void StaticMatcherHelper::addPattern(Record *record) {


        


More information about the Mlir-commits mailing list