Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,11 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
/// Used to retrieve the block inside the op's region.
Block &getBody() { return getLoopRegions().front()->front(); }

/// Used to determine if this operation is merely a container for a loop
/// operation instead of being loop-like itself.
bool isLoopLike() { return !getLowerbound().empty(); }
bool isContainerLike() { return !isLoopLike(); }

/// Return true if the op has the auto attribute for the
/// mlir::acc::DeviceType::None device_type.
bool hasAuto();
Expand Down Expand Up @@ -2197,7 +2202,7 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",

let hasCustomAssemblyFormat = 1;
let assemblyFormat = [{
custom<CombinedConstructsLoop>($combined)
( `combined` `(` custom<CombinedConstructsLoop>($combined)^ `)` )?
oilist(
`gang` `` custom<GangClause>($gangOperands, type($gangOperands),
$gangOperandsArgType, $gangOperandsDeviceType,
Expand Down
55 changes: 33 additions & 22 deletions mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,25 +1686,19 @@ static void printDeviceTypeOperandsWithKeywordOnly(
static ParseResult
parseCombinedConstructsLoop(mlir::OpAsmParser &parser,
mlir::acc::CombinedConstructsTypeAttr &attr) {
if (succeeded(parser.parseOptionalKeyword("combined"))) {
if (parser.parseLParen())
return failure();
if (succeeded(parser.parseOptionalKeyword("kernels"))) {
attr = mlir::acc::CombinedConstructsTypeAttr::get(
parser.getContext(), mlir::acc::CombinedConstructsType::KernelsLoop);
} else if (succeeded(parser.parseOptionalKeyword("parallel"))) {
attr = mlir::acc::CombinedConstructsTypeAttr::get(
parser.getContext(), mlir::acc::CombinedConstructsType::ParallelLoop);
} else if (succeeded(parser.parseOptionalKeyword("serial"))) {
attr = mlir::acc::CombinedConstructsTypeAttr::get(
parser.getContext(), mlir::acc::CombinedConstructsType::SerialLoop);
} else {
parser.emitError(parser.getCurrentLocation(),
"expected compute construct name");
return failure();
}
if (parser.parseRParen())
return failure();
if (succeeded(parser.parseOptionalKeyword("kernels"))) {
attr = mlir::acc::CombinedConstructsTypeAttr::get(
parser.getContext(), mlir::acc::CombinedConstructsType::KernelsLoop);
} else if (succeeded(parser.parseOptionalKeyword("parallel"))) {
attr = mlir::acc::CombinedConstructsTypeAttr::get(
parser.getContext(), mlir::acc::CombinedConstructsType::ParallelLoop);
} else if (succeeded(parser.parseOptionalKeyword("serial"))) {
attr = mlir::acc::CombinedConstructsTypeAttr::get(
parser.getContext(), mlir::acc::CombinedConstructsType::SerialLoop);
} else {
parser.emitError(parser.getCurrentLocation(),
"expected compute construct name");
return failure();
}
return success();
}
Expand All @@ -1715,13 +1709,13 @@ printCombinedConstructsLoop(mlir::OpAsmPrinter &p, mlir::Operation *op,
if (attr) {
switch (attr.getValue()) {
case mlir::acc::CombinedConstructsType::KernelsLoop:
p << "combined(kernels)";
p << "kernels";
break;
case mlir::acc::CombinedConstructsType::ParallelLoop:
p << "combined(parallel)";
p << "parallel";
break;
case mlir::acc::CombinedConstructsType::SerialLoop:
p << "combined(serial)";
p << "serial";
break;
};
}
Expand Down Expand Up @@ -2304,6 +2298,14 @@ LogicalResult checkDeviceTypes(mlir::ArrayAttr deviceTypes) {
}

LogicalResult acc::LoopOp::verify() {
if (getUpperbound().size() != getStep().size())
return emitError() << "number of upperbounds expected to be the same as "
"number of steps";

if (getUpperbound().size() != getLowerbound().size())
return emitError() << "number of upperbounds expected to be the same as "
"number of lowerbounds";

if (!getUpperbound().empty() && getInclusiveUpperbound() &&
(getUpperbound().size() != getInclusiveUpperbound()->size()))
return emitError() << "inclusiveUpperbound size is expected to be the same"
Expand Down Expand Up @@ -2421,6 +2423,15 @@ LogicalResult acc::LoopOp::verify() {
if (getRegion().empty())
return emitError("expected non-empty body.");

// When it is container-like - it is expected to hold a loop-like operation.
// TODO: Get the collapse attribute into account.
if (isContainerLike()) {
// TODO: Ensure there is a single loop-like operation at any one level.
auto loopLikeOps = getRegion().getOps<LoopLikeOpInterface>();
if (loopLikeOps.empty())
return emitError("expected to hold a loop-like operation.");
}

return success();
}

Expand Down
Loading