@@ -36,6 +36,11 @@ using OpenACCIRBuilder = llvm::OpenMPIRBuilder;
36
36
static constexpr uint64_t createFlag = 0 ;
37
37
// / 1 = to/copyin
38
38
static constexpr uint64_t copyinFlag = 1 ;
39
+ // / 2 = from/copyout
40
+ static constexpr uint64_t copyoutFlag = 2 ;
41
+ // / 8 = delete
42
+ static constexpr uint64_t deleteFlag = 8 ;
43
+
39
44
// / Default value for the device id
40
45
static constexpr int64_t defaultDevice = -1 ;
41
46
@@ -57,10 +62,10 @@ static llvm::Constant *createSourceLocStrFromLocation(Location loc,
57
62
}
58
63
59
64
// / Create the location struct from the operation location information.
60
- static llvm::Value *createSourceLocationInfo (acc::EnterDataOp &op ,
61
- OpenACCIRBuilder &builder ) {
62
- auto loc = op. getLoc ();
63
- auto funcOp = op. getOperation () ->getParentOfType <LLVM::LLVMFuncOp>();
65
+ static llvm::Value *createSourceLocationInfo (OpenACCIRBuilder &builder ,
66
+ Operation *op ) {
67
+ auto loc = op-> getLoc ();
68
+ auto funcOp = op->getParentOfType <LLVM::LLVMFuncOp>();
64
69
StringRef funcName = funcOp ? funcOp.getName () : " unknown" ;
65
70
llvm::Constant *locStr =
66
71
createSourceLocStrFromLocation (loc, builder, funcName);
@@ -81,10 +86,16 @@ static llvm::Constant *createMappingInformation(Location loc,
81
86
82
87
// / Return the runtime function used to lower the given operation.
83
88
static llvm::Function *getAssociatedFunction (OpenACCIRBuilder &builder,
84
- Operation &op) {
85
- if (isa<acc::EnterDataOp>(op))
86
- return builder.getOrCreateRuntimeFunctionPtr (
87
- llvm::omp::OMPRTL___tgt_target_data_begin_mapper);
89
+ Operation *op) {
90
+ return llvm::TypeSwitch<Operation *, llvm::Function *>(op)
91
+ .Case ([&](acc::EnterDataOp) {
92
+ return builder.getOrCreateRuntimeFunctionPtr (
93
+ llvm::omp::OMPRTL___tgt_target_data_begin_mapper);
94
+ })
95
+ .Case ([&](acc::ExitDataOp) {
96
+ return builder.getOrCreateRuntimeFunctionPtr (
97
+ llvm::omp::OMPRTL___tgt_target_data_end_mapper);
98
+ });
88
99
llvm_unreachable (" Unknown OpenACC operation" );
89
100
}
90
101
@@ -105,7 +116,7 @@ static llvm::Value *getSizeInBytes(llvm::IRBuilderBase &builder,
105
116
// / to populate the future functions arguments.
106
117
static LogicalResult
107
118
processOperands (llvm::IRBuilderBase &builder,
108
- LLVM::ModuleTranslation &moduleTranslation, Operation & op,
119
+ LLVM::ModuleTranslation &moduleTranslation, Operation * op,
109
120
ValueRange operands, unsigned totalNbOperand,
110
121
uint64_t operandFlag, SmallVector<uint64_t > &flags,
111
122
SmallVector<llvm::Constant *> &names, unsigned &index,
@@ -137,7 +148,7 @@ processOperands(llvm::IRBuilderBase &builder,
137
148
dataPtr = dataValue;
138
149
dataSize = getSizeInBytes (builder, dataValue);
139
150
} else {
140
- return op. emitOpError ()
151
+ return op-> emitOpError ()
141
152
<< " Data operand must be legalized before translation."
142
153
<< " Unsupported type: " << data.getType ();
143
154
}
@@ -171,28 +182,81 @@ processOperands(llvm::IRBuilderBase &builder,
171
182
return success ();
172
183
}
173
184
185
+ // / Process data operands from acc::EnterDataOp
186
+ static LogicalResult
187
+ processDataOperands (llvm::IRBuilderBase &builder,
188
+ LLVM::ModuleTranslation &moduleTranslation,
189
+ acc::EnterDataOp op, SmallVector<uint64_t > &flags,
190
+ SmallVector<llvm::Constant *> &names, unsigned &index,
191
+ llvm::AllocaInst *argsBase, llvm::AllocaInst *args,
192
+ llvm::AllocaInst *argSizes) {
193
+ // TODO add `create_zero` and `attach` operands
194
+
195
+ // Create operands are handled as `alloc` call.
196
+ if (failed (processOperands (builder, moduleTranslation, op,
197
+ op.createOperands (), op.getNumDataOperands (),
198
+ createFlag, flags, names, index, argsBase, args,
199
+ argSizes)))
200
+ return failure ();
201
+
202
+ // Copyin operands are handled as `to` call.
203
+ if (failed (processOperands (builder, moduleTranslation, op,
204
+ op.copyinOperands (), op.getNumDataOperands (),
205
+ copyinFlag, flags, names, index, argsBase, args,
206
+ argSizes)))
207
+ return failure ();
208
+
209
+ return success ();
210
+ }
211
+
212
+ // / Process data operands from acc::ExitDataOp
213
+ static LogicalResult
214
+ processDataOperands (llvm::IRBuilderBase &builder,
215
+ LLVM::ModuleTranslation &moduleTranslation,
216
+ acc::ExitDataOp op, SmallVector<uint64_t > &flags,
217
+ SmallVector<llvm::Constant *> &names, unsigned &index,
218
+ llvm::AllocaInst *argsBase, llvm::AllocaInst *args,
219
+ llvm::AllocaInst *argSizes) {
220
+ // TODO add `detach` operands
221
+
222
+ // Delete operands are handled as `delete` call.
223
+ if (failed (processOperands (builder, moduleTranslation, op,
224
+ op.deleteOperands (), op.getNumDataOperands (),
225
+ deleteFlag, flags, names, index, argsBase, args,
226
+ argSizes)))
227
+ return failure ();
228
+
229
+ // Copyout operands are handled as `from` call.
230
+ if (failed (processOperands (builder, moduleTranslation, op,
231
+ op.copyoutOperands (), op.getNumDataOperands (),
232
+ copyoutFlag, flags, names, index, argsBase, args,
233
+ argSizes)))
234
+ return failure ();
235
+
236
+ return success ();
237
+ }
238
+
174
239
// ===----------------------------------------------------------------------===//
175
240
// Conversion functions
176
241
// ===----------------------------------------------------------------------===//
177
242
178
- // / Converts an OpenACC enter_data operartion into LLVM IR.
243
+ // / Converts an OpenACC standalone data operation into LLVM IR.
244
+ template <typename OpTy>
179
245
static LogicalResult
180
- convertEnterDataOp (Operation &op, llvm::IRBuilderBase &builder,
181
- LLVM::ModuleTranslation &moduleTranslation) {
182
- auto enterDataOp = cast<acc::EnterDataOp>(op);
183
- auto enclosingFuncOp = op.getParentOfType <LLVM::LLVMFuncOp>();
246
+ convertStandaloneDataOp (OpTy &op, llvm::IRBuilderBase &builder,
247
+ LLVM::ModuleTranslation &moduleTranslation) {
248
+ auto enclosingFuncOp =
249
+ op.getOperation ()-> template getParentOfType <LLVM::LLVMFuncOp>();
184
250
llvm::Function *enclosingFunction =
185
251
moduleTranslation.lookupFunction (enclosingFuncOp.getName ());
186
252
187
253
OpenACCIRBuilder *accBuilder = moduleTranslation.getOpenMPBuilder ();
188
254
189
- auto *srcLocInfo = createSourceLocationInfo (enterDataOp, *accBuilder);
255
+ auto *srcLocInfo = createSourceLocationInfo (*accBuilder, op );
190
256
auto *mapperFunc = getAssociatedFunction (*accBuilder, op);
191
257
192
258
// Number of arguments in the enter_data operation.
193
- // TODO include create_zero and attach operands.
194
- unsigned totalNbOperand =
195
- enterDataOp.createOperands ().size () + enterDataOp.copyinOperands ().size ();
259
+ unsigned totalNbOperand = op.getNumDataOperands ();
196
260
197
261
// TODO could be moved to OpenXXIRBuilder?
198
262
llvm::LLVMContext &ctx = builder.getContext ();
@@ -214,18 +278,8 @@ convertEnterDataOp(Operation &op, llvm::IRBuilderBase &builder,
214
278
SmallVector<llvm::Constant *> names;
215
279
unsigned index = 0 ;
216
280
217
- // Create operands are handled as `alloc` call.
218
- if (failed (processOperands (builder, moduleTranslation, op,
219
- enterDataOp.createOperands (), totalNbOperand,
220
- createFlag, flags, names, index, argsBase, args,
221
- argSizes)))
222
- return failure ();
223
-
224
- // Copyin operands are handled as `to` call.
225
- if (failed (processOperands (builder, moduleTranslation, op,
226
- enterDataOp.copyinOperands (), totalNbOperand,
227
- copyinFlag, flags, names, index, argsBase, args,
228
- argSizes)))
281
+ if (failed (processDataOperands (builder, moduleTranslation, op, flags, names,
282
+ index, argsBase, args, argSizes)))
229
283
return failure ();
230
284
231
285
llvm::GlobalVariable *maptypes =
@@ -282,8 +336,13 @@ LogicalResult OpenACCDialectLLVMIRTranslationInterface::convertOperation(
282
336
LLVM::ModuleTranslation &moduleTranslation) const {
283
337
284
338
return llvm::TypeSwitch<Operation *, LogicalResult>(op)
285
- .Case ([&](acc::EnterDataOp) {
286
- return convertEnterDataOp (*op, builder, moduleTranslation);
339
+ .Case ([&](acc::EnterDataOp enterDataOp) {
340
+ return convertStandaloneDataOp<acc::EnterDataOp>(enterDataOp, builder,
341
+ moduleTranslation);
342
+ })
343
+ .Case ([&](acc::ExitDataOp exitDataOp) {
344
+ return convertStandaloneDataOp<acc::ExitDataOp>(exitDataOp, builder,
345
+ moduleTranslation);
287
346
})
288
347
.Default ([&](Operation *op) {
289
348
return op->emitError (" unsupported OpenACC operation: " )
0 commit comments