summaryrefslogtreecommitdiff
path: root/mlir/include
diff options
context:
space:
mode:
authorDavid Stone <davidfromonline@gmail.com>2025-11-20 11:23:12 -0700
committerGitHub <noreply@github.com>2025-11-20 11:23:12 -0700
commitbfbd191f35352df2decde46d117bb940864889bf (patch)
tree6faf86d4a09c78d2f4ddcd3b39035a3afd5fe44f /mlir/include
parent01e5e4fd001c960e197ac377cd06ea177b320964 (diff)
[mlir] Replace `llvm::OwningArrayRef` with `std::vector` (#168803)
There are several places where we use `llvm::OwningArrayRef`. The interface to this requires us to first construct temporary storage, then allocate space and set the allocated memory to 0, then copy the values we actually want into that memory, then move the array into place. Instead we can just do it all inline in a single pass by using `std::vector`. In one case we actually allocate a completely separate container and then allocate + copy the data over because `llvm::OwningArrayRef` does not (and can't) support `push_back`. Note that `llvm::SmallVector` is not a suitable replacement here because we rely on reference stability on move construction: when the outer container reallocates, we need the the contents of the inner containers to be fixed in memory, and `llvm::SmallVector` does not give us that guarantee.
Diffstat (limited to 'mlir/include')
-rw-r--r--mlir/include/mlir/IR/PDLPatternMatch.h.inc12
1 files changed, 4 insertions, 8 deletions
diff --git a/mlir/include/mlir/IR/PDLPatternMatch.h.inc b/mlir/include/mlir/IR/PDLPatternMatch.h.inc
index d5fb57d7c360..4afbcf292496 100644
--- a/mlir/include/mlir/IR/PDLPatternMatch.h.inc
+++ b/mlir/include/mlir/IR/PDLPatternMatch.h.inc
@@ -152,9 +152,7 @@ public:
void push_back(TypeRange value) {
// The lifetime of a TypeRange can't be guaranteed, so we'll need to
// allocate a storage for it.
- llvm::OwningArrayRef<Type> storage(value.size());
- llvm::copy(value, storage.begin());
- allocatedTypeRanges.emplace_back(std::move(storage));
+ allocatedTypeRanges.emplace_back(value.begin(), value.end());
typeRanges.push_back(allocatedTypeRanges.back());
results.push_back(&typeRanges.back());
}
@@ -174,9 +172,7 @@ public:
void push_back(ValueRange value) {
// The lifetime of a ValueRange can't be guaranteed, so we'll need to
// allocate a storage for it.
- llvm::OwningArrayRef<Value> storage(value.size());
- llvm::copy(value, storage.begin());
- allocatedValueRanges.emplace_back(std::move(storage));
+ allocatedValueRanges.emplace_back(value.begin(), value.end());
valueRanges.push_back(allocatedValueRanges.back());
results.push_back(&valueRanges.back());
}
@@ -206,8 +202,8 @@ protected:
SmallVector<ValueRange> valueRanges;
/// Memory allocated to store ranges in the result list whose lifetime was
/// generated in the native function.
- SmallVector<llvm::OwningArrayRef<Type>> allocatedTypeRanges;
- SmallVector<llvm::OwningArrayRef<Value>> allocatedValueRanges;
+ SmallVector<std::vector<Type>> allocatedTypeRanges;
+ SmallVector<std::vector<Value>> allocatedValueRanges;
};
//===----------------------------------------------------------------------===//