65 MemRefType srcType = subView.getSourceType();
67 if (!srcType.hasStaticShape())
73 if (srcType.getRank() != subView.getType().getRank())
77 if (!subView.hasUnitStride())
80 return VectorType::isValidElementType(srcType.getElementType());
88 if (!subView.getType().hasStaticShape())
95 return llvm::all_of(subView.getMixedOffsets(), [](
OpFoldResult offset) {
96 return getConstantIntValue(offset).has_value();
105 if (subView.getType().hasStaticShape())
112 return subView.hasZeroOffset();
121 assert(value &&
"expected a static offset");
122 offsets.push_back(*value);
130 auto parentType = cast<MemRefType>(subView.getSource().getType());
131 assert(parentType.hasStaticShape() &&
"expected a statically-shaped parent");
132 return VectorType::get(parentType.getShape(), parentType.getElementType());
146 memref::SubViewOp subView) {
150 return vector::CreateMaskOp::create(
152 VectorType::get(parentVecType.getShape(), builder.
getI1Type()), bounds);
175struct SubViewOpPromotableModel
176 :
public PromotableOpInterface::ExternalModel<SubViewOpPromotableModel,
184 newBlockingUses.push_back(&use);
211struct SubViewOpAliasModel
212 :
public PromotableAliaserInterface::ExternalModel<SubViewOpAliasModel,
214 void getPromotableSlotAliases(Operation *op,
215 OpOperand &aliasedSlotPointerOperand,
216 const MemorySlot &parentSlot,
217 SmallVectorImpl<MemorySlot> &newSlots)
const {
218 auto subView = cast<memref::SubViewOp>(op);
221 if (aliasedSlotPointerOperand.
get() != subView.getSource())
226 auto parentVecType = dyn_cast<VectorType>(parentSlot.
valueType);
232 auto resType = cast<MemRefType>(subView.getResult().getType());
233 VectorType aliasVecType =
234 VectorType::get(resType.getShape(), resType.getElementType());
235 newSlots.push_back(MemorySlot{subView.getResult(), aliasVecType});
240 newSlots.push_back(MemorySlot{subView.getResult(), parentVecType});
244 Value projectSlotValueToAliasValue(Operation *op,
247 const MemorySlot &aliasSlot,
249 OpBuilder &builder)
const {
250 auto subView = cast<memref::SubViewOp>(op);
258 auto aliasVecType = cast<VectorType>(aliasSlot.
valueType);
259 SmallVector<int64_t> strides(offsets.size(), 1);
260 return vector::ExtractStridedSliceOp::create(
261 builder, op->
getLoc(), slotValue, offsets,
262 aliasVecType.getShape(), strides)
266 Value projectAliasValueToSlotValue(Operation *op,
270 Value aliasValue, Value reachingDef,
271 OpBuilder &builder)
const {
272 auto subView = cast<memref::SubViewOp>(op);
276 Location loc = op->
getLoc();
278 return arith::SelectOp::create(builder, loc, mask, aliasValue,
283 SmallVector<int64_t> strides(offsets.size(), 1);
284 return vector::InsertStridedSliceOp::create(
285 builder, op->
getLoc(), aliasValue, reachingDef, offsets, strides)
298 memref::SubViewOp::attachInterface<SubViewOpAliasModel>(*ctx);
299 memref::SubViewOp::attachInterface<SubViewOpPromotableModel>(*ctx);
The main mechanism for performing data layout queries.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
IRValueT get() const
Return the current value being used by this operand.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class helps build Operations.
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.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
void registerMemorySlotOpInterfaceExternalModels(DialectRegistry ®istry)
Value buildDynamicSubViewMask(OpBuilder &builder, Location loc, Value slotPtr)
Builds a mask for the subview's valid region in the parent vector, or returns null if isDynamicSubVie...
bool isDynamicSubViewSlot(Value slotPtr)
Returns whether slotPtr is a dynamic memref.subview that can be promoted as an alias of the whole par...
Include the generated interface declarations.
std::optional< int64_t > getConstantIntValue(OpFoldResult ofr)
If ofr is a constant integer or an IntegerAttr, return the integer.
DeletionKind
Returned by operation promotion logic requesting the deletion of an operation.
@ Delete
Delete the operation after promotion.
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
Type valueType
Type of the value contained in the slot.