let builders = [
// Build a PadOp with mixed static and dynamic entries.
- OpBuilder<(ins "Value":$source, "ArrayRef<int64_t>":$staticLow,
- "ArrayRef<int64_t>":$staticHigh, "ValueRange":$low, "ValueRange":$high,
- CArg<"bool", "false">:$nofold,
+ OpBuilder<(ins "Type":$resultType, "Value":$source,
+ "ArrayRef<int64_t>":$staticLow, "ArrayRef<int64_t>":$staticHigh,
+ "ValueRange":$low, "ValueRange":$high, CArg<"bool", "false">:$nofold,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>,
// Build a PadOp with all dynamic entries.
- OpBuilder<(ins "Value":$source, "ValueRange":$low, "ValueRange":$high,
- CArg<"bool", "false">:$nofold,
+ OpBuilder<(ins "Type":$resultType, "Value":$source, "ValueRange":$low,
+ "ValueRange":$high, CArg<"bool", "false">:$nofold,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>,
// Build a PadOp with mixed static and dynamic entries and custom
// result type. If the type passed is nullptr, it is inferred.
return RankedTensorType::get(inferredShape, sourceType.getElementType());
}
-void PadOp::build(OpBuilder &b, OperationState &result, Value source,
- ArrayRef<int64_t> staticLow, ArrayRef<int64_t> staticHigh,
- ValueRange low, ValueRange high, bool nofold,
- ArrayRef<NamedAttribute> attrs) {
+void PadOp::build(OpBuilder &b, OperationState &result, Type resultType,
+ Value source, ArrayRef<int64_t> staticLow,
+ ArrayRef<int64_t> staticHigh, ValueRange low, ValueRange high,
+ bool nofold, ArrayRef<NamedAttribute> attrs) {
auto sourceType = source.getType().cast<RankedTensorType>();
- auto resultType = inferResultType(sourceType, staticLow, staticHigh);
+ if (!resultType)
+ resultType = inferResultType(sourceType, staticLow, staticHigh);
build(b, result, resultType, source, low, high,
b.getDenseI64ArrayAttr(staticLow), b.getDenseI64ArrayAttr(staticHigh),
nofold ? b.getUnitAttr() : UnitAttr());
result.addAttributes(attrs);
}
-void PadOp::build(OpBuilder &b, OperationState &result, Value source,
- ValueRange low, ValueRange high, bool nofold,
+void PadOp::build(OpBuilder &b, OperationState &result, Type resultType,
+ Value source, ValueRange low, ValueRange high, bool nofold,
ArrayRef<NamedAttribute> attrs) {
auto sourceType = source.getType().cast<RankedTensorType>();
unsigned rank = sourceType.getRank();
SmallVector<int64_t, 4> staticVector(rank, ShapedType::kDynamic);
- build(b, result, source, staticVector, staticVector, low, high, nofold,
- attrs);
+ build(b, result, resultType, source, staticVector, staticVector, low, high,
+ nofold, attrs);
}
void PadOp::build(OpBuilder &b, OperationState &result, Type resultType,
} else {
auto newOp = rewriter.create<PadOp>(
padTensorOp->getLoc(), newResultType, padTensorOp.getSource(),
- padTensorOp.getLow(), padTensorOp.getHigh(),
padTensorOp.getStaticLow(), padTensorOp.getStaticHigh(),
- padTensorOp.getNofold());
+ padTensorOp.getLow(), padTensorOp.getHigh(), padTensorOp.getNofold(),
+ getPrunedAttributeList(padTensorOp, PadOp::getAttributeNames()));
IRMapping mapper;
padTensorOp.getRegion().cloneInto(&newOp.getRegion(), mapper);
auto replacementOp = rewriter.create<PadOp>(
padTensorOp.getLoc(), tensorCastOp.getDest().getType(),
- padTensorOp.getSource(), padTensorOp.getLow(), padTensorOp.getHigh(),
- padTensorOp.getStaticLow(), padTensorOp.getStaticHigh(),
- padTensorOp.getNofold());
+ padTensorOp.getSource(), padTensorOp.getStaticLow(),
+ padTensorOp.getStaticHigh(), padTensorOp.getLow(),
+ padTensorOp.getHigh(), padTensorOp.getNofold(),
+ getPrunedAttributeList(padTensorOp, PadOp::getAttributeNames()));
replacementOp.getRegion().takeBody(padTensorOp.getRegion());
rewriter.replaceOp(padTensorOp, replacementOp.getResult());
innerSliceOp.getMixedStrides());
auto newPadOp = rewriter.create<PadOp>(
padOp.getLoc(), padOp.getResultType(), newSliceOp.getResult(),
- padOp.getMixedLowPad(), newHighPad, padOp.getNofold());
+ padOp.getMixedLowPad(), newHighPad, padOp.getNofold(),
+ getPrunedAttributeList(padOp, PadOp::getAttributeNames()));
rewriter.inlineRegionBefore(padOp.getRegion(), newPadOp.getRegion(),
newPadOp.getRegion().begin());
rewriter.replaceOp(padOp, newPadOp.getResult());
auto newResultType = RankedTensorType::get(
newOutDims, padTensorOp.getType().getElementType());
auto newOp = rewriter.create<PadOp>(
- padTensorOp->getLoc(), newResultType, input, padTensorOp.getLow(),
- padTensorOp.getHigh(), staticLow, staticHigh, padTensorOp.getNofold());
+ padTensorOp->getLoc(), newResultType, input, staticLow, staticHigh,
+ padTensorOp.getLow(), padTensorOp.getHigh(), padTensorOp.getNofold(),
+ getPrunedAttributeList(padTensorOp, PadOp::getAttributeNames()));
IRMapping mapper;
padTensorOp.getRegion().cloneInto(&newOp.getRegion(), mapper);