/// 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);
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.