diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationBase.td b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationBase.td --- a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationBase.td +++ b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationBase.td @@ -41,6 +41,7 @@ kBufferLayoutAttrName = "bufferization.buffer_layout"; }]; let hasOperationAttrVerify = 1; + let emitAccessorPrefix = kEmitAccessorPrefix_Prefixed; } #endif // BUFFERIZATION_BASE diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td --- a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td +++ b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td @@ -64,7 +64,7 @@ ``` }]; - let arguments = (ins Variadic:$dynamicSizes, + let arguments = (ins Variadic:$dynamic_sizes, Optional:$copy, OptionalAttr:$escape); @@ -98,7 +98,7 @@ // the tensor at dimension `idx`. Asserts that the shape is // dynamic at that `idx`. unsigned getIndexOfDynamicSize(unsigned idx) { - assert(!copy() && "no dim sizes specified when copying a tensor"); + assert(!getCopy() && "no dim sizes specified when copying a tensor"); assert(isDynamicDim(idx) && "expected dynamic size"); ArrayRef shape = getType().getShape(); return std::count_if( @@ -169,8 +169,8 @@ let results = (outs Arg:$output); let extraClassDeclaration = [{ - Value getSource() { return input(); } - Value getTarget() { return output(); } + Value getSource() { return getInput(); } + Value getTarget() { return getOutput(); } }]; let assemblyFormat = "$input attr-dict `:` type($input) `to` type($output)"; diff --git a/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp b/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp --- a/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp +++ b/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp @@ -57,7 +57,8 @@ if (!memrefType.isDynamicDim(i)) continue; Value size = rewriter.createOrFold(loc, i); - Value dim = rewriter.createOrFold(loc, op.input(), size); + Value dim = + rewriter.createOrFold(loc, op.getInput(), size); dynamicOperands.push_back(dim); } @@ -68,7 +69,7 @@ if (memrefType != allocType) alloc = rewriter.create(op->getLoc(), memrefType, alloc); rewriter.replaceOp(op, alloc); - rewriter.create(loc, op.input(), alloc); + rewriter.create(loc, op.getInput(), alloc); return success(); } }; diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp --- a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp @@ -484,7 +484,7 @@ // Replace "%t = to_tensor %m" with %m. if (auto toTensorOp = value.getDefiningOp()) - return toTensorOp.memref(); + return toTensorOp.getMemref(); // Insert to_memref op. OpBuilder::InsertionGuard g(rewriter); @@ -502,7 +502,7 @@ assert(tensorType && "unexpected non-tensor type"); if (auto toTensorOp = value.getDefiningOp()) - return toTensorOp.memref().getType().cast(); + return toTensorOp.getMemref().getType().cast(); return getMemRefType(tensorType, options); } diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp @@ -84,11 +84,11 @@ /// to_memref op are different, a memref.cast is needed. LogicalResult mlir::bufferization::foldToMemrefToTensorPair( RewriterBase &rewriter, ToMemrefOp toMemref, bool allowSameType) { - auto memrefToTensor = toMemref.tensor().getDefiningOp(); + auto memrefToTensor = toMemref.getTensor().getDefiningOp(); if (!memrefToTensor) return failure(); - Type srcType = memrefToTensor.memref().getType(); + Type srcType = memrefToTensor.getMemref().getType(); Type destType = toMemref.getType(); // Directly rewrite if the type did not change. @@ -96,7 +96,7 @@ // Function can be configured to only handle cases where a cast is needed. if (!allowSameType) return failure(); - rewriter.replaceOp(toMemref, memrefToTensor.memref()); + rewriter.replaceOp(toMemref, memrefToTensor.getMemref()); return success(); } @@ -107,7 +107,7 @@ // Ranked memref -> Ranked memref cast. if (rankedSrcType && rankedDestType) { FailureOr replacement = castOrReallocMemRefValue( - rewriter, memrefToTensor.memref(), rankedDestType); + rewriter, memrefToTensor.getMemref(), rankedDestType); if (failed(replacement)) return failure(); @@ -125,7 +125,7 @@ assert(memref::CastOp::areCastCompatible(srcType, destType) && "expected that types are cast compatible"); rewriter.replaceOpWithNewOp(toMemref, destType, - memrefToTensor.memref()); + memrefToTensor.getMemref()); return success(); } @@ -162,12 +162,12 @@ // Create buffer allocation. Value copyBuffer; - if (copy()) - copyBuffer = getBuffer(rewriter, copy(), options); + if (getCopy()) + copyBuffer = getBuffer(rewriter, getCopy(), options); auto allocType = MemRefType::get(getType().getShape(), getType().getElementType()); - SmallVector dynamicDims = dynamicSizes(); - if (copy()) { + SmallVector dynamicDims = getDynamicSizes(); + if (getCopy()) { assert(dynamicDims.empty() && "expected either `copy` or `dynamicDims`"); populateDynamicDimSizes(rewriter, loc, copyBuffer, dynamicDims); } @@ -177,7 +177,7 @@ return failure(); // Create memory copy (if any). - if (copy()) { + if (getCopy()) { if (failed(options.createMemCpy(rewriter, loc, copyBuffer, *alloc))) return failure(); } @@ -185,8 +185,8 @@ // Should the buffer be deallocated? AnalysisState analysisState(options); bool dealloc; - if (escape().hasValue()) { - dealloc = !*escape(); + if (getEscape().hasValue()) { + dealloc = !*getEscape(); } else { // No "escape" annotation found. if (options.createDeallocs) { @@ -213,7 +213,7 @@ bool AllocTensorOp::isMemoryWrite(OpResult opResult, const AnalysisState &state) { // AllocTensorOps do not write unless they have a `copy` value. - return static_cast(copy()); + return static_cast(getCopy()); } bool AllocTensorOp::bufferizesToMemoryRead(OpOperand &opOperand, @@ -238,13 +238,13 @@ } LogicalResult AllocTensorOp::verify() { - if (copy() && !dynamicSizes().empty()) + if (getCopy() && !getDynamicSizes().empty()) return emitError("dynamic sizes not needed when copying a tensor"); - if (!copy() && getType().getNumDynamicDims() != - static_cast(dynamicSizes().size())) + if (!getCopy() && getType().getNumDynamicDims() != + static_cast(getDynamicSizes().size())) return emitError("expected ") << getType().getNumDynamicDims() << " dynamic sizes"; - if (copy() && copy().getType() != getType()) + if (getCopy() && getCopy().getType() != getType()) return emitError("expected that `copy` and return type match"); return success(); } @@ -284,7 +284,7 @@ LogicalResult matchAndRewrite(AllocTensorOp op, PatternRewriter &rewriter) const override { - if (op.copy()) + if (op.getCopy()) return failure(); SmallVector newShape = llvm::to_vector(op.getType().getShape()); SmallVector newDynamicSizes; @@ -292,7 +292,7 @@ for (int64_t i = 0; i < op.getType().getRank(); ++i) { if (!op.isDynamicDim(i)) continue; - Value value = op.dynamicSizes()[dynValCounter++]; + Value value = op.getDynamicSizes()[dynValCounter++]; APInt intVal; if (matchPattern(value, m_ConstantInt(&intVal))) { newShape[i] = intVal.getSExtValue(); @@ -306,7 +306,7 @@ return failure(); auto newOp = rewriter.create( op.getLoc(), newType, newDynamicSizes, /*copy=*/Value(), - /*escape=*/op.escapeAttr()); + /*escape=*/op.getEscapeAttr()); rewriter.replaceOpWithNewOp(op, op.getType(), newOp); return success(); } @@ -381,13 +381,13 @@ } void AllocTensorOp::print(OpAsmPrinter &p) { - p << "(" << dynamicSizes() << ")"; - if (copy()) - p << " copy(" << copy() << ")"; + p << "(" << getDynamicSizes() << ")"; + if (getCopy()) + p << " copy(" << getCopy() << ")"; p.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{ AllocTensorOp::getOperandSegmentSizeAttr()}); p << " : "; - auto type = result().getType(); + auto type = getResult().getType(); if (auto validType = type.dyn_cast<::mlir::TensorType>()) p.printStrippedAttrOrType(validType); else @@ -396,8 +396,8 @@ Value AllocTensorOp::getDynamicSize(OpBuilder &b, unsigned idx) { assert(isDynamicDim(idx) && "expected dynamic dim"); - if (copy()) - return b.create(getLoc(), copy(), idx); + if (getCopy()) + return b.create(getLoc(), getCopy(), idx); return getOperand(getIndexOfDynamicSize(idx)); } @@ -408,11 +408,11 @@ void CloneOp::getEffects( SmallVectorImpl> &effects) { - effects.emplace_back(MemoryEffects::Read::get(), input(), + effects.emplace_back(MemoryEffects::Read::get(), getInput(), SideEffects::DefaultResource::get()); - effects.emplace_back(MemoryEffects::Write::get(), output(), + effects.emplace_back(MemoryEffects::Write::get(), getOutput(), SideEffects::DefaultResource::get()); - effects.emplace_back(MemoryEffects::Allocate::get(), output(), + effects.emplace_back(MemoryEffects::Allocate::get(), getOutput(), SideEffects::DefaultResource::get()); } @@ -434,13 +434,13 @@ return success(); } - Value source = cloneOp.input(); + Value source = cloneOp.getInput(); // This only finds dealloc operations for the immediate value. It should // also consider aliases. That would also make the safety check below // redundant. llvm::Optional maybeCloneDeallocOp = - memref::findDealloc(cloneOp.output()); + memref::findDealloc(cloneOp.getOutput()); // Skip if either of them has > 1 deallocate operations. if (!maybeCloneDeallocOp.hasValue()) return failure(); @@ -501,12 +501,12 @@ //===----------------------------------------------------------------------===// OpFoldResult ToTensorOp::fold(ArrayRef) { - if (auto toMemref = memref().getDefiningOp()) + if (auto toMemref = getMemref().getDefiningOp()) // Approximate alias analysis by conservatively folding only when no there // is no interleaved operation. if (toMemref->getBlock() == this->getOperation()->getBlock() && toMemref->getNextNode() == this->getOperation()) - return toMemref.tensor(); + return toMemref.getTensor(); return {}; } @@ -521,8 +521,8 @@ if (!memrefToTensorOp) return failure(); - rewriter.replaceOpWithNewOp(dimOp, memrefToTensorOp.memref(), - dimOp.index()); + rewriter.replaceOpWithNewOp( + dimOp, memrefToTensorOp.getMemref(), dimOp.index()); return success(); } }; @@ -539,9 +539,9 @@ //===----------------------------------------------------------------------===// OpFoldResult ToMemrefOp::fold(ArrayRef) { - if (auto memrefToTensor = tensor().getDefiningOp()) - if (memrefToTensor.memref().getType() == getType()) - return memrefToTensor.memref(); + if (auto memrefToTensor = getTensor().getDefiningOp()) + if (memrefToTensor.getMemref().getType() == getType()) + return memrefToTensor.getMemref(); return {}; } @@ -596,7 +596,7 @@ if (!toMemref) return failure(); - rewriter.replaceOpWithNewOp(load, toMemref.tensor(), + rewriter.replaceOpWithNewOp(load, toMemref.getTensor(), load.indices()); return success(); } diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp --- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp @@ -92,7 +92,7 @@ LogicalResult matchAndRewrite(bufferization::ToTensorOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override { - rewriter.replaceOp(op, adaptor.memref()); + rewriter.replaceOp(op, adaptor.getMemref()); return success(); } }; @@ -108,7 +108,7 @@ LogicalResult matchAndRewrite(bufferization::ToMemrefOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override { - rewriter.replaceOp(op, adaptor.tensor()); + rewriter.replaceOp(op, adaptor.getTensor()); return success(); } }; diff --git a/mlir/lib/Dialect/Bufferization/Transforms/TensorCopyInsertion.cpp b/mlir/lib/Dialect/Bufferization/Transforms/TensorCopyInsertion.cpp --- a/mlir/lib/Dialect/Bufferization/Transforms/TensorCopyInsertion.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/TensorCopyInsertion.cpp @@ -52,11 +52,11 @@ // Find AllocTensorOps without an `escape` attribute and add the attribute // based on analysis results. if (auto allocTensorOp = dyn_cast(op)) { - if (allocTensorOp.escape()) + if (allocTensorOp.getEscape()) return WalkResult::advance(); bool escape = !state.getOptions().createDeallocs || - state.isTensorYielded(allocTensorOp.result()); - allocTensorOp.escapeAttr(rewriter.getBoolAttr(escape)); + state.isTensorYielded(allocTensorOp.getResult()); + allocTensorOp.setEscapeAttr(rewriter.getBoolAttr(escape)); return WalkResult::advance(); } diff --git a/mlir/lib/Dialect/SCF/SCF.cpp b/mlir/lib/Dialect/SCF/SCF.cpp --- a/mlir/lib/Dialect/SCF/SCF.cpp +++ b/mlir/lib/Dialect/SCF/SCF.cpp @@ -986,7 +986,7 @@ if (!isTensor || !tensorLoadOp || (!bbArg.use_empty() && !tensorToMemref)) continue; // If tensorToMemref is present, it must feed into the `ToTensorOp`. - if (tensorToMemref && tensorLoadOp.memref() != tensorToMemref) + if (tensorToMemref && tensorLoadOp.getMemref() != tensorToMemref) continue; // TODO: Any aliasing write of tensorLoadOp.memref() nested under `forOp` // must be before `ToTensorOp` in the block so that the lastWrite @@ -1000,14 +1000,14 @@ if (tensorToMemref) { rewriter.setInsertionPoint(forOp); rewriter.replaceOpWithNewOp( - tensorToMemref, tensorToMemref.memref().getType(), - tensorToMemref.tensor()); + tensorToMemref, tensorToMemref.getMemref().getType(), + tensorToMemref.getTensor()); } // Clone the tensorLoad after forOp. rewriter.setInsertionPointAfter(forOp); Value newTensorLoad = rewriter.create( - loc, tensorLoadOp.memref()); + loc, tensorLoadOp.getMemref()); Value forOpResult = forOp.getResult(bbArg.getArgNumber() - /*iv=*/1); replacements.insert(std::make_pair(forOpResult, newTensorLoad));