@@ -542,6 +542,13 @@ static llvm::omp::ProcBindKind getProcBindKind(omp::ClauseProcBindKind kind) {
542
542
llvm_unreachable (" Unknown ClauseProcBindKind kind" );
543
543
}
544
544
545
+ static void forwardArgs (LLVM::ModuleTranslation &moduleTranslation,
546
+ llvm::ArrayRef<BlockArgument> blockArgs,
547
+ OperandRange operands) {
548
+ for (auto [arg, var] : llvm::zip_equal (blockArgs, operands))
549
+ moduleTranslation.mapValue (arg, moduleTranslation.lookupValue (var));
550
+ }
551
+
545
552
// / Helper function to map block arguments defined by ignored loop wrappers to
546
553
// / LLVM values and prevent any uses of those from triggering null pointer
547
554
// / dereferences.
@@ -554,18 +561,12 @@ convertIgnoredWrapper(omp::LoopWrapperInterface opInst,
554
561
// Map block arguments directly to the LLVM value associated to the
555
562
// corresponding operand. This is semantically equivalent to this wrapper not
556
563
// being present.
557
- auto forwardArgs =
558
- [&moduleTranslation](llvm::ArrayRef<BlockArgument> blockArgs,
559
- OperandRange operands) {
560
- for (auto [arg, var] : llvm::zip_equal (blockArgs, operands))
561
- moduleTranslation.mapValue (arg, moduleTranslation.lookupValue (var));
562
- };
563
-
564
564
return llvm::TypeSwitch<Operation *, LogicalResult>(opInst)
565
565
.Case ([&](omp::SimdOp op) {
566
566
auto blockArgIface = cast<omp::BlockArgOpenMPOpInterface>(*op);
567
- forwardArgs (blockArgIface.getPrivateBlockArgs (), op.getPrivateVars ());
568
- forwardArgs (blockArgIface.getReductionBlockArgs (),
567
+ forwardArgs (moduleTranslation, blockArgIface.getPrivateBlockArgs (),
568
+ op.getPrivateVars ());
569
+ forwardArgs (moduleTranslation, blockArgIface.getReductionBlockArgs (),
569
570
op.getReductionVars ());
570
571
op.emitWarning () << " simd information on composite construct discarded" ;
571
572
return success ();
@@ -5255,6 +5256,49 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
5255
5256
return WalkResult::interrupt ();
5256
5257
return WalkResult::skip ();
5257
5258
}
5259
+
5260
+ // Non-target ops might nest target-related ops, therefore, we
5261
+ // translate them as non-OpenMP scopes. Translating them is needed by
5262
+ // nested target-related ops since they might LLVM values defined in
5263
+ // their parent non-target ops.
5264
+ if (isa<omp::OpenMPDialect>(oper->getDialect ()) &&
5265
+ oper->getParentOfType <LLVM::LLVMFuncOp>() &&
5266
+ !oper->getRegions ().empty ()) {
5267
+
5268
+ // TODO Handle other ops with entry block args.
5269
+ if (auto wsloop = dyn_cast<omp::WsloopOp>(oper)) {
5270
+ auto blockArgIface = cast<omp::BlockArgOpenMPOpInterface>(oper);
5271
+ if (blockArgIface) {
5272
+ forwardArgs (moduleTranslation,
5273
+ blockArgIface.getPrivateBlockArgs (),
5274
+ wsloop.getPrivateVars ());
5275
+ forwardArgs (moduleTranslation,
5276
+ blockArgIface.getReductionBlockArgs (),
5277
+ wsloop.getReductionVars ());
5278
+ }
5279
+ }
5280
+
5281
+ if (auto loopNest = dyn_cast<omp::LoopNestOp>(oper)) {
5282
+ for (auto iv : loopNest.getIVs ()) {
5283
+ // Create fake allocas just to maintain IR validity.
5284
+ moduleTranslation.mapValue (
5285
+ iv, builder.CreateAlloca (
5286
+ moduleTranslation.convertType (iv.getType ())));
5287
+ }
5288
+ }
5289
+
5290
+ for (Region ®ion : oper->getRegions ()) {
5291
+ auto result = convertOmpOpRegions (
5292
+ region, oper->getName ().getStringRef ().str () + " .fake.region" ,
5293
+ builder, moduleTranslation);
5294
+ if (result.takeError ())
5295
+ return WalkResult::interrupt ();
5296
+ builder.SetInsertPoint (result.get (), result.get ()->end ());
5297
+ }
5298
+
5299
+ return WalkResult::skip ();
5300
+ }
5301
+
5258
5302
return WalkResult::advance ();
5259
5303
}).wasInterrupted ();
5260
5304
return failure (interrupted);
0 commit comments