[Mlir-commits] [mlir] [MLIR] Add a getStaticTripCount method to LoopLikeOpInterface (PR #158679)
Mehdi Amini
llvmlistbot at llvm.org
Tue Sep 16 05:10:21 PDT 2025
================
@@ -112,21 +113,30 @@ SmallVector<OpFoldResult> getAsIndexOpFoldResult(MLIRContext *ctx,
}
/// If ofr is a constant integer or an IntegerAttr, return the integer.
-std::optional<int64_t> getConstantIntValue(OpFoldResult ofr) {
+/// The boolean indicates whether the value is an index type.
+std::optional<std::pair<APInt, bool>> getConstantAPIntValue(OpFoldResult ofr) {
// Case 1: Check for Constant integer.
if (auto val = llvm::dyn_cast_if_present<Value>(ofr)) {
- APSInt intVal;
+ APInt intVal;
if (matchPattern(val, m_ConstantInt(&intVal)))
- return intVal.getSExtValue();
+ return std::make_pair(intVal, val.getType().isIndex());
return std::nullopt;
}
// Case 2: Check for IntegerAttr.
Attribute attr = llvm::dyn_cast_if_present<Attribute>(ofr);
if (auto intAttr = dyn_cast_or_null<IntegerAttr>(attr))
- return intAttr.getValue().getSExtValue();
+ return std::make_pair(intAttr.getValue(), intAttr.getType().isIndex());
return std::nullopt;
}
+/// If ofr is a constant integer or an IntegerAttr, return the integer.
+std::optional<int64_t> getConstantIntValue(OpFoldResult ofr) {
+ std::optional<std::pair<APInt, bool>> apsInt = getConstantAPIntValue(ofr);
----------------
joker-eph wrote:
I'll change it.
Initially I wanted `getConstantAPIntValue` to return a APSint, but the signed isn't carried by the value so it doesn't make sense!
https://github.com/llvm/llvm-project/pull/158679
More information about the Mlir-commits
mailing list