[Mlir-commits] [mlir] [mlir][transform] Add transform.get_operand op (PR #78397)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Wed Jan 17 01:05:13 PST 2024
================
@@ -1464,6 +1464,35 @@ transform::GetProducerOfOperand::apply(transform::TransformRewriter &rewriter,
return DiagnosedSilenceableFailure::success();
}
+//===----------------------------------------------------------------------===//
+// GetOperandOp
+//===----------------------------------------------------------------------===//
+
+DiagnosedSilenceableFailure
+transform::GetOperandOp::apply(transform::TransformRewriter &rewriter,
+ transform::TransformResults &results,
+ transform::TransformState &state) {
+ std::optional<int64_t> maybeOperandNumber = getOperandNumber();
+ SmallVector<Value> operands;
+ for (Operation *target : state.getPayloadOps(getTarget())) {
+ if (!maybeOperandNumber) {
+ for (Value operand : target->getOperands())
+ operands.push_back(operand);
+ continue;
+ }
+ int64_t operandNumber = *maybeOperandNumber;
+ if (operandNumber >= target->getNumOperands()) {
+ DiagnosedSilenceableFailure diag =
+ emitSilenceableError() << "targeted op does not have enough operands";
----------------
ftynse wrote:
Nit: this can be more helpful if it tells how many operands were requested and how many operands does the op actually have.
https://github.com/llvm/llvm-project/pull/78397
More information about the Mlir-commits
mailing list