Skip to content

Commit bf94aeb

Browse files
committed
handle some review comments
1 parent 0816681 commit bf94aeb

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ static llvm::omp::ProcBindKind getProcBindKind(omp::ClauseProcBindKind kind) {
542542
/// with entry block arguments is converted to LLVM. In this case \p blockArgs
543543
/// are (part of) of the OpenMP region's entry arguments and \p operands are
544544
/// (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+
/// ```
545553
static void forwardArgs(LLVM::ModuleTranslation &moduleTranslation,
546554
llvm::ArrayRef<BlockArgument> blockArgs,
547555
OperandRange operands) {
@@ -5307,21 +5315,17 @@ template <typename OMPOp>
53075315
static void forwardPrivateArgs(OMPOp ompOp,
53085316
LLVM::ModuleTranslation &moduleTranslation) {
53095317
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());
53145320
}
53155321

53165322
/// Forwards reduction entry block arguments, \see forwardArgs for more details.
53175323
template <typename OMPOp>
53185324
static void forwardReductionArgs(OMPOp ompOp,
53195325
LLVM::ModuleTranslation &moduleTranslation) {
53205326
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());
53255329
}
53265330

53275331
static LogicalResult
@@ -5346,8 +5350,8 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
53465350

53475351
// Non-target ops might nest target-related ops, therefore, we
53485352
// 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.
53515355
if (isa<omp::OpenMPDialect>(oper->getDialect()) &&
53525356
oper->getParentOfType<LLVM::LLVMFuncOp>() &&
53535357
!oper->getRegions().empty()) {
@@ -5367,6 +5371,8 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
53675371
});
53685372

53695373
if (auto loopNest = dyn_cast<omp::LoopNestOp>(oper)) {
5374+
assert(builder.GetInsertBlock() &&
5375+
"No insert block is set for the builder");
53705376
for (auto iv : loopNest.getIVs()) {
53715377
// Create fake allocas just to maintain IR validity.
53725378
moduleTranslation.mapValue(
@@ -5376,6 +5382,10 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
53765382
}
53775383

53785384
for (Region &region : 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.
53795389
auto result = convertOmpOpRegions(
53805390
region, oper->getName().getStringRef().str() + ".fake.region",
53815391
builder, moduleTranslation);

0 commit comments

Comments
 (0)