48 loc, fn, mappingOperands, convertedOperands, rewriter, accSupport,
49 globalSymbolRegion, symbolTable, config, trailingArguments,
options);
57 auto func = dyn_cast<FunctionOpInterface>(op);
66 ConversionPatternRewriter &rewriter,
68 return LLVM::ConstantOp::create(rewriter, loc, rewriter.getI64Type(),
73template <
typename OpTy>
75 ACCDataDirectivePattern(
const LLVMTypeConverter &converter,
76 OpenACCSupport &accSupport,
77 Region &globalSymbolRegion, SymbolTable &symbolTable,
78 const ACCRuntimeCallConfig &config,
79 DeviceType clauseDeviceType,
80 PatternBenefit benefit = 1)
81 : ConvertOpToLLVMPattern<OpTy>(converter, benefit),
82 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
83 symbolTable(symbolTable), config(config),
84 clauseDeviceType(clauseDeviceType) {}
87 Value
getAsyncQueue(OpTy op, ConversionPatternRewriter &rewriter)
const {
94 ConversionPatternRewriter &rewriter)
const {
96 accSupport, globalSymbolRegion, symbolTable,
101 LogicalResult emitMappingCall(OpTy op,
ValueRange convertedOperands,
104 ConversionPatternRewriter &rewriter)
const {
106 convertedOperands, callKind, rewriter,
107 accSupport, globalSymbolRegion, symbolTable,
108 config, {asyncQueue});
111 OpenACCSupport &accSupport;
112 Region &globalSymbolRegion;
113 SymbolTable &symbolTable;
114 ACCRuntimeCallConfig config;
115 DeviceType clauseDeviceType;
118struct DataOpLowering :
public ACCDataDirectivePattern<DataOp> {
119 using ACCDataDirectivePattern<DataOp>::ACCDataDirectivePattern;
122 matchAndRewrite(DataOp op, DataOp::Adaptor adaptor,
123 ConversionPatternRewriter &rewriter)
const override {
126 ValueRange mappingOperands = op.getDataClauseOperands();
127 Location beginLoc = mappingOperands.empty()
129 : mappingOperands.front().getLoc();
136 auto emitBegin = [&]() {
137 return emitMappingCall(op, adaptor.getDataClauseOperands(), beginLoc,
138 RuntimeFunction::ACCRTL_tgt_acc_data_begin,
139 ACCDataCallKind::DataEnter, asyncQueue, rewriter);
145 rewriter.setInsertionPointAfter(op);
146 auto emitEnd = [&]() {
147 return emitMappingCall(op, adaptor.getDataClauseOperands(), endLoc,
148 RuntimeFunction::ACCRTL_tgt_acc_data_end,
149 ACCDataCallKind::DataExit, asyncQueue, rewriter);
156 rewriter.eraseOp(op);
163template <
typename OpTy, RuntimeFunction fn, ACCDataCallKind callKind>
164struct ACCDataCallLowering :
public ACCDataDirectivePattern<OpTy> {
165 using ACCDataDirectivePattern<OpTy>::ACCDataDirectivePattern;
168 matchAndRewrite(OpTy op,
typename OpTy::Adaptor adaptor,
169 ConversionPatternRewriter &rewriter)
const override {
170 Location loc = op.getLoc();
176 return this->emitMappingCall(op, adaptor.getDataClauseOperands(), loc, fn,
177 callKind, asyncQueue, rewriter);
182 rewriter.eraseOp(op);
187using EnterDataOpLowering =
188 ACCDataCallLowering<EnterDataOp, RuntimeFunction::ACCRTL_tgt_acc_data_enter,
190using ExitDataOpLowering =
191 ACCDataCallLowering<ExitDataOp, RuntimeFunction::ACCRTL_tgt_acc_data_exit,
193using UpdateOpLowering =
194 ACCDataCallLowering<UpdateOp, RuntimeFunction::ACCRTL_tgt_acc_data_update,
204 DeclareEnterOpLowering(
const LLVMTypeConverter &converter,
205 OpenACCSupport &accSupport, Region &globalSymbolRegion,
206 SymbolTable &symbolTable,
207 const ACCRuntimeCallConfig &config,
208 PatternBenefit benefit = 1)
209 : ConvertOpToLLVMPattern<DeclareEnterOp>(converter, benefit),
210 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
211 symbolTable(symbolTable), config(config) {}
214 matchAndRewrite(DeclareEnterOp op, DeclareEnterOp::Adaptor adaptor,
215 ConversionPatternRewriter &rewriter)
const override {
216 Location loc = op.getLoc();
217 ValueRange mappingOperands = op.getDataClauseOperands();
218 ValueRange convertedOperands = adaptor.getDataClauseOperands();
221 LogicalResult emitted =
success();
224 loc, RuntimeFunction::ACCRTL_tgt_acc_mirror_alloc, mappingOperands,
225 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
226 globalSymbolRegion, symbolTable, config, {});
227 }
else if (!op.getToken().use_empty()) {
229 loc, RuntimeFunction::ACCRTL_tgt_acc_data_begin, mappingOperands,
230 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
231 globalSymbolRegion, symbolTable, config, {asyncQueue},
232 ACCDataRegionFlags::Declare);
234 Value binaryDescriptor =
235 config.createDeclareBinaryDescriptor(loc, rewriter);
237 loc, RuntimeFunction::ACCRTL_tgt_acc_declare, mappingOperands,
238 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
239 globalSymbolRegion, symbolTable, config,
240 {asyncQueue, binaryDescriptor});
245 if (op.getToken().use_empty()) {
246 rewriter.eraseOp(op);
250 Type tokenTy = getTypeConverter()->convertType(op.getToken().getType());
251 rewriter.replaceOp(op, LLVM::ZeroOp::create(rewriter, loc, tokenTy));
256 OpenACCSupport &accSupport;
257 Region &globalSymbolRegion;
258 SymbolTable &symbolTable;
259 ACCRuntimeCallConfig config;
268 DeclareExitOpLowering(
const LLVMTypeConverter &converter,
269 OpenACCSupport &accSupport, Region &globalSymbolRegion,
270 SymbolTable &symbolTable,
271 const ACCRuntimeCallConfig &config,
272 PatternBenefit benefit = 1)
273 : ConvertOpToLLVMPattern<DeclareExitOp>(converter, benefit),
274 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
275 symbolTable(symbolTable), config(config) {}
278 matchAndRewrite(DeclareExitOp op, DeclareExitOp::Adaptor adaptor,
279 ConversionPatternRewriter &rewriter)
const override {
280 Location loc = op.getLoc();
281 ValueRange mappingOperands = op.getDataClauseOperands();
282 ValueRange convertedOperands = adaptor.getDataClauseOperands();
285 LogicalResult emitted =
success();
287 if (action && action.getPreDealloc()) {
289 loc, RuntimeFunction::ACCRTL_tgt_acc_mirror_dealloc, mappingOperands,
290 convertedOperands, ACCDataCallKind::DataEnter, rewriter, accSupport,
291 globalSymbolRegion, symbolTable, config, {});
294 ? ACCDataRegionFlags::Declare
295 : ACCDataRegionFlags::None;
297 loc, RuntimeFunction::ACCRTL_tgt_acc_data_end, mappingOperands,
298 convertedOperands, ACCDataCallKind::DataExit, rewriter, accSupport,
299 globalSymbolRegion, symbolTable, config, {asyncQueue}, regionFlags);
303 rewriter.eraseOp(op);
307 OpenACCSupport &accSupport;
308 Region &globalSymbolRegion;
309 SymbolTable &symbolTable;
310 ACCRuntimeCallConfig config;
317template <
typename OpTy>
319 using ConvertOpToLLVMPattern<OpTy>::ConvertOpToLLVMPattern;
320 using OpAdaptor =
typename OpTy::Adaptor;
323 matchAndRewrite(OpTy op, OpAdaptor adaptor,
324 ConversionPatternRewriter &rewriter)
const override {
325 rewriter.replaceOp(op, adaptor.getVar());
336struct GetDevicePtrOpLowering
338 GetDevicePtrOpLowering(
const LLVMTypeConverter &converter,
339 OpenACCSupport &accSupport, Region &globalSymbolRegion,
340 SymbolTable &symbolTable,
341 const ACCRuntimeCallConfig &config,
342 PatternBenefit benefit = 1)
343 : ConvertOpToLLVMPattern<acc::GetDevicePtrOp>(converter, benefit),
344 accSupport(accSupport), globalSymbolRegion(globalSymbolRegion),
345 symbolTable(symbolTable), config(config) {}
350 static bool isMappingUse(Operation *user) {
352 acc::KernelEnvironmentOp>(user);
356 matchAndRewrite(acc::GetDevicePtrOp op, OpAdaptor adaptor,
357 ConversionPatternRewriter &rewriter)
const override {
358 bool readAsValue = llvm::any_of(
359 op->getUsers(), [](Operation *user) { return !isMappingUse(user); });
361 rewriter.replaceOp(op, adaptor.getVar());
367 if (llvm::any_of(op->getUsers(), isMappingUse)) {
368 (void)accSupport.emitNYI(
369 op.getLoc(),
"device address read from a clause that also states a "
370 "mapping of the object");
375 op, adaptor.getVar(),
false, rewriter, globalSymbolRegion,
376 symbolTable, config);
379 rewriter.replaceOp(op, *devicePtr);
383 OpenACCSupport &accSupport;
384 Region &globalSymbolRegion;
385 SymbolTable &symbolTable;
386 ACCRuntimeCallConfig config;
391template <
typename OpTy>
393 using ConvertOpToLLVMPattern<OpTy>::ConvertOpToLLVMPattern;
394 using OpAdaptor =
typename OpTy::Adaptor;
397 matchAndRewrite(OpTy op, OpAdaptor,
398 ConversionPatternRewriter &rewriter)
const override {
399 rewriter.eraseOp(op);
413 target.addIllegalOp<acc::DataOp, acc::EnterDataOp, acc::ExitDataOp,
414 acc::UpdateOp, acc::DeclareEnterOp, acc::DeclareExitOp,
415 acc::GetDevicePtrOp>();
425 converter.addConversion(
426 [](acc::DataBoundsType type) ->
Type {
return type; });
429 DataEntryOpLowering<acc::MapInfoOp>, DataEntryOpLowering<acc::CopyinOp>,
430 DataEntryOpLowering<acc::CreateOp>, DataEntryOpLowering<acc::PresentOp>,
431 DataEntryOpLowering<acc::NoCreateOp>, DataEntryOpLowering<acc::AttachOp>,
432 DataEntryOpLowering<acc::DevicePtrOp>,
433 DataEntryOpLowering<acc::UpdateDeviceOp>,
434 DataEntryOpLowering<acc::PrivateOp>,
435 DataEntryOpLowering<acc::FirstprivateOp>,
436 DataEntryOpLowering<acc::FirstprivateMapInitialOp>,
437 DataEntryOpLowering<acc::DeclareDeviceResidentOp>,
438 DataEntryOpLowering<acc::DeclareLinkOp>,
439 EraseDataClauseOp<acc::CopyoutOp>, EraseDataClauseOp<acc::DeleteOp>,
440 EraseDataClauseOp<acc::DetachOp>, EraseDataClauseOp<acc::UpdateHostOp>,
441 EraseDataClauseOp<acc::DataBoundsOp>>(converter);
442 patterns.
add<GetDevicePtrOpLowering>(converter, accSupport,
443 globalSymbolRegion, symbolTable, config);
450 acc::DeviceType clauseDeviceType) {
451 converter.addConversion([](acc::DeclareTokenType type) ->
Type {
452 return LLVM::LLVMPointerType::get(type.getContext());
455 patterns.
add<DataOpLowering, EnterDataOpLowering, ExitDataOpLowering,
456 UpdateOpLowering>(converter, accSupport, globalSymbolRegion,
457 symbolTable, config, clauseDeviceType);
458 patterns.
add<DeclareEnterOpLowering, DeclareExitOpLowering>(
459 converter, accSupport, globalSymbolRegion, symbolTable, config);
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, ACCDataRegionFlags regionFlags=ACCDataRegionFlags::None)
Emits the call to the mapping entry point fn for mappingOperands, the data-clause operands of a data ...
static DeclareActionAttr getEnclosingDeclareAction(Operation *op)
Returns the action that the declare-action recipe holding op carries out, which the recipe states by ...
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.
ACCDataRegionFlags
Flags of __tgt_acc_data_begin and __tgt_acc_data_end.
@ None
An explicit data construct.
What a data runtime call is asked for besides mapping its operands.