Skip to content

Commit

Permalink
[MLIR] Fix non-deterministic generation from buffer-deallocation pass
Browse files Browse the repository at this point in the history
The buffer-deallocation pass generates a different output on each run
due to an unstable iteration order.

Fixes: #59118

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D143622
  • Loading branch information
bondhugula committed Feb 9, 2023
1 parent 68c9068 commit e6edc1b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Expand Up @@ -55,7 +55,7 @@ class BufferViewFlowAnalysis {
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
Expand Down
Expand Up @@ -259,7 +259,7 @@ class BufferDeallocation : public BufferPlacementTransformationBase {
// 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;

Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e6edc1b

Please sign in to comment.