[MLIR] Fix non-deterministic generation from buffer-deallocation pass
authorUday Bondhugula <uday@polymagelabs.com>
Thu, 9 Feb 2023 22:38:39 +0000 (04:08 +0530)
committerUday Bondhugula <uday@polymagelabs.com>
Thu, 9 Feb 2023 23:21:59 +0000 (04:51 +0530)
The buffer-deallocation pass generates a different output on each run
due to an unstable iteration order.

Fixes: https://github.com/llvm/llvm-project/issues/59118

Reviewed By: mehdi_amini

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

mlir/include/mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
mlir/lib/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.cpp

index c03d780..5905204 100644 (file)
@@ -55,7 +55,7 @@ public:
   ValueSetT resolve(Value value) const;
 
   /// Removes the given values from all alias sets.
-  void remove(const SmallPtrSetImpl<Value> &aliasValues);
+  void remove(const SetVector<Value> &aliasValues);
 
 private:
   /// This function constructs a mapping from values to its immediate
index 27a31c9..cf51aa5 100644 (file)
@@ -259,7 +259,7 @@ private:
     // Initialize the set of values that require a dedicated memory free
     // operation since their operands cannot be safely deallocated in a post
     // dominator.
-    SmallPtrSet<Value, 8> valuesToFree;
+    SetVector<Value> valuesToFree;
     llvm::SmallDenseSet<std::tuple<Value, Block *>> visitedValues;
     SmallVector<std::tuple<Value, Block *>, 8> toProcess;
 
index 1d61a8b..b4cfe89 100644 (file)
@@ -12,6 +12,7 @@
 #include "mlir/Interfaces/ControlFlowInterfaces.h"
 #include "mlir/Interfaces/ViewLikeInterface.h"
 #include "llvm/ADT/SetOperations.h"
+#include "llvm/ADT/SetVector.h"
 
 using namespace mlir;
 
@@ -40,7 +41,7 @@ BufferViewFlowAnalysis::resolve(Value rootValue) const {
 }
 
 /// Removes the given values from all alias sets.
-void BufferViewFlowAnalysis::remove(const SmallPtrSetImpl<Value> &aliasValues) {
+void BufferViewFlowAnalysis::remove(const SetVector<Value> &aliasValues) {
   for (auto &entry : dependencies)
     llvm::set_subtract(entry.second, aliasValues);
 }