[Mlir-commits] [mlir] 71b53ad - IntegerAttr accessor changed to returning APInt by reference. (#187351)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Mar 23 05:48:16 PDT 2026
Author: Jacques Pienaar
Date: 2026-03-23T14:48:11+02:00
New Revision: 71b53ad78cb7ca3f67c6e04cf2de62748d1bb03f
URL: https://github.com/llvm/llvm-project/commit/71b53ad78cb7ca3f67c6e04cf2de62748d1bb03f
DIFF: https://github.com/llvm/llvm-project/commit/71b53ad78cb7ca3f67c6e04cf2de62748d1bb03f.diff
LOG: IntegerAttr accessor changed to returning APInt by reference. (#187351)
IntegerAttr accessor getValue() returned an APInt by value. This works
well for the case where APInt is small, but leads to unnecessary copies
for larger bitwidths. This change switches this to returnsa const APInt&
instead.
Added:
Modified:
mlir/include/mlir/IR/AttrTypeBase.td
mlir/lib/Dialect/Arith/IR/ArithOps.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/AttrTypeBase.td b/mlir/include/mlir/IR/AttrTypeBase.td
index 16f7f8b532521..ac7ac8fdb3039 100644
--- a/mlir/include/mlir/IR/AttrTypeBase.td
+++ b/mlir/include/mlir/IR/AttrTypeBase.td
@@ -390,7 +390,7 @@ class StringRefParameter<string desc = "", string value = ""> :
// default APInt comparison operator asserts when the bitwidths
diff er, so
// a custom implementation is necessary.
class APIntParameter<string desc> :
- AttrOrTypeParameter<"::llvm::APInt", desc> {
+ AttrOrTypeParameter<"::llvm::APInt", desc, "const ::llvm::APInt &"> {
let comparator = "$_lhs.getBitWidth() == $_rhs.getBitWidth() && $_lhs == $_rhs";
}
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index f26aef625fd4a..155edc5070a9d 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -42,8 +42,8 @@ static IntegerAttr
applyToIntegerAttrs(PatternRewriter &builder, Value res, Attribute lhs,
Attribute rhs,
function_ref<APInt(const APInt &, const APInt &)> binFn) {
- APInt lhsVal = llvm::cast<IntegerAttr>(lhs).getValue();
- APInt rhsVal = llvm::cast<IntegerAttr>(rhs).getValue();
+ const APInt &lhsVal = llvm::cast<IntegerAttr>(lhs).getValue();
+ const APInt &rhsVal = llvm::cast<IntegerAttr>(rhs).getValue();
APInt value = binFn(lhsVal, rhsVal);
return IntegerAttr::get(res.getType(), value);
}
More information about the Mlir-commits
mailing list