45 loc, fn, mappingOperands, convertedOperands, rewriter, accSupport,
46 globalSymbolRegion, symbolTable, config, trailingArguments,
options);
54 auto func = dyn_cast<FunctionOpInterface>(op);
63 ConversionPatternRewriter &rewriter,
65 return LLVM::ConstantOp::create(rewriter, loc, rewriter.getI64Type(),
70template <
typename OpTy>
72 ACCDataDirectivePattern(
const LLVMTypeConverter &converter,
73 OpenACCSupport &accSupport,
74 Region &globalSymbolRegion, SymbolTable &symbolTable,
75 const ACCRuntimeCallConfig &config,
76 DeviceType clauseDeviceType,
77 PatternBenefit benefit = 1)
78 : ConvertOpToLLVMPattern<OpTy>(converter, benefit),
79 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
80 symbolTable(symbolTable), config(config),
81 clauseDeviceType(clauseDeviceType) {}
84 Value
getAsyncQueue(OpTy op, ConversionPatternRewriter &rewriter)
const {
91 ConversionPatternRewriter &rewriter)
const {
93 accSupport, globalSymbolRegion, symbolTable,
98 LogicalResult emitMappingCall(OpTy op,
ValueRange convertedOperands,
101 ConversionPatternRewriter &rewriter)
const {
103 convertedOperands, callKind, rewriter,
104 accSupport, globalSymbolRegion, symbolTable,
105 config, {asyncQueue});
108 OpenACCSupport &accSupport;
109 Region &globalSymbolRegion;
110 SymbolTable &symbolTable;
111 ACCRuntimeCallConfig config;
112 DeviceType clauseDeviceType;
115struct DataOpLowering :
public ACCDataDirectivePattern<DataOp> {
116 using ACCDataDirectivePattern<DataOp>::ACCDataDirectivePattern;
119 matchAndRewrite(DataOp op, DataOp::Adaptor adaptor,
120 ConversionPatternRewriter &rewriter)
const override {
123 ValueRange mappingOperands = op.getDataClauseOperands();
124 Location beginLoc = mappingOperands.empty()
126 : mappingOperands.front().getLoc();
133 auto emitBegin = [&]() {
134 return emitMappingCall(op, adaptor.getDataClauseOperands(), beginLoc,
135 RuntimeFunction::ACCRTL_tgt_acc_data_begin,
136 ACCDataCallKind::DataEnter, asyncQueue, rewriter);
142 rewriter.setInsertionPointAfter(op);
143 auto emitEnd = [&]() {
144 return emitMappingCall(op, adaptor.getDataClauseOperands(), endLoc,
145 RuntimeFunction::ACCRTL_tgt_acc_data_end,
146 ACCDataCallKind::DataExit, asyncQueue, rewriter);
153 rewriter.eraseOp(op);
160template <
typename OpTy, RuntimeFunction fn, ACCDataCallKind callKind>
161struct ACCDataCallLowering :
public ACCDataDirectivePattern<OpTy> {
162 using ACCDataDirectivePattern<OpTy>::ACCDataDirectivePattern;
165 matchAndRewrite(OpTy op,
typename OpTy::Adaptor adaptor,
166 ConversionPatternRewriter &rewriter)
const override {
167 Location loc = op.getLoc();
173 return this->emitMappingCall(op, adaptor.getDataClauseOperands(), loc, fn,
174 callKind, asyncQueue, rewriter);
179 rewriter.eraseOp(op);
184using EnterDataOpLowering =
185 ACCDataCallLowering<EnterDataOp, RuntimeFunction::ACCRTL_tgt_acc_data_enter,
187using ExitDataOpLowering =
188 ACCDataCallLowering<ExitDataOp, RuntimeFunction::ACCRTL_tgt_acc_data_exit,
190using UpdateOpLowering =
191 ACCDataCallLowering<UpdateOp, RuntimeFunction::ACCRTL_tgt_acc_data_update,
200 DeclareEnterOpLowering(
const LLVMTypeConverter &converter,
201 OpenACCSupport &accSupport, Region &globalSymbolRegion,
202 SymbolTable &symbolTable,
203 const ACCRuntimeCallConfig &config,
204 PatternBenefit benefit = 1)
205 : ConvertOpToLLVMPattern<DeclareEnterOp>(converter, benefit),
206 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
207 symbolTable(symbolTable), config(config) {}
210 matchAndRewrite(DeclareEnterOp op, DeclareEnterOp::Adaptor adaptor,
211 ConversionPatternRewriter &rewriter)
const override {
212 Location loc = op.getLoc();
213 ValueRange mappingOperands = op.getDataClauseOperands();
214 ValueRange convertedOperands = adaptor.getDataClauseOperands();
217 LogicalResult emitted =
success();
220 loc, RuntimeFunction::ACCRTL_tgt_acc_mirror_alloc, mappingOperands,
221 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
222 globalSymbolRegion, symbolTable, config, {});
223 }
else if (!op.getToken().use_empty()) {
225 loc, RuntimeFunction::ACCRTL_tgt_acc_data_begin, mappingOperands,
226 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
227 globalSymbolRegion, symbolTable, config, {asyncQueue});
229 Value binaryDescriptor =
230 config.createDeclareBinaryDescriptor(loc, rewriter);
232 loc, RuntimeFunction::ACCRTL_tgt_acc_declare, mappingOperands,
233 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
234 globalSymbolRegion, symbolTable, config,
235 {asyncQueue, binaryDescriptor});
240 if (op.getToken().use_empty()) {
241 rewriter.eraseOp(op);
245 Type tokenTy = getTypeConverter()->convertType(op.getToken().getType());
246 rewriter.replaceOp(op, LLVM::ZeroOp::create(rewriter, loc, tokenTy));
251 OpenACCSupport &accSupport;
252 Region &globalSymbolRegion;
253 SymbolTable &symbolTable;
254 ACCRuntimeCallConfig config;
261 DeclareExitOpLowering(
const LLVMTypeConverter &converter,
262 OpenACCSupport &accSupport, Region &globalSymbolRegion,
263 SymbolTable &symbolTable,
264 const ACCRuntimeCallConfig &config,
265 PatternBenefit benefit = 1)
266 : ConvertOpToLLVMPattern<DeclareExitOp>(converter, benefit),
267 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
268 symbolTable(symbolTable), config(config) {}
271 matchAndRewrite(DeclareExitOp op, DeclareExitOp::Adaptor adaptor,
272 ConversionPatternRewriter &rewriter)
const override {
273 Location loc = op.getLoc();
274 ValueRange mappingOperands = op.getDataClauseOperands();
275 ValueRange convertedOperands = adaptor.getDataClauseOperands();
278 LogicalResult emitted =
success();
280 if (action && action.getPreDealloc()) {
282 loc, RuntimeFunction::ACCRTL_tgt_acc_mirror_dealloc, mappingOperands,
283 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
284 globalSymbolRegion, symbolTable, config, {});
287 loc, RuntimeFunction::ACCRTL_tgt_acc_data_end, mappingOperands,
288 convertedOperands, ACCDataCallKind::DataExit, rewriter, accSupport,
289 globalSymbolRegion, symbolTable, config, {asyncQueue});
293 rewriter.eraseOp(op);
297 OpenACCSupport &accSupport;
298 Region &globalSymbolRegion;
299 SymbolTable &symbolTable;
300 ACCRuntimeCallConfig config;
307template <
typename OpTy>
309 using ConvertOpToLLVMPattern<OpTy>::ConvertOpToLLVMPattern;
310 using OpAdaptor =
typename OpTy::Adaptor;
313 matchAndRewrite(OpTy op, OpAdaptor adaptor,
314 ConversionPatternRewriter &rewriter)
const override {
315 rewriter.replaceOp(op, adaptor.getVar());
326struct GetDevicePtrOpLowering
328 GetDevicePtrOpLowering(
const LLVMTypeConverter &converter,
329 OpenACCSupport &accSupport, Region &globalSymbolRegion,
330 SymbolTable &symbolTable,
331 const ACCRuntimeCallConfig &config,
332 PatternBenefit benefit = 1)
333 : ConvertOpToLLVMPattern<acc::GetDevicePtrOp>(converter, benefit),
334 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
335 symbolTable(symbolTable), config(config) {}
340 static bool isMappingUse(Operation *user) {
342 acc::KernelEnvironmentOp>(user);
346 matchAndRewrite(acc::GetDevicePtrOp op, OpAdaptor adaptor,
347 ConversionPatternRewriter &rewriter)
const override {
348 bool readAsValue = llvm::any_of(
349 op->getUsers(), [](Operation *user) { return !isMappingUse(user); });
351 rewriter.replaceOp(op, adaptor.getVar());
357 if (llvm::any_of(op->getUsers(), isMappingUse)) {
358 (void)accSupport.emitNYI(
359 op.getLoc(),
"device address read from a clause that also states a "
360 "mapping of the object");
365 op, adaptor.getVar(),
false, rewriter, globalSymbolRegion,
366 symbolTable, config);
369 rewriter.replaceOp(op, *devicePtr);
373 OpenACCSupport &accSupport;
374 Region &globalSymbolRegion;
375 SymbolTable &symbolTable;
376 ACCRuntimeCallConfig config;
381template <
typename OpTy>
383 using ConvertOpToLLVMPattern<OpTy>::ConvertOpToLLVMPattern;
384 using OpAdaptor =
typename OpTy::Adaptor;
387 matchAndRewrite(OpTy op, OpAdaptor,
388 ConversionPatternRewriter &rewriter)
const override {
389 rewriter.eraseOp(op);
403 target.addIllegalOp<acc::DataOp, acc::EnterDataOp, acc::ExitDataOp,
404 acc::UpdateOp, acc::DeclareEnterOp, acc::DeclareExitOp,
405 acc::GetDevicePtrOp>();
415 converter.addConversion(
416 [](acc::DataBoundsType type) ->
Type {
return type; });
419 DataEntryOpLowering<acc::MapInfoOp>, DataEntryOpLowering<acc::CopyinOp>,
420 DataEntryOpLowering<acc::CreateOp>, DataEntryOpLowering<acc::PresentOp>,
421 DataEntryOpLowering<acc::NoCreateOp>, DataEntryOpLowering<acc::AttachOp>,
422 DataEntryOpLowering<acc::DevicePtrOp>,
423 DataEntryOpLowering<acc::UpdateDeviceOp>,
424 DataEntryOpLowering<acc::PrivateOp>,
425 DataEntryOpLowering<acc::FirstprivateOp>,
426 DataEntryOpLowering<acc::FirstprivateMapInitialOp>,
427 DataEntryOpLowering<acc::DeclareDeviceResidentOp>,
428 DataEntryOpLowering<acc::DeclareLinkOp>,
429 EraseDataClauseOp<acc::CopyoutOp>, EraseDataClauseOp<acc::DeleteOp>,
430 EraseDataClauseOp<acc::DetachOp>, EraseDataClauseOp<acc::UpdateHostOp>,
431 EraseDataClauseOp<acc::DataBoundsOp>>(converter);
432 patterns.
add<GetDevicePtrOpLowering>(converter, accSupport,
433 globalSymbolRegion, symbolTable, config);
440 acc::DeviceType clauseDeviceType) {
441 converter.addConversion([](acc::DeclareTokenType type) ->
Type {
442 return LLVM::LLVMPointerType::get(type.getContext());
445 patterns.
add<DataOpLowering, EnterDataOpLowering, ExitDataOpLowering,
446 UpdateOpLowering>(converter, accSupport, globalSymbolRegion,
447 symbolTable, config, clauseDeviceType);
448 patterns.
add<DeclareEnterOpLowering, DeclareExitOpLowering>(
449 converter, accSupport, globalSymbolRegion, symbolTable, config);
static DeclareActionAttr getEnclosingDeclareAction(Operation *op)
Returns the action that the declare-action recipe holding op carries out, which the recipe states by ...
static LogicalResult emitDataRuntimeCall(Location loc, RuntimeFunction fn, ValueRange mappingOperands, ValueRange convertedOperands, ACCDataCallKind callKind, ConversionPatternRewriter &rewriter, OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const ACCRuntimeCallConfig &config, ArrayRef< Value > trailingArguments)
Emits the call to the mapping entry point fn for mappingOperands, the data-clause operands of a data ...
static Value getDeclareAsyncQueue(Location loc, ConversionPatternRewriter &rewriter, const ACCRuntimeCallConfig &config)
static llvm::ManagedStatic< PassManagerOptions > options
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.
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
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.
int64_t getAsyncSyncRuntimeValue() const
#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.
static constexpr StringLiteral getDeclareActionAttrName()
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< 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,...
FailureOr< SmallVector< Value > > emitACCDataRuntimeCall(Location loc, acc::RuntimeFunction fn, ValueRange mappingOperands, ValueRange convertedOperands, ConversionPatternRewriter &rewriter, acc::OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const acc::ACCRuntimeCallConfig &config, ArrayRef< Value > trailingArguments, const ACCDataCallOptions &options={})
Emit the call to the mapping entry point fn for mappingOperands, followed by trailingArguments.
ACCDataCallKind
Identifies how data runtime arguments will be consumed.
void configureACCDataDirectiveConversionLegality(ConversionTarget &target)
Configure conversion legality for OpenACC data directives.
What a data runtime call is asked for besides mapping its operands.