16 #define GEN_PASS_DEF_AMDGPURESOLVESTRIDEDMETADATAPASS
17 #include "mlir/Dialect/AMDGPU/Transforms/Passes.h.inc"
24 struct AmdgpuResolveStridedMetadataPass
25 :
public amdgpu::impl::AmdgpuResolveStridedMetadataPassBase<
26 AmdgpuResolveStridedMetadataPass> {
27 void runOnOperation()
override;
30 struct ExtractStridedMetadataOnFatRawBufferCastFolder final
33 LogicalResult matchAndRewrite(memref::ExtractStridedMetadataOp metadataOp,
35 auto castOp = metadataOp.getSource().getDefiningOp<FatRawBufferCastOp>();
38 "not a fat raw buffer cast");
40 auto sourceMetadata = rewriter.
create<memref::ExtractStridedMetadataOp>(
41 loc, castOp.getSource());
43 if (metadataOp.getBaseBuffer().use_empty()) {
44 results.push_back(
nullptr);
47 cast<MemRefType>(metadataOp.getBaseBuffer().getType());
48 if (baseBufferType == castOp.getResult().getType()) {
49 results.push_back(castOp.getResult());
51 results.push_back(rewriter.
create<memref::ReinterpretCastOp>(
52 loc, baseBufferType, castOp.getResult(), 0,
56 if (castOp.getResetOffset())
57 results.push_back(rewriter.
create<arith::ConstantIndexOp>(loc, 0));
59 results.push_back(sourceMetadata.getOffset());
60 llvm::append_range(results, sourceMetadata.getSizes());
61 llvm::append_range(results, sourceMetadata.getStrides());
70 patterns.add<ExtractStridedMetadataOnFatRawBufferCastFolder>(
74 void AmdgpuResolveStridedMetadataPass::runOnOperation() {
static MLIRContext * getContext(OpFoldResult val)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
void populateAmdgpuResolveStridedMetadataPatterns(RewritePatternSet &patterns)
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
const FrozenRewritePatternSet & patterns
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...