diff options
author | Lorenzo Chelini <l.chelini@icloud.com> | 2022-09-27 18:16:43 +0300 |
---|---|---|
committer | Emilio Cota <ecg@google.com> | 2022-09-27 18:18:25 +0300 |
commit | 4db3a649ea79966ed7ab297a381d27fbbb6b6f7a (patch) | |
tree | 34bcfa144518c7fab8366e42ead67248c7538baa | |
parent | 17f2ee804a3c50f0b50d57a0100ce9f4102bfa3f (diff) |
[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC) [reland]
The utility function should live in `StaticValueUtils.h` as it provides
a convenient way to convert a vector of OpFoldResults into a vector of
Values.
Reviewed By: nicolasvasilache, cota
Differential Revision: https://reviews.llvm.org/D134451
-rw-r--r-- | mlir/include/mlir/Dialect/Utils/StaticValueUtils.h | 7 | ||||
-rw-r--r-- | mlir/lib/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.cpp | 12 | ||||
-rw-r--r-- | mlir/lib/Dialect/Utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | mlir/lib/Dialect/Utils/StaticValueUtils.cpp | 13 | ||||
-rw-r--r-- | utils/bazel/llvm-project-overlay/mlir/BUILD.bazel | 4 |
5 files changed, 24 insertions, 13 deletions
diff --git a/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h b/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h index f290b1e8e8b3..f09cf88afaab 100644 --- a/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h +++ b/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h @@ -80,6 +80,13 @@ bool isConstantIntValue(OpFoldResult ofr, int64_t value); /// no IndexAttr and that IndexType have no bitwidth. bool isEqualConstantIntOrValue(OpFoldResult ofr1, OpFoldResult ofr2); +/// Helper function to convert a vector of `OpFoldResult`s into a vector of +/// `Value`s. For each `OpFoldResult` in `valueOrAttrVec` return the fold result +/// if it casts to a `Value` or create an index-type constant if it casts to +/// `IntegerAttr`. No other attribute types are supported. +SmallVector<Value> getAsValues(OpBuilder &b, Location loc, + ArrayRef<OpFoldResult> valueOrAttrVec); + } // namespace mlir #endif // MLIR_DIALECT_UTILS_STATICVALUEUTILS_H diff --git a/mlir/lib/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.cpp b/mlir/lib/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.cpp index 3a6be9f74164..df65eee6782c 100644 --- a/mlir/lib/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.cpp @@ -8,8 +8,8 @@ #include "mlir/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" -#include "mlir/Dialect/Arithmetic/Utils/Utils.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" +#include "mlir/Dialect/Utils/StaticValueUtils.h" #include "mlir/Interfaces/InferTypeOpInterface.h" using namespace mlir; @@ -134,16 +134,6 @@ getReshapeOutputShapeFromInputShape(OpBuilder &builder, Location loc, Value src, builder, loc, src, dstStaticShape, reassocation); } -/// Helper function to convert a vector of `OpFoldResult`s into a vector of -/// `Value`s. -static SmallVector<Value> getAsValues(OpBuilder &b, Location loc, - ArrayRef<OpFoldResult> valueOrAttrVec) { - return llvm::to_vector<4>( - llvm::map_range(valueOrAttrVec, [&](OpFoldResult value) -> Value { - return getValueOrCreateConstantIndexOp(b, loc, value); - })); -} - template <typename OpTy> struct ReifyExpandOrCollapseShapeOp : public ReifyRankedShapedTypeOpInterface::ExternalModel< diff --git a/mlir/lib/Dialect/Utils/CMakeLists.txt b/mlir/lib/Dialect/Utils/CMakeLists.txt index f329afa8fa75..b93a30da1dc3 100644 --- a/mlir/lib/Dialect/Utils/CMakeLists.txt +++ b/mlir/lib/Dialect/Utils/CMakeLists.txt @@ -5,5 +5,6 @@ add_mlir_library(MLIRDialectUtils StaticValueUtils.cpp LINK_LIBS PUBLIC + MLIRArithmeticUtils MLIRIR ) diff --git a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp index 6212df931144..2392b1d123f1 100644 --- a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp +++ b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Dialect/Utils/StaticValueUtils.h" +#include "mlir/Dialect/Arithmetic/Utils/Utils.h" #include "mlir/IR/Matchers.h" #include "mlir/Support/LLVM.h" #include "llvm/ADT/APSInt.h" @@ -124,4 +125,16 @@ bool isEqualConstantIntOrValue(OpFoldResult ofr1, OpFoldResult ofr2) { auto v1 = ofr1.dyn_cast<Value>(), v2 = ofr2.dyn_cast<Value>(); return v1 && v1 == v2; } + +/// Helper function to convert a vector of `OpFoldResult`s into a vector of +/// `Value`s. For each `OpFoldResult` in `valueOrAttrVec` return the fold result +/// if it casts to a `Value` or create an index-type constant if it casts to +/// `IntegerAttr`. No other attribute types are supported. +SmallVector<Value> getAsValues(OpBuilder &b, Location loc, + ArrayRef<OpFoldResult> valueOrAttrVec) { + return llvm::to_vector<4>( + llvm::map_range(valueOrAttrVec, [&](OpFoldResult value) -> Value { + return getValueOrCreateConstantIndexOp(b, loc, value); + })); +} } // namespace mlir diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index 8fade09a5448..135e54ce2973 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -2344,6 +2344,7 @@ cc_library( ]), includes = ["include"], deps = [ + ":ArithmeticUtils", ":DialectUtilsIncGen", ":IR", ":Support", @@ -5033,7 +5034,7 @@ cc_library( includes = ["include"], deps = [ ":AffineDialect", - ":ArithmeticUtils", + ":DialectUtils", ":IR", ":InferTypeOpInterface", ":TensorDialect", @@ -8597,7 +8598,6 @@ cc_library( ":ArithmeticCanonicalizationIncGen", ":ArithmeticOpsIncGen", ":CommonFolders", - ":DialectUtils", ":IR", ":InferIntRangeInterface", ":InferTypeOpInterface", |