31 std::nullopt, independencies,
true)))
37 memref::AllocaOp allocaOp,
48 newSizes.push_back(*ub);
52 if (llvm::equal(allocaOp.getMixedSizes(), newSizes))
53 return allocaOp.getResult();
57 b.
create<AllocaOp>(loc, newSizes, allocaOp.getType().getElementType());
63 .
create<SubViewOp>(loc, newAllocaOp, offsets, allocaOp.getMixedSizes(),
69 static UnrealizedConversionCastOp
71 UnrealizedConversionCastOp conversionOp, SubViewOp op) {
74 auto newResultType = cast<MemRefType>(SubViewOp::inferRankReducedResultType(
75 op.getType().getShape(), op.getSourceType(), op.getMixedOffsets(),
76 op.getMixedSizes(), op.getMixedStrides()));
78 op.
getLoc(), newResultType, conversionOp.getOperand(0),
79 op.getMixedOffsets(), op.getMixedSizes(), op.getMixedStrides());
80 auto newConversionOp = rewriter.
create<UnrealizedConversionCastOp>(
81 op.
getLoc(), op.getType(), newSubview);
83 return newConversionOp;
103 "expected same number of results");
110 for (
const auto &it :
112 unrealizedConversions.push_back(rewriter.
create<UnrealizedConversionCastOp>(
113 to->
getLoc(), std::get<0>(it.value()).getType(),
114 std::get<1>(it.value())));
116 unrealizedConversions.back()->getResult(0));
121 for (
int i = 0; i < static_cast<int>(unrealizedConversions.size()); ++i) {
122 UnrealizedConversionCastOp conversion = unrealizedConversions[i];
123 assert(conversion->getNumOperands() == 1 &&
124 conversion->getNumResults() == 1 &&
125 "expected single operand and single result");
130 if (
auto subviewOp = dyn_cast<SubViewOp>(user)) {
131 unrealizedConversions.push_back(
141 if (llvm::any_of(user->getResultTypes(),
142 [](
Type t) { return isa<MemRefType>(t); }))
144 if (llvm::any_of(user->getRegions(), [](
Region &r) {
145 return llvm::any_of(r.getArguments(), [](BlockArgument bbArg) {
146 return isa<MemRefType>(bbArg.getType());
154 for (
OpOperand &operand : user->getOpOperands()) {
155 if ([[maybe_unused]]
auto castOp =
156 operand.get().getDefiningOp<UnrealizedConversionCastOp>()) {
158 user, [&]() { operand.set(conversion->getOperand(0)); });
165 for (
auto op : unrealizedConversions)
167 rewriter.eraseOp(op);
171 memref::AllocaOp allocaOp,
178 replacement->getDefiningOp());
184 function_ref<
bool(memref::AllocOp, memref::DeallocOp)> filter) {
185 memref::DeallocOp dealloc =
nullptr;
187 llvm::make_range(alloc->getIterator(), alloc->getBlock()->end())) {
188 dealloc = dyn_cast<memref::DeallocOp>(candidate);
189 if (dealloc && dealloc.getMemref() == alloc.getMemref() &&
190 (!filter || filter(alloc, dealloc))) {
201 alloc, alloc.getMemref().getType(), alloc.getOperands());
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Attributes are known-constant values of operations.
IntegerAttr getIndexAttr(int64_t value)
This class provides support for representing a failure result, or a valid value of type T.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
void setInsertionPointAfter(Operation *op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
This class represents a single result from folding an operation.
This class represents an operand of an operation.
Operation is the basic unit of execution within MLIR.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Location getLoc()
The source location the operation was defined or derived from.
result_range getResults()
use_range getUses()
Returns a range of all uses, which is useful for iterating over all uses.
unsigned getNumResults()
Return the number of results held by this operation.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
void updateRootInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around a root update of an operation.
void replaceAllUsesWith(Value from, Value to)
Find uses of from and replace them with to.
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replaces the result op with a new op that is created without verification.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
static LogicalResult computeIndependentBound(AffineMap &resultMap, ValueDimList &mapOperands, presburger::BoundType type, Value value, std::optional< int64_t > dim, ValueRange independencies, bool closedUB=false)
Compute a bound in that is independent of all values in independencies.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
OpFoldResult materializeComputedBound(OpBuilder &b, Location loc, AffineMap boundMap, ArrayRef< std::pair< Value, std::optional< int64_t >>> mapOperands)
Materialize an already computed bound with Affine dialect ops.
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
FailureOr< Value > buildIndependentOp(OpBuilder &b, AllocaOp allocaOp, ValueRange independencies)
Build a new memref::AllocaOp whose dynamic sizes are independent of all given independencies.
FailureOr< Value > replaceWithIndependentOp(RewriterBase &rewriter, memref::AllocaOp allocaOp, ValueRange independencies)
Build a new memref::AllocaOp whose dynamic sizes are independent of all given independencies.
memref::AllocaOp allocToAlloca(RewriterBase &rewriter, memref::AllocOp alloc, function_ref< bool(memref::AllocOp, memref::DeallocOp)> filter=nullptr)
Replaces the given alloc with the corresponding alloca and returns it if the following conditions are...
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.