Author: Chia-hung Duan Date: 2022-02-28T15:19:46-08:00 New Revision: 779871c3515add46508aa2901c838650eb01f2d3
URL: https://github.com/llvm/llvm-project/commit/779871c3515add46508aa2901c838650eb01f2d3 DIFF: https://github.com/llvm/llvm-project/commit/779871c3515add46508aa2901c838650eb01f2d3.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 (cherry picked from commit d56ef5ed20c5c1380c2d97e970c8fc4d4166bdb8) 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 4fcc880464c98..d37856112b196 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; @@ -1708,7 +1708,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) { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
