[Mlir-commits] [mlir] [mlir][gpu] Add gpu.rotate operation (PR #142796)
Jakub Kuderski
llvmlistbot at llvm.org
Thu Jun 26 07:17:24 PDT 2025
================
@@ -1331,6 +1331,46 @@ void ShuffleOp::build(OpBuilder &builder, OperationState &result, Value value,
mode);
}
+//===----------------------------------------------------------------------===//
+// RotateOp
+//===----------------------------------------------------------------------===//
+
+void RotateOp::build(OpBuilder &builder, OperationState &result, Value value,
+ int32_t offset, int32_t width) {
+ build(builder, result, value,
+ builder.create<arith::ConstantOp>(result.location,
+ builder.getI32IntegerAttr(offset)),
+ builder.create<arith::ConstantOp>(result.location,
+ builder.getI32IntegerAttr(width)));
+}
+
+LogicalResult RotateOp::verify() {
+ auto offsetConstOp = getOffset().getDefiningOp<arith::ConstantOp>();
+ if (!offsetConstOp)
+ return emitOpError() << "offset is not a constant value";
+
+ auto offsetIntAttr =
+ llvm::dyn_cast<mlir::IntegerAttr>(offsetConstOp.getValue());
+
+ auto widthConstOp = getWidth().getDefiningOp<arith::ConstantOp>();
+ if (!widthConstOp)
+ return emitOpError() << "width is not a constant value";
+
+ auto widthIntAttr =
+ llvm::dyn_cast<mlir::IntegerAttr>(widthConstOp.getValue());
+
+ llvm::APInt offsetValue = offsetIntAttr.getValue();
+ llvm::APInt widthValue = widthIntAttr.getValue();
+
+ if (!widthValue.isPowerOf2())
+ return emitOpError() << "width must be a power of two";
+
+ if (offsetValue.sge(widthValue) || offsetValue.slt(0))
+ return emitOpError() << "offset must be in the range [0, width)";
----------------
kuhar wrote:
Would be nice to also print what `width` is
https://github.com/llvm/llvm-project/pull/142796
More information about the Mlir-commits
mailing list