@@ -264,6 +264,43 @@ static llvm::omp::ProcBindKind getProcBindKind(omp::ClauseProcBindKind kind) {
264
264
llvm_unreachable (" Unknown ClauseProcBindKind kind" );
265
265
}
266
266
267
+ // / Converts an OpenMP 'masked' operation into LLVM IR using OpenMPIRBuilder.
268
+ static LogicalResult
269
+ convertOmpMasked (Operation &opInst, llvm::IRBuilderBase &builder,
270
+ LLVM::ModuleTranslation &moduleTranslation) {
271
+ auto maskedOp = cast<omp::MaskedOp>(opInst);
272
+ using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
273
+ // TODO: support error propagation in OpenMPIRBuilder and use it instead of
274
+ // relying on captured variables.
275
+ LogicalResult bodyGenStatus = success ();
276
+
277
+ auto bodyGenCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP) {
278
+ // MaskedOp has only one region associated with it.
279
+ auto ®ion = maskedOp.getRegion ();
280
+ builder.restoreIP (codeGenIP);
281
+ convertOmpOpRegions (region, " omp.masked.region" , builder, moduleTranslation,
282
+ bodyGenStatus);
283
+ };
284
+
285
+ // TODO: Perform finalization actions for variables. This has to be
286
+ // called for variables which have destructors/finalizers.
287
+ auto finiCB = [&](InsertPointTy codeGenIP) {};
288
+
289
+ llvm::Value *filterVal = nullptr ;
290
+ if (auto filterVar = maskedOp.getFilteredThreadId ()) {
291
+ filterVal = moduleTranslation.lookupValue (filterVar);
292
+ } else {
293
+ llvm::LLVMContext &llvmContext = builder.getContext ();
294
+ filterVal =
295
+ llvm::ConstantInt::get (llvm::Type::getInt32Ty (llvmContext), /* V=*/ 0 );
296
+ }
297
+ assert (filterVal != nullptr );
298
+ llvm::OpenMPIRBuilder::LocationDescription ompLoc (builder);
299
+ builder.restoreIP (moduleTranslation.getOpenMPBuilder ()->createMasked (
300
+ ompLoc, bodyGenCB, finiCB, filterVal));
301
+ return success ();
302
+ }
303
+
267
304
// / Converts an OpenMP 'master' operation into LLVM IR using OpenMPIRBuilder.
268
305
static LogicalResult
269
306
convertOmpMaster (Operation &opInst, llvm::IRBuilderBase &builder,
@@ -3414,6 +3451,9 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
3414
3451
.Case ([&](omp::ParallelOp op) {
3415
3452
return convertOmpParallel (op, builder, moduleTranslation);
3416
3453
})
3454
+ .Case ([&](omp::MaskedOp) {
3455
+ return convertOmpMasked (*op, builder, moduleTranslation);
3456
+ })
3417
3457
.Case ([&](omp::MasterOp) {
3418
3458
return convertOmpMaster (*op, builder, moduleTranslation);
3419
3459
})
0 commit comments