40 if (mappingOperands.empty())
43 Operation *firstMapOp = mappingOperands.front().getDefiningOp();
46 loc, mappingOperands, convertedOperands, rewriter, globalSymbolRegion,
47 accSupport, config, runtimeArgs, callKind, &symbolTable)))
48 return rewriter.notifyMatchFailure(
49 firstMapOp,
"unsupported OpenACC data-clause operand");
52 arguments.push_back(asyncQueue);
58template <
typename OpTy>
60 ACCDataDirectivePattern(
const LLVMTypeConverter &converter,
61 OpenACCSupport &accSupport,
62 Region &globalSymbolRegion, SymbolTable &symbolTable,
63 const ACCRuntimeCallConfig &config,
64 DeviceType clauseDeviceType,
65 PatternBenefit benefit = 1)
66 : ConvertOpToLLVMPattern<OpTy>(converter, benefit),
67 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
68 symbolTable(symbolTable), config(config),
69 clauseDeviceType(clauseDeviceType) {}
72 Value
getAsyncQueue(OpTy op, ConversionPatternRewriter &rewriter)
const {
79 ConversionPatternRewriter &rewriter)
const {
81 accSupport, globalSymbolRegion, symbolTable,
86 LogicalResult emitMappingCall(OpTy op,
ValueRange convertedOperands,
89 ConversionPatternRewriter &rewriter)
const {
91 convertedOperands, asyncQueue, callKind,
92 rewriter, accSupport, globalSymbolRegion,
96 OpenACCSupport &accSupport;
97 Region &globalSymbolRegion;
98 SymbolTable &symbolTable;
99 ACCRuntimeCallConfig config;
100 DeviceType clauseDeviceType;
103struct DataOpLowering :
public ACCDataDirectivePattern<DataOp> {
104 using ACCDataDirectivePattern<DataOp>::ACCDataDirectivePattern;
107 matchAndRewrite(DataOp op, DataOp::Adaptor adaptor,
108 ConversionPatternRewriter &rewriter)
const override {
111 ValueRange mappingOperands = op.getDataClauseOperands();
112 Location beginLoc = mappingOperands.empty()
114 : mappingOperands.front().getLoc();
121 auto emitBegin = [&]() {
122 return emitMappingCall(op, adaptor.getDataClauseOperands(), beginLoc,
123 RuntimeFunction::ACCRTL_tgt_acc_data_begin,
124 ACCDataCallKind::DataEnter, asyncQueue, rewriter);
130 rewriter.setInsertionPointAfter(op);
131 auto emitEnd = [&]() {
132 return emitMappingCall(op, adaptor.getDataClauseOperands(), endLoc,
133 RuntimeFunction::ACCRTL_tgt_acc_data_end,
134 ACCDataCallKind::DataExit, asyncQueue, rewriter);
141 rewriter.eraseOp(op);
148template <
typename OpTy, RuntimeFunction fn, ACCDataCallKind callKind>
149struct ACCDataCallLowering :
public ACCDataDirectivePattern<OpTy> {
150 using ACCDataDirectivePattern<OpTy>::ACCDataDirectivePattern;
153 matchAndRewrite(OpTy op,
typename OpTy::Adaptor adaptor,
154 ConversionPatternRewriter &rewriter)
const override {
155 Location loc = op.getLoc();
161 return this->emitMappingCall(op, adaptor.getDataClauseOperands(), loc, fn,
162 callKind, asyncQueue, rewriter);
167 rewriter.eraseOp(op);
172using EnterDataOpLowering =
173 ACCDataCallLowering<EnterDataOp, RuntimeFunction::ACCRTL_tgt_acc_data_enter,
175using ExitDataOpLowering =
176 ACCDataCallLowering<ExitDataOp, RuntimeFunction::ACCRTL_tgt_acc_data_exit,
178using UpdateOpLowering =
179 ACCDataCallLowering<UpdateOp, RuntimeFunction::ACCRTL_tgt_acc_data_update,
186template <
typename OpTy>
188 using ConvertOpToLLVMPattern<OpTy>::ConvertOpToLLVMPattern;
189 using OpAdaptor =
typename OpTy::Adaptor;
192 matchAndRewrite(OpTy op, OpAdaptor adaptor,
193 ConversionPatternRewriter &rewriter)
const override {
194 rewriter.replaceOp(op, adaptor.getVar());
205struct GetDevicePtrOpLowering
207 GetDevicePtrOpLowering(
const LLVMTypeConverter &converter,
208 OpenACCSupport &accSupport, Region &globalSymbolRegion,
209 SymbolTable &symbolTable,
210 const ACCRuntimeCallConfig &config,
211 PatternBenefit benefit = 1)
212 : ConvertOpToLLVMPattern<acc::GetDevicePtrOp>(converter, benefit),
213 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
214 symbolTable(symbolTable), config(config) {}
219 static bool isMappingUse(Operation *user) {
221 acc::KernelEnvironmentOp>(user);
225 matchAndRewrite(acc::GetDevicePtrOp op, OpAdaptor adaptor,
226 ConversionPatternRewriter &rewriter)
const override {
227 bool readAsValue = llvm::any_of(
228 op->getUsers(), [](Operation *user) { return !isMappingUse(user); });
230 rewriter.replaceOp(op, adaptor.getVar());
236 if (llvm::any_of(op->getUsers(), isMappingUse)) {
237 (void)accSupport.emitNYI(
238 op.getLoc(),
"device address read from a clause that also states a "
239 "mapping of the object");
244 op, adaptor.getVar(),
false, rewriter, globalSymbolRegion,
245 symbolTable, config);
248 rewriter.replaceOp(op, *devicePtr);
252 OpenACCSupport &accSupport;
253 Region &globalSymbolRegion;
254 SymbolTable &symbolTable;
255 ACCRuntimeCallConfig config;
260template <
typename OpTy>
262 using ConvertOpToLLVMPattern<OpTy>::ConvertOpToLLVMPattern;
263 using OpAdaptor =
typename OpTy::Adaptor;
266 matchAndRewrite(OpTy op, OpAdaptor,
267 ConversionPatternRewriter &rewriter)
const override {
268 rewriter.eraseOp(op);
282 target.addIllegalOp<acc::DataOp, acc::EnterDataOp, acc::ExitDataOp,
283 acc::UpdateOp, acc::GetDevicePtrOp>();
293 converter.addConversion(
294 [](acc::DataBoundsType type) ->
Type {
return type; });
297 DataEntryOpLowering<acc::MapInfoOp>, DataEntryOpLowering<acc::CopyinOp>,
298 DataEntryOpLowering<acc::CreateOp>, DataEntryOpLowering<acc::PresentOp>,
299 DataEntryOpLowering<acc::NoCreateOp>, DataEntryOpLowering<acc::AttachOp>,
300 DataEntryOpLowering<acc::DevicePtrOp>,
301 DataEntryOpLowering<acc::UpdateDeviceOp>,
302 DataEntryOpLowering<acc::PrivateOp>,
303 DataEntryOpLowering<acc::FirstprivateOp>,
304 DataEntryOpLowering<acc::FirstprivateMapInitialOp>,
305 DataEntryOpLowering<acc::DeclareDeviceResidentOp>,
306 EraseDataClauseOp<acc::CopyoutOp>, EraseDataClauseOp<acc::DeleteOp>,
307 EraseDataClauseOp<acc::DetachOp>, EraseDataClauseOp<acc::UpdateHostOp>,
308 EraseDataClauseOp<acc::DataBoundsOp>>(converter);
309 patterns.
add<GetDevicePtrOpLowering>(converter, accSupport,
310 globalSymbolRegion, symbolTable, config);
317 acc::DeviceType clauseDeviceType) {
318 patterns.
add<DataOpLowering, EnterDataOpLowering, ExitDataOpLowering,
319 UpdateOpLowering>(converter, accSupport, globalSymbolRegion,
320 symbolTable, config, clauseDeviceType);
static LogicalResult emitDataRuntimeCall(Location loc, RuntimeFunction fn, ValueRange mappingOperands, ValueRange convertedOperands, Value asyncQueue, ACCDataCallKind callKind, ConversionPatternRewriter &rewriter, OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const ACCRuntimeCallConfig &config)
Emits the call to the mapping entry point fn for mappingOperands, the data-clause operands of a data ...
static LogicalResult emit(SolverOp solver, const SMTEmissionOptions &options, mlir::raw_indented_ostream &stream)
Emit the SMT operations in the given 'solver' to the 'stream'.
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
Conversion from types to the LLVM IR dialect.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Configuration for OpenACC to LLVM runtime lowering.
#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS
#define ACC_DATA_EXIT_OPS
std::optional< Location > getMappingExitLoc(ValueRange dataClauseOperands)
Returns where the mappings of dataClauseOperands end, taken from the first of them that says.
LogicalResult emitWaitClause(OpTy op, DeviceType deviceType, Value asyncQueue, ConversionPatternRewriter &rewriter, OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const ACCRuntimeCallConfig &config)
Emits the wait that a wait clause on op asks for before the runtime calls of the construct,...
Value getAsyncQueue(Location loc, Value asyncOperand, bool asyncOnly, OpBuilder &builder, const ACCRuntimeCallConfig &config)
Returns the queue an async clause selects: the value of the clause when it has one,...
RuntimeFunction
IDs for OpenACC compiler-to-runtime entry points (__tgt_acc_*).
LogicalResult emitGuardedByIfCond(Location loc, Value ifCond, RewriterBase &rewriter, function_ref< LogicalResult()> emitFn)
Runs emitFn guarded by a branch on ifCond, or unguarded when there is no condition.
void spliceConstructRegion(Operation *op, Region ®ion, RewriterBase &rewriter)
Splices region, the body of a structured construct, into the block holding op, so that the construct ...
FailureOr< LLVM::CallOp > createRuntimeCall(Location loc, OpBuilder &builder, Region &globalSymbolRegion, SymbolTable &symbolTable, RuntimeFunction fn, const ACCRuntimeCallConfig &config, ArrayRef< Value > arguments)
Declares (if needed) and returns a call to the runtime function identified by fn using the name from ...
FailureOr< Value > emitGetDevicePtrCall(Operation *clauseOp, Value hostPtr, bool ifPresent, OpBuilder &builder, Region &globalSymbolRegion, SymbolTable &symbolTable, const ACCRuntimeCallConfig &config)
Emits the runtime call that asks for the device address the object of the data clause clauseOp is map...
Include the generated interface declarations.
void populateACCDataClauseOpPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, acc::OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const acc::ACCRuntimeCallConfig &config={})
Populate the patterns that remove OpenACC data clause operations once the constructs holding them hav...
void populateACCDataDirectivePatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, acc::OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const acc::ACCRuntimeCallConfig &config={}, acc::DeviceType clauseDeviceType=acc::DeviceType::None)
Populate patterns that lower OpenACC data directives (acc.data, enter_data, exit_data,...
ACCDataCallKind
Identifies how data runtime arguments will be consumed.
LogicalResult emitACCDataRuntimeArgs(Location loc, ValueRange mappingOperands, ValueRange convertedOperands, ConversionPatternRewriter &rewriter, Region &globalSymbolRegion, acc::OpenACCSupport &accSupport, const acc::ACCRuntimeCallConfig &config, ACCDataRuntimeArgs &runtimeArgs, ACCDataCallKind callKind=ACCDataCallKind::DataEnter, SymbolTable *symbolTable=nullptr)
Emit the OpenACC data runtime arguments for data-clause operands.
void configureACCDataDirectiveConversionLegality(ConversionTarget &target)
Configure conversion legality for OpenACC data directives.
The arguments every mapping entry point of the OpenACC runtime takes, in the order they are passed.
SmallVector< Value > getCallArgs() const
Returns the fields above in the order the entry points take them, so that a caller only appends the a...