[Mlir-commits] [mlir] 8afe6f7 - [mlir] NFC - Add some more static value utils

Nicolas Vasilache llvmlistbot at llvm.org
Sun Mar 12 08:25:58 PDT 2023


Author: Nicolas Vasilache
Date: 2023-03-12T08:25:52-07:00
New Revision: 8afe6f7bd548188ee534def57cf9895ccfb71c08

URL: https://github.com/llvm/llvm-project/commit/8afe6f7bd548188ee534def57cf9895ccfb71c08
DIFF: https://github.com/llvm/llvm-project/commit/8afe6f7bd548188ee534def57cf9895ccfb71c08.diff

LOG: [mlir] NFC - Add some more static value utils

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Utils/StaticValueUtils.h
    mlir/lib/Dialect/Utils/StaticValueUtils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h b/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h
index c97c0834f588d..2be3e74c62dd2 100644
--- a/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h
+++ b/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h
@@ -63,14 +63,18 @@ SmallVector<int64_t, 4> extractFromI64ArrayAttr(Attribute attr);
 /// Given a value, try to extract a constant Attribute. If this fails, return
 /// the original value.
 OpFoldResult getAsOpFoldResult(Value val);
-
 /// Given an array of values, try to extract a constant Attribute from each
 /// value. If this fails, return the original value.
 SmallVector<OpFoldResult> getAsOpFoldResult(ValueRange values);
-
 /// Convert `arrayAttr` to a vector of OpFoldResult.
 SmallVector<OpFoldResult> getAsOpFoldResult(ArrayAttr arrayAttr);
 
+/// Convert int64_t to integer attributes of index type and return them as
+/// OpFoldResult.
+OpFoldResult getAsIndexOpFoldResult(MLIRContext *ctx, int64_t val);
+SmallVector<OpFoldResult> getAsIndexOpFoldResult(MLIRContext *ctx,
+                                                 ArrayRef<int64_t> values);
+
 /// If ofr is a constant integer or an IntegerAttr, return the integer.
 std::optional<int64_t> getConstantIntValue(OpFoldResult ofr);
 

diff  --git a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp
index 5a4b7ea4f9881..bf80acb754dd7 100644
--- a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp
+++ b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp
@@ -102,6 +102,16 @@ SmallVector<OpFoldResult> getAsOpFoldResult(ArrayAttr arrayAttr) {
   return res;
 }
 
+OpFoldResult getAsIndexOpFoldResult(MLIRContext *ctx, int64_t val) {
+  return IntegerAttr::get(IndexType::get(ctx), val);
+}
+
+SmallVector<OpFoldResult> getAsIndexOpFoldResult(MLIRContext *ctx,
+                                                 ArrayRef<int64_t> values) {
+  return llvm::to_vector<4>(llvm::map_range(
+      values, [ctx](int64_t v) { return getAsIndexOpFoldResult(ctx, v); }));
+}
+
 /// If ofr is a constant integer or an IntegerAttr, return the integer.
 std::optional<int64_t> getConstantIntValue(OpFoldResult ofr) {
   // Case 1: Check for Constant integer.


        


More information about the Mlir-commits mailing list