42 ReifyRankedShapedTypeOpInterface op) {
43 LLVM_DEBUG({
DBGS() <<
" reifying op: " << op <<
"\n"; });
47 reifiedResultShapes.empty()) {
48 return op->emitWarning() <<
"failed to get the reified shapes";
51 bool modified =
false;
54 for (
const auto &[oldTy, reifiedShape] :
55 llvm::zip(op->getResultTypes(), reifiedResultShapes)) {
57 if (!isa<RankedTensorType, MemRefType>(oldTy)) {
58 outTypes.push_back(oldTy);
62 ShapedType shapedTy = dyn_cast<ShapedType>(oldTy);
65 for (
auto &&[dim, ofr] : llvm::zip_equal(
shape, reifiedShape)) {
68 if (!maybeCst.has_value()) {
69 dim = ShapedType::kDynamic;
77 if (
shape == shapedTy.getShape()) {
78 outTypes.push_back(oldTy);
82 outTypes.push_back(shapedTy.cloneWith(
shape, shapedTy.getElementType()));
87 LLVM_DEBUG({
DBGS() <<
"- op doesn't require update\n"; });
92 DBGS() <<
"- oldTypes: " << llvm::interleaved_array(op->getResultTypes())
94 DBGS() <<
"- outTypes: " << llvm::interleaved_array(outTypes) <<
" \n";
103 assert((isa<tensor::PadOp, tensor::ConcatOp>(op.getOperation())) &&
106 for (
auto [reifiedTy, oldRes] : llvm::zip(outTypes, op->getResults())) {
108 Type oldTy = oldRes.getType();
110 if (oldTy == reifiedTy || !isa<MemRefType, RankedTensorType>(oldTy)) {
111 newResults.push_back(newRes);
117 if (isa<RankedTensorType>(reifiedTy)) {
118 newResults.push_back(
119 tensor::CastOp::create(rewriter, loc, oldTy, newRes));
121 assert(isa<MemRefType>(reifiedTy) &&
"expected a memref type");
122 newResults.push_back(
123 memref::CastOp::create(rewriter, loc, oldTy, newRes));
128 DBGS() <<
"- reified results " << llvm::interleaved_array(newResults)
static LogicalResult reifyOpResultShapes(RewriterBase &rewriter, ReifyRankedShapedTypeOpInterface op)
Reifies the results of op, potentially replacing op with a reified version.
Operation * clone(Operation &op, IRMapping &mapper)
Creates a deep copy of the specified operation, remapping any operands that use values outside of the...
LogicalResult reifyResultShapes(OpBuilder &b, Operation *op, ReifiedRankedShapedTypeDims &reifiedReturnShapes)
Reify the shape of the result of an operation (typically in terms of the shape of its operands).