Skip to content

Commit dac2419

Browse files
author
Razvan Lupusoru
committed
[mlir][acc] Improve acc.loop support as a container
Dialects which have their own loop representation not representable with numeric bounds + steps cannot be represented cleanly with acc.loop. In such a case, we permit the dialects representation with acc.loop merely encompasing its loop representation. This limitation became obvious when looking at range / random iterator C++ loops. The API of acc.loop was updated to test for this differentiation. Additionally, the verifier was updated to check for consistent bounds and whether inner-loops are contained when it works as a container.
1 parent a24457e commit dac2419

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,11 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
21272127
/// Used to retrieve the block inside the op's region.
21282128
Block &getBody() { return getLoopRegions().front()->front(); }
21292129

2130+
/// Used to determine if this operation is merely a container for a loop
2131+
/// operation instead of being loop-like itself.
2132+
bool isLoopLike() { return !getLowerbound().empty(); }
2133+
bool isContainerLike() { return !isLoopLike(); }
2134+
21302135
/// Return true if the op has the auto attribute for the
21312136
/// mlir::acc::DeviceType::None device_type.
21322137
bool hasAuto();

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,6 +2298,14 @@ LogicalResult checkDeviceTypes(mlir::ArrayAttr deviceTypes) {
22982298
}
22992299

23002300
LogicalResult acc::LoopOp::verify() {
2301+
if (getUpperbound().size() != getStep().size())
2302+
return emitError() << "number of upperbounds expected to be the same as "
2303+
"number of steps";
2304+
2305+
if (getUpperbound().size() != getLowerbound().size())
2306+
return emitError() << "number of upperbounds expected to be the same as "
2307+
"number of lowerbounds";
2308+
23012309
if (!getUpperbound().empty() && getInclusiveUpperbound() &&
23022310
(getUpperbound().size() != getInclusiveUpperbound()->size()))
23032311
return emitError() << "inclusiveUpperbound size is expected to be the same"
@@ -2415,6 +2423,15 @@ LogicalResult acc::LoopOp::verify() {
24152423
if (getRegion().empty())
24162424
return emitError("expected non-empty body.");
24172425

2426+
// When it is container-like - it is expected to hold a loop-like operation.
2427+
// TODO: Get the collapse attribute into account.
2428+
if (isContainerLike()) {
2429+
// TODO: Ensure there is a single loop-like operation at any one level.
2430+
auto loopLikeOps = getRegion().getOps<LoopLikeOpInterface>();
2431+
if (loopLikeOps.empty())
2432+
return emitError("expected to hold a loop-like operation.");
2433+
}
2434+
24182435
return success();
24192436
}
24202437

0 commit comments

Comments
 (0)