[mlir-tblgen] Fix non-deterministic generating static verifier in DRR.
authorChia-hung Duan <chiahungduan@google.com>
Mon, 28 Feb 2022 18:21:28 +0000 (18:21 +0000)
committerChia-hung Duan <chiahungduan@google.com>
Mon, 28 Feb 2022 18:36:22 +0000 (18:36 +0000)
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

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

index db753f5..d4d3294 100644 (file)
@@ -114,7 +114,7 @@ public:
   ///
   /// 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 @@ private:
   /// 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;
index 973d50d..7fb6d95 100644 (file)
@@ -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(
index b8d875f..9310810 100644 (file)
@@ -322,7 +322,7 @@ private:
   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) {