[Mlir-commits] [mlir] 6091873 - [mli][linalg] Reuse getValueOrCreateConstantIndexOp method (NFC).
Tobias Gysi
llvmlistbot at llvm.org
Tue Sep 14 08:33:29 PDT 2021
Author: Tobias Gysi
Date: 2021-09-14T15:32:29Z
New Revision: 609187365137be708509dd8d92acc5b9aef76695
URL: https://github.com/llvm/llvm-project/commit/609187365137be708509dd8d92acc5b9aef76695
DIFF: https://github.com/llvm/llvm-project/commit/609187365137be708509dd8d92acc5b9aef76695.diff
LOG: [mli][linalg] Reuse getValueOrCreateConstantIndexOp method (NFC).
Use getValueOrCreateConstantIndexOp introduced by https://reviews.llvm.org/D109601 in multiple places in LinalgOps.cpp.
Reviewed By: nicolasvasilache, springerm
Differential Revision: https://reviews.llvm.org/D109756
Added:
Modified:
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index 688f241c36f5a..a0e02400f7ce3 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -17,6 +17,7 @@
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/SCF.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
+#include "mlir/Dialect/StandardOps/Utils/Utils.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
@@ -98,10 +99,7 @@ static SmallVector<Value> getAsValues(OpBuilder &b, Location loc,
ArrayRef<OpFoldResult> valueOrAttrVec) {
return llvm::to_vector<4>(
llvm::map_range(valueOrAttrVec, [&](OpFoldResult value) -> Value {
- if (auto attr = value.dyn_cast<Attribute>())
- return b.create<ConstantIndexOp>(loc,
- attr.cast<IntegerAttr>().getInt());
- return value.get<Value>();
+ return getValueOrCreateConstantIndexOp(b, loc, value);
}));
}
@@ -1195,16 +1193,6 @@ LogicalResult PadTensorOp::reifyResultShapes(
// Methods related to PadTensor tiling.
//===----------------------------------------------------------------------===//
-/// Given an OpFoldResult, return a Value. If the OpFoldResult is an Attribute,
-/// it must be of type Integer.
-static Value getAsValue(OpBuilder &builder, Location loc, OpFoldResult ofr) {
- if (auto val = ofr.dyn_cast<Value>())
- return val;
- auto intVal = getConstantIntValue(ofr);
- assert(intVal && "expected Value or IntegerAttr");
- return builder.create<ConstantIndexOp>(loc, *intVal);
-}
-
SmallVector<Value> PadTensorOp::getDestinationOperands(OpBuilder &b) {
ReifiedRankedShapedTypeDims reifiedShapes;
(void)reifyResultShapes(b, reifiedShapes);
@@ -1292,12 +1280,12 @@ Operation *PadTensorOp::getTiledImplementation(OpBuilder &b, ValueRange dest,
int64_t rank = getSourceType().getRank();
for (unsigned dim = 0; dim < rank; ++dim) {
- auto low = getAsValue(b, loc, getMixedLowPad()[dim]);
+ auto low = getValueOrCreateConstantIndexOp(b, loc, getMixedLowPad()[dim]);
bool hasLowPad = getConstantIntValue(low) != static_cast<int64_t>(0);
- auto high = getAsValue(b, loc, getMixedHighPad()[dim]);
+ auto high = getValueOrCreateConstantIndexOp(b, loc, getMixedHighPad()[dim]);
bool hasHighPad = getConstantIntValue(high) != static_cast<int64_t>(0);
- auto offset = getAsValue(b, loc, offsets[dim]);
- auto length = getAsValue(b, loc, sizes[dim]);
+ auto offset = getValueOrCreateConstantIndexOp(b, loc, offsets[dim]);
+ auto length = getValueOrCreateConstantIndexOp(b, loc, sizes[dim]);
auto srcSize = b.createOrFold<tensor::DimOp>(loc, source(), dim);
// The new amount of low padding is `low - offset`. Except for the case
More information about the Mlir-commits
mailing list