@@ -542,6 +542,14 @@ static llvm::omp::ProcBindKind getProcBindKind(omp::ClauseProcBindKind kind) {
542
542
// / with entry block arguments is converted to LLVM. In this case \p blockArgs
543
543
// / are (part of) of the OpenMP region's entry arguments and \p operands are
544
544
// / (part of) of the operands to the OpenMP op containing the region.
545
+ // /
546
+ // / This function assumes that \p operands belong to the enclosing op of the
547
+ // / block containing \p blockArgs:
548
+ // / ```
549
+ // / enclosing_op(operands) {
550
+ // / block(blockArgs)
551
+ // / }
552
+ // / ```
545
553
static void forwardArgs (LLVM::ModuleTranslation &moduleTranslation,
546
554
llvm::ArrayRef<BlockArgument> blockArgs,
547
555
OperandRange operands) {
@@ -5307,21 +5315,17 @@ template <typename OMPOp>
5307
5315
static void forwardPrivateArgs (OMPOp ompOp,
5308
5316
LLVM::ModuleTranslation &moduleTranslation) {
5309
5317
auto blockArgIface = cast<omp::BlockArgOpenMPOpInterface>(*ompOp);
5310
- if (blockArgIface) {
5311
- forwardArgs (moduleTranslation, blockArgIface.getPrivateBlockArgs (),
5312
- ompOp.getPrivateVars ());
5313
- }
5318
+ forwardArgs (moduleTranslation, blockArgIface.getPrivateBlockArgs (),
5319
+ ompOp.getPrivateVars ());
5314
5320
}
5315
5321
5316
5322
// / Forwards reduction entry block arguments, \see forwardArgs for more details.
5317
5323
template <typename OMPOp>
5318
5324
static void forwardReductionArgs (OMPOp ompOp,
5319
5325
LLVM::ModuleTranslation &moduleTranslation) {
5320
5326
auto blockArgIface = cast<omp::BlockArgOpenMPOpInterface>(*ompOp);
5321
- if (blockArgIface) {
5322
- forwardArgs (moduleTranslation, blockArgIface.getReductionBlockArgs (),
5323
- ompOp.getReductionVars ());
5324
- }
5327
+ forwardArgs (moduleTranslation, blockArgIface.getReductionBlockArgs (),
5328
+ ompOp.getReductionVars ());
5325
5329
}
5326
5330
5327
5331
static LogicalResult
@@ -5346,8 +5350,8 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
5346
5350
5347
5351
// Non-target ops might nest target-related ops, therefore, we
5348
5352
// translate them as non-OpenMP scopes. Translating them is needed by
5349
- // nested target-related ops since they might LLVM values defined in
5350
- // their parent non-target ops.
5353
+ // nested target-related ops since they might need LLVM values defined
5354
+ // in their parent non-target ops.
5351
5355
if (isa<omp::OpenMPDialect>(oper->getDialect ()) &&
5352
5356
oper->getParentOfType <LLVM::LLVMFuncOp>() &&
5353
5357
!oper->getRegions ().empty ()) {
@@ -5367,6 +5371,8 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
5367
5371
});
5368
5372
5369
5373
if (auto loopNest = dyn_cast<omp::LoopNestOp>(oper)) {
5374
+ assert (builder.GetInsertBlock () &&
5375
+ " No insert block is set for the builder" );
5370
5376
for (auto iv : loopNest.getIVs ()) {
5371
5377
// Create fake allocas just to maintain IR validity.
5372
5378
moduleTranslation.mapValue (
@@ -5376,6 +5382,10 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
5376
5382
}
5377
5383
5378
5384
for (Region ®ion : oper->getRegions ()) {
5385
+ // Regions are fake in the sense that they are not a truthful
5386
+ // translation of the OpenMP construct being converted (e.g. no
5387
+ // OpenMP runtime calls will be generated). We just need this to
5388
+ // prepare the kernel invocation args.
5379
5389
auto result = convertOmpOpRegions (
5380
5390
region, oper->getName ().getStringRef ().str () + " .fake.region" ,
5381
5391
builder, moduleTranslation);
0 commit comments