35#include "llvm/Support/Debug.h"
39#define GEN_PASS_DEF_ACCLEGALIZESERIAL
40#include "mlir/Dialect/OpenACC/Transforms/Passes.h.inc"
44#define DEBUG_TYPE "acc-legalize-serial"
52 LogicalResult matchAndRewrite(acc::SerialOp serialOp,
55 const Location loc = serialOp.getLoc();
61 numValues.push_back(value);
66 numGangsSegments.push_back(numValues.size());
72 auto crtDeviceTypeAttr = mlir::acc::DeviceTypeAttr::get(
73 rewriter.
getContext(), mlir::acc::DeviceType::None);
74 crtDeviceTypes.push_back(crtDeviceTypeAttr);
76 mlir::ArrayAttr::get(rewriter.
getContext(), crtDeviceTypes);
78 LLVM_DEBUG(llvm::dbgs() <<
"acc.serial OP: " << serialOp <<
"\n");
82 acc::ParallelOp parOp = acc::ParallelOp::create(
83 rewriter, loc, serialOp.getAsyncOperands(),
84 serialOp.getAsyncOperandsDeviceTypeAttr(), serialOp.getAsyncOnlyAttr(),
85 serialOp.getWaitOperands(), serialOp.getWaitOperandsSegmentsAttr(),
86 serialOp.getWaitOperandsDeviceTypeAttr(),
87 serialOp.getHasWaitDevnumAttr(), serialOp.getWaitOnlyAttr(), numValues,
88 gangSegmentsAttr, devTypeAttr, numValues, devTypeAttr, numValues,
89 devTypeAttr, serialOp.getIfCond(), serialOp.getSelfCond(),
90 serialOp.getSelfAttrAttr(), serialOp.getReductionOperands(),
91 serialOp.getPrivateOperands(), serialOp.getFirstprivateOperands(),
92 serialOp.getDataClauseOperands(), serialOp.getDefaultAttrAttr(),
93 serialOp.getCombinedAttr());
95 parOp.getRegion().takeBody(serialOp.getRegion());
97 LLVM_DEBUG(llvm::dbgs() <<
"acc.parallel OP: " << parOp <<
"\n");
104class ACCLegalizeSerial
107 using ACCLegalizeSerialBase<ACCLegalizeSerial>::ACCLegalizeSerialBase;
108 void runOnOperation()
override {
109 func::FuncOp funcOp = getOperation();
112 patterns.insert<ACCSerialOpConversion>(context);
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
MLIRContext * getContext() const
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...
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)
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...