28struct PromoteShuffleToSwizzlePattern
32 LogicalResult matchAndRewrite(gpu::ShuffleOp op,
33 PatternRewriter &rewriter)
const override {
34 if (op.getMode() != gpu::ShuffleMode::XOR)
36 "only xor shuffle mode is supported");
40 "only 64 width shuffle is supported");
45 "offset must be a constant integer");
47 int64_t offsetValue = *offset;
48 if (offsetValue < 0 || offsetValue >= 32)
50 "offset must be in the range [0, 31]");
52 Location loc = op.getLoc();
53 Value res = amdgpu::SwizzleBitModeOp::create(
54 rewriter, loc, op.getResult(0).getType(), op.getValue(),
65struct PromoteShuffleToPermlanePattern
69 LogicalResult matchAndRewrite(gpu::ShuffleOp op,
70 PatternRewriter &rewriter)
const override {
71 if (op.getMode() != gpu::ShuffleMode::XOR)
73 "only xor shuffle mode is supported");
77 "only 64 width shuffle is supported");
82 "offset must be a constant integer");
84 int64_t offsetValue = *offset;
85 if (offsetValue != 16 && offsetValue != 32)
88 Location loc = op.getLoc();
89 Value res = amdgpu::PermlaneSwapOp::create(
90 rewriter, loc, op.getResult(0).getType(), op.getValue(), offsetValue);
100 patterns.
add<PromoteShuffleToSwizzlePattern>(patterns.
getContext(),
102 if (
target &&
target->has(llvm::AMDGPU::FEAT_PERMLANE32_SWAP))
103 patterns.
add<PromoteShuffleToPermlanePattern>(patterns.
getContext(),
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
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,...
static ConstantIntOp create(OpBuilder &builder, Location location, int64_t value, unsigned width)
Include the generated interface declarations.
bool isConstantIntValue(OpFoldResult ofr, int64_t value)
Return true if ofr is constant integer equal to value.
void populateGpuPromoteShuffleToAMDGPUPatterns(RewritePatternSet &patterns, std::optional< ROCDL::TargetInfo > target)
Tries to promote gpu.shuffles to specialized AMDGPU intrinsics.
std::optional< int64_t > getConstantIntValue(OpFoldResult ofr)
If ofr is a constant integer or an IntegerAttr, return the integer.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...