73#define GEN_PASS_DEF_ACCSPECIALIZEFORDEVICE
74#include "mlir/Dialect/OpenACC/Transforms/Passes.h.inc"
84class FoldAccOnDeviceOpConversion :
public OpRewritePattern<acc::OnDeviceOp> {
85 using OpRewritePattern<acc::OnDeviceOp>::OpRewritePattern;
90 FoldAccOnDeviceOpConversion(MLIRContext *context,
92 : OpRewritePattern<acc::OnDeviceOp>(context),
93 theDeviceTypes(theDeviceTypes) {}
95 LogicalResult matchAndRewrite(acc::OnDeviceOp op,
96 PatternRewriter &rewriter)
const override {
101 bool result = theDeviceTypes.contains(constVal.getSExtValue());
108class ACCSpecializeForDevice
111 using ACCSpecializeForDeviceBase<
112 ACCSpecializeForDevice>::ACCSpecializeForDeviceBase;
114 void runOnOperation()
override {
115 func::FuncOp func = getOperation();
117 TypesForDevice types{theDeviceTypes.begin(), theDeviceTypes.end()};
121 GreedyRewriteConfig config;
135 SmallVector<Operation *> opsToTransform;
136 func.walk([&](Operation *op) {
137 if (isa<ACC_COMPUTE_CONSTRUCT_OPS>(op)) {
139 op->
walk([&](Operation *innerOp) {
143 if (isa<acc::OpenACCDialect>(innerOp->
getDialect()))
144 opsToTransform.push_back(innerOp);
148 if (!opsToTransform.empty())
212 patterns.
insert<FoldAccOnDeviceOpConversion>(context, theDeviceTypes);
BoolAttr getBoolAttr(bool value)
GreedyRewriteConfig & setUseTopDownTraversal(bool use=true)
GreedyRewriteConfig & setStrictness(GreedyRewriteStrictness mode)
MLIRContext is the top-level object for a collection of MLIR operations.
Dialect * getDialect()
Return the dialect this operation is associated with, or nullptr if the associated dialect is not loa...
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
RewritePatternSet & insert(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
MLIRContext * getContext() const
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
Pattern to erase acc.declare_enter and its associated acc.declare_exit.
Pattern to simply erase an ACC op (for ops with no results).
Pattern to replace an ACC op with its var operand.
Pattern to unwrap a region from an ACC op and erase the wrapper.
llvm::SmallSetVector< int64_t, 3 > TypesForDevice
Holds information for which integers represent a device type in the runtime.
bool isSpecializedAccRoutine(mlir::Operation *op)
Used to check whether this is a specialized accelerator version of acc routine function.
void populateACCSpecializeForDevicePatterns(RewritePatternSet &patterns, const TypesForDevice &theDeviceTypes)
Populates all patterns for device specialization.
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
detail::constant_int_value_binder m_ConstantInt(IntegerAttr::ValueType *bind_value)
Matches a constant holding a scalar/vector/tensor integer (splat) and writes the integer value to bin...
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...
LogicalResult applyOpPatternsGreedily(ArrayRef< Operation * > ops, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr, bool *allErased=nullptr)
Rewrite the specified ops by repeatedly applying the highest benefit patterns in a greedy worklist dr...
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...