36#include "llvm/Support/Debug.h"
40#define GEN_PASS_DEF_ACCLEGALIZESERIAL
41#include "mlir/Dialect/OpenACC/Transforms/Passes.h.inc"
45#define DEBUG_TYPE "acc-legalize-serial"
53 LogicalResult matchAndRewrite(acc::SerialOp serialOp,
56 const Location loc = serialOp.getLoc();
62 numValues.push_back(value);
67 numGangsSegments.push_back(numValues.size());
73 auto crtDeviceTypeAttr = mlir::acc::DeviceTypeAttr::get(
74 rewriter.
getContext(), mlir::acc::DeviceType::None);
75 crtDeviceTypes.push_back(crtDeviceTypeAttr);
77 mlir::ArrayAttr::get(rewriter.
getContext(), crtDeviceTypes);
79 LLVM_DEBUG(llvm::dbgs() <<
"acc.serial OP: " << serialOp <<
"\n");
83 acc::ParallelOp parOp = acc::ParallelOp::create(
84 rewriter, loc, serialOp.getAsyncOperands(),
85 serialOp.getAsyncOperandsDeviceTypeAttr(), serialOp.getAsyncOnlyAttr(),
86 serialOp.getWaitOperands(), serialOp.getWaitOperandsSegmentsAttr(),
87 serialOp.getWaitOperandsDeviceTypeAttr(),
88 serialOp.getHasWaitDevnumAttr(), serialOp.getWaitOnlyAttr(), numValues,
89 gangSegmentsAttr, devTypeAttr, numValues, devTypeAttr, numValues,
90 devTypeAttr, serialOp.getIfCond(), serialOp.getSelfCond(),
91 serialOp.getSelfAttrAttr(), serialOp.getReductionOperands(),
92 serialOp.getPrivateOperands(), serialOp.getFirstprivateOperands(),
93 serialOp.getDataClauseOperands(), serialOp.getDefaultAttrAttr(),
94 serialOp.getCombinedAttr());
96 parOp.getRegion().takeBody(serialOp.getRegion());
98 LLVM_DEBUG(llvm::dbgs() <<
"acc.parallel OP: " << parOp <<
"\n");
105class ACCLegalizeSerial
108 using ACCLegalizeSerialBase<ACCLegalizeSerial>::ACCLegalizeSerialBase;
111 ACCLegalizeSerialBase<ACCLegalizeSerial>::getDependentDialects(registry);
114 void runOnOperation()
override {
115 func::FuncOp funcOp = getOperation();
118 patterns.
insert<ACCSerialOpConversion>(context);
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
MLIRContext * getContext() const
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
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.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
RewritePatternSet & insert(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...
static ConstantIntOp create(OpBuilder &builder, Location location, int64_t value, unsigned width)
void registerAllExtensions(DialectRegistry ®istry)
Register the standard OpenACC models for GPU, LLVM and MemRef IR.
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...
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...