2020-08-12 23:48:24 +08:00
|
|
|
//===- OpenACC.cpp - OpenACC MLIR Operations ------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
#include "mlir/Dialect/OpenACC/OpenACC.h"
|
|
|
|
#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.cpp.inc"
|
|
|
|
#include "mlir/IR/Builders.h"
|
2020-12-04 09:22:29 +08:00
|
|
|
#include "mlir/IR/BuiltinTypes.h"
|
2020-08-12 23:48:24 +08:00
|
|
|
#include "mlir/IR/OpImplementation.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
using namespace acc;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OpenACC operations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void OpenACCDialect::initialize() {
|
|
|
|
addOperations<
|
|
|
|
#define GET_OP_LIST
|
|
|
|
#include "mlir/Dialect/OpenACC/OpenACCOps.cpp.inc"
|
|
|
|
>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename StructureOp>
|
|
|
|
static ParseResult parseRegions(OpAsmParser &parser, OperationState &state,
|
|
|
|
unsigned nRegions = 1) {
|
|
|
|
|
|
|
|
SmallVector<Region *, 2> regions;
|
|
|
|
for (unsigned i = 0; i < nRegions; ++i)
|
|
|
|
regions.push_back(state.addRegion());
|
|
|
|
|
|
|
|
for (Region *region : regions) {
|
|
|
|
if (parser.parseRegion(*region, /*arguments=*/{}, /*argTypes=*/{}))
|
|
|
|
return failure();
|
|
|
|
}
|
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
static ParseResult
|
|
|
|
parseOperandList(OpAsmParser &parser, StringRef keyword,
|
|
|
|
SmallVectorImpl<OpAsmParser::OperandType> &args,
|
|
|
|
SmallVectorImpl<Type> &argTypes, OperationState &result) {
|
|
|
|
if (failed(parser.parseOptionalKeyword(keyword)))
|
|
|
|
return success();
|
|
|
|
|
|
|
|
if (failed(parser.parseLParen()))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
// Exit early if the list is empty.
|
|
|
|
if (succeeded(parser.parseOptionalRParen()))
|
|
|
|
return success();
|
|
|
|
|
|
|
|
do {
|
|
|
|
OpAsmParser::OperandType arg;
|
|
|
|
Type type;
|
|
|
|
|
|
|
|
if (parser.parseRegionArgument(arg) || parser.parseColonType(type))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
args.push_back(arg);
|
|
|
|
argTypes.push_back(type);
|
|
|
|
} while (succeeded(parser.parseOptionalComma()));
|
|
|
|
|
|
|
|
if (failed(parser.parseRParen()))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
return parser.resolveOperands(args, argTypes, parser.getCurrentLocation(),
|
|
|
|
result.operands);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printOperandList(Operation::operand_range operands,
|
|
|
|
StringRef listName, OpAsmPrinter &printer) {
|
|
|
|
|
|
|
|
if (operands.size() > 0) {
|
|
|
|
printer << " " << listName << "(";
|
|
|
|
llvm::interleaveComma(operands, printer, [&](Value op) {
|
|
|
|
printer << op << ": " << op.getType();
|
|
|
|
});
|
|
|
|
printer << ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ParseResult parseOptionalOperand(OpAsmParser &parser, StringRef keyword,
|
|
|
|
OpAsmParser::OperandType &operand,
|
|
|
|
Type type, bool &hasOptional,
|
|
|
|
OperationState &result) {
|
|
|
|
hasOptional = false;
|
|
|
|
if (succeeded(parser.parseOptionalKeyword(keyword))) {
|
|
|
|
hasOptional = true;
|
|
|
|
if (parser.parseLParen() || parser.parseOperand(operand) ||
|
|
|
|
parser.resolveOperand(operand, type, result.operands) ||
|
|
|
|
parser.parseRParen())
|
|
|
|
return failure();
|
|
|
|
}
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2020-09-23 22:26:09 +08:00
|
|
|
static ParseResult parseOperandAndType(OpAsmParser &parser,
|
|
|
|
OperationState &result) {
|
|
|
|
OpAsmParser::OperandType operand;
|
|
|
|
Type type;
|
|
|
|
if (parser.parseOperand(operand) || parser.parseColonType(type) ||
|
|
|
|
parser.resolveOperand(operand, type, result.operands))
|
|
|
|
return failure();
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Parse optional operand and its type wrapped in parenthesis prefixed with
|
|
|
|
/// a keyword.
|
|
|
|
/// Example:
|
|
|
|
/// keyword `(` %vectorLength: i64 `)`
|
2020-09-17 23:33:31 +08:00
|
|
|
static OptionalParseResult parseOptionalOperandAndType(OpAsmParser &parser,
|
|
|
|
StringRef keyword,
|
|
|
|
OperationState &result) {
|
|
|
|
OpAsmParser::OperandType operand;
|
|
|
|
if (succeeded(parser.parseOptionalKeyword(keyword))) {
|
2020-09-23 22:26:09 +08:00
|
|
|
return failure(parser.parseLParen() ||
|
|
|
|
parseOperandAndType(parser, result) || parser.parseRParen());
|
|
|
|
}
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Parse optional operand and its type wrapped in parenthesis.
|
|
|
|
/// Example:
|
|
|
|
/// `(` %vectorLength: i64 `)`
|
|
|
|
static OptionalParseResult parseOptionalOperandAndType(OpAsmParser &parser,
|
|
|
|
OperationState &result) {
|
|
|
|
if (succeeded(parser.parseOptionalLParen())) {
|
|
|
|
return failure(parseOperandAndType(parser, result) || parser.parseRParen());
|
|
|
|
}
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Parse optional operand with its type prefixed with prefixKeyword `=`.
|
|
|
|
/// Example:
|
|
|
|
/// num=%gangNum: i32
|
|
|
|
static OptionalParseResult parserOptionalOperandAndTypeWithPrefix(
|
|
|
|
OpAsmParser &parser, OperationState &result, StringRef prefixKeyword) {
|
|
|
|
if (succeeded(parser.parseOptionalKeyword(prefixKeyword))) {
|
|
|
|
parser.parseEqual();
|
|
|
|
return parseOperandAndType(parser, result);
|
2020-09-17 23:33:31 +08:00
|
|
|
}
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
2020-09-30 01:12:54 +08:00
|
|
|
static bool isComputeOperation(Operation *op) {
|
|
|
|
return isa<acc::ParallelOp>(op) || isa<acc::LoopOp>(op);
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:48:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ParallelOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Parse acc.parallel operation
|
|
|
|
/// operation := `acc.parallel` `async` `(` index `)`?
|
|
|
|
/// `wait` `(` index-list `)`?
|
|
|
|
/// `num_gangs` `(` value `)`?
|
|
|
|
/// `num_workers` `(` value `)`?
|
|
|
|
/// `vector_length` `(` value `)`?
|
|
|
|
/// `if` `(` value `)`?
|
|
|
|
/// `self` `(` value `)`?
|
|
|
|
/// `reduction` `(` value-list `)`?
|
|
|
|
/// `copy` `(` value-list `)`?
|
|
|
|
/// `copyin` `(` value-list `)`?
|
2020-09-16 22:48:51 +08:00
|
|
|
/// `copyin_readonly` `(` value-list `)`?
|
2020-08-12 23:48:24 +08:00
|
|
|
/// `copyout` `(` value-list `)`?
|
2020-09-16 22:48:51 +08:00
|
|
|
/// `copyout_zero` `(` value-list `)`?
|
2020-08-12 23:48:24 +08:00
|
|
|
/// `create` `(` value-list `)`?
|
2020-09-16 22:48:51 +08:00
|
|
|
/// `create_zero` `(` value-list `)`?
|
2020-08-12 23:48:24 +08:00
|
|
|
/// `no_create` `(` value-list `)`?
|
|
|
|
/// `present` `(` value-list `)`?
|
|
|
|
/// `deviceptr` `(` value-list `)`?
|
|
|
|
/// `attach` `(` value-list `)`?
|
|
|
|
/// `private` `(` value-list `)`?
|
|
|
|
/// `firstprivate` `(` value-list `)`?
|
|
|
|
/// region attr-dict?
|
|
|
|
static ParseResult parseParallelOp(OpAsmParser &parser,
|
|
|
|
OperationState &result) {
|
|
|
|
Builder &builder = parser.getBuilder();
|
|
|
|
SmallVector<OpAsmParser::OperandType, 8> privateOperands,
|
2020-09-16 22:48:51 +08:00
|
|
|
firstprivateOperands, copyOperands, copyinOperands,
|
|
|
|
copyinReadonlyOperands, copyoutOperands, copyoutZeroOperands,
|
|
|
|
createOperands, createZeroOperands, noCreateOperands, presentOperands,
|
|
|
|
devicePtrOperands, attachOperands, waitOperands, reductionOperands;
|
|
|
|
SmallVector<Type, 8> waitOperandTypes, reductionOperandTypes,
|
|
|
|
copyOperandTypes, copyinOperandTypes, copyinReadonlyOperandTypes,
|
|
|
|
copyoutOperandTypes, copyoutZeroOperandTypes, createOperandTypes,
|
|
|
|
createZeroOperandTypes, noCreateOperandTypes, presentOperandTypes,
|
|
|
|
deviceptrOperandTypes, attachOperandTypes, privateOperandTypes,
|
|
|
|
firstprivateOperandTypes;
|
2020-08-12 23:48:24 +08:00
|
|
|
|
2020-09-17 23:33:31 +08:00
|
|
|
SmallVector<Type, 8> operandTypes;
|
|
|
|
OpAsmParser::OperandType ifCond, selfCond;
|
|
|
|
bool hasIfCond = false, hasSelfCond = false;
|
|
|
|
OptionalParseResult async, numGangs, numWorkers, vectorLength;
|
2020-08-12 23:48:24 +08:00
|
|
|
Type i1Type = builder.getI1Type();
|
|
|
|
|
|
|
|
// async()?
|
2020-09-17 23:33:31 +08:00
|
|
|
async = parseOptionalOperandAndType(parser, ParallelOp::getAsyncKeyword(),
|
|
|
|
result);
|
|
|
|
if (async.hasValue() && failed(*async))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// wait()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getWaitKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
waitOperands, waitOperandTypes, result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// num_gangs(value)?
|
2020-09-17 23:33:31 +08:00
|
|
|
numGangs = parseOptionalOperandAndType(
|
|
|
|
parser, ParallelOp::getNumGangsKeyword(), result);
|
|
|
|
if (numGangs.hasValue() && failed(*numGangs))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// num_workers(value)?
|
2020-09-17 23:33:31 +08:00
|
|
|
numWorkers = parseOptionalOperandAndType(
|
|
|
|
parser, ParallelOp::getNumWorkersKeyword(), result);
|
|
|
|
if (numWorkers.hasValue() && failed(*numWorkers))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// vector_length(value)?
|
2020-09-17 23:33:31 +08:00
|
|
|
vectorLength = parseOptionalOperandAndType(
|
|
|
|
parser, ParallelOp::getVectorLengthKeyword(), result);
|
|
|
|
if (vectorLength.hasValue() && failed(*vectorLength))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// if()?
|
|
|
|
if (failed(parseOptionalOperand(parser, ParallelOp::getIfKeyword(), ifCond,
|
|
|
|
i1Type, hasIfCond, result)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
// self()?
|
|
|
|
if (failed(parseOptionalOperand(parser, ParallelOp::getSelfKeyword(),
|
|
|
|
selfCond, i1Type, hasSelfCond, result)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
// reduction()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getReductionKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
reductionOperands, reductionOperandTypes,
|
|
|
|
result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// copy()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getCopyKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
copyOperands, copyOperandTypes, result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// copyin()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getCopyinKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
copyinOperands, copyinOperandTypes, result)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
// copyin_readonly()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getCopyinReadonlyKeyword(),
|
|
|
|
copyinReadonlyOperands,
|
|
|
|
copyinReadonlyOperandTypes, result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// copyout()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getCopyoutKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
copyoutOperands, copyoutOperandTypes, result)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
// copyout_zero()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getCopyoutZeroKeyword(),
|
|
|
|
copyoutZeroOperands, copyoutZeroOperandTypes,
|
|
|
|
result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// create()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getCreateKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
createOperands, createOperandTypes, result)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
// create_zero()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getCreateZeroKeyword(),
|
|
|
|
createZeroOperands, createZeroOperandTypes,
|
|
|
|
result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// no_create()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getNoCreateKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
noCreateOperands, noCreateOperandTypes, result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// present()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getPresentKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
presentOperands, presentOperandTypes, result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// deviceptr()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getDevicePtrKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
devicePtrOperands, deviceptrOperandTypes,
|
|
|
|
result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// attach()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getAttachKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
attachOperands, attachOperandTypes, result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// private()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getPrivateKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
privateOperands, privateOperandTypes, result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// firstprivate()?
|
|
|
|
if (failed(parseOperandList(parser, ParallelOp::getFirstPrivateKeyword(),
|
2020-09-16 22:48:51 +08:00
|
|
|
firstprivateOperands, firstprivateOperandTypes,
|
|
|
|
result)))
|
2020-08-12 23:48:24 +08:00
|
|
|
return failure();
|
|
|
|
|
|
|
|
// Parallel op region
|
|
|
|
if (failed(parseRegions<ParallelOp>(parser, result)))
|
|
|
|
return failure();
|
|
|
|
|
2020-09-17 23:33:31 +08:00
|
|
|
result.addAttribute(
|
|
|
|
ParallelOp::getOperandSegmentSizeAttr(),
|
|
|
|
builder.getI32VectorAttr(
|
|
|
|
{static_cast<int32_t>(async.hasValue() ? 1 : 0),
|
|
|
|
static_cast<int32_t>(waitOperands.size()),
|
|
|
|
static_cast<int32_t>(numGangs.hasValue() ? 1 : 0),
|
|
|
|
static_cast<int32_t>(numWorkers.hasValue() ? 1 : 0),
|
|
|
|
static_cast<int32_t>(vectorLength.hasValue() ? 1 : 0),
|
|
|
|
static_cast<int32_t>(hasIfCond ? 1 : 0),
|
|
|
|
static_cast<int32_t>(hasSelfCond ? 1 : 0),
|
|
|
|
static_cast<int32_t>(reductionOperands.size()),
|
|
|
|
static_cast<int32_t>(copyOperands.size()),
|
|
|
|
static_cast<int32_t>(copyinOperands.size()),
|
|
|
|
static_cast<int32_t>(copyinReadonlyOperands.size()),
|
|
|
|
static_cast<int32_t>(copyoutOperands.size()),
|
|
|
|
static_cast<int32_t>(copyoutZeroOperands.size()),
|
|
|
|
static_cast<int32_t>(createOperands.size()),
|
|
|
|
static_cast<int32_t>(createZeroOperands.size()),
|
|
|
|
static_cast<int32_t>(noCreateOperands.size()),
|
|
|
|
static_cast<int32_t>(presentOperands.size()),
|
|
|
|
static_cast<int32_t>(devicePtrOperands.size()),
|
|
|
|
static_cast<int32_t>(attachOperands.size()),
|
|
|
|
static_cast<int32_t>(privateOperands.size()),
|
|
|
|
static_cast<int32_t>(firstprivateOperands.size())}));
|
2020-08-12 23:48:24 +08:00
|
|
|
|
|
|
|
// Additional attributes
|
|
|
|
if (failed(parser.parseOptionalAttrDictWithKeyword(result.attributes)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print(OpAsmPrinter &printer, ParallelOp &op) {
|
|
|
|
printer << ParallelOp::getOperationName();
|
|
|
|
|
|
|
|
// async()?
|
2020-09-15 21:48:24 +08:00
|
|
|
if (Value async = op.async())
|
2020-09-17 23:33:31 +08:00
|
|
|
printer << " " << ParallelOp::getAsyncKeyword() << "(" << async << ": "
|
|
|
|
<< async.getType() << ")";
|
2020-08-12 23:48:24 +08:00
|
|
|
|
|
|
|
// wait()?
|
|
|
|
printOperandList(op.waitOperands(), ParallelOp::getWaitKeyword(), printer);
|
|
|
|
|
|
|
|
// num_gangs()?
|
2020-09-15 21:48:24 +08:00
|
|
|
if (Value numGangs = op.numGangs())
|
2020-08-12 23:48:24 +08:00
|
|
|
printer << " " << ParallelOp::getNumGangsKeyword() << "(" << numGangs
|
2020-09-17 23:33:31 +08:00
|
|
|
<< ": " << numGangs.getType() << ")";
|
2020-08-12 23:48:24 +08:00
|
|
|
|
|
|
|
// num_workers()?
|
2020-09-15 21:48:24 +08:00
|
|
|
if (Value numWorkers = op.numWorkers())
|
2020-08-12 23:48:24 +08:00
|
|
|
printer << " " << ParallelOp::getNumWorkersKeyword() << "(" << numWorkers
|
2020-09-17 23:33:31 +08:00
|
|
|
<< ": " << numWorkers.getType() << ")";
|
2020-08-12 23:48:24 +08:00
|
|
|
|
2020-09-15 21:48:24 +08:00
|
|
|
// vector_length()?
|
|
|
|
if (Value vectorLength = op.vectorLength())
|
|
|
|
printer << " " << ParallelOp::getVectorLengthKeyword() << "("
|
2020-09-17 23:33:31 +08:00
|
|
|
<< vectorLength << ": " << vectorLength.getType() << ")";
|
2020-09-15 21:48:24 +08:00
|
|
|
|
2020-08-12 23:48:24 +08:00
|
|
|
// if()?
|
|
|
|
if (Value ifCond = op.ifCond())
|
|
|
|
printer << " " << ParallelOp::getIfKeyword() << "(" << ifCond << ")";
|
|
|
|
|
|
|
|
// self()?
|
|
|
|
if (Value selfCond = op.selfCond())
|
|
|
|
printer << " " << ParallelOp::getSelfKeyword() << "(" << selfCond << ")";
|
|
|
|
|
|
|
|
// reduction()?
|
|
|
|
printOperandList(op.reductionOperands(), ParallelOp::getReductionKeyword(),
|
|
|
|
printer);
|
|
|
|
|
|
|
|
// copy()?
|
|
|
|
printOperandList(op.copyOperands(), ParallelOp::getCopyKeyword(), printer);
|
|
|
|
|
|
|
|
// copyin()?
|
|
|
|
printOperandList(op.copyinOperands(), ParallelOp::getCopyinKeyword(),
|
|
|
|
printer);
|
|
|
|
|
2020-09-16 22:48:51 +08:00
|
|
|
// copyin_readonly()?
|
|
|
|
printOperandList(op.copyinReadonlyOperands(),
|
|
|
|
ParallelOp::getCopyinReadonlyKeyword(), printer);
|
|
|
|
|
2020-08-12 23:48:24 +08:00
|
|
|
// copyout()?
|
|
|
|
printOperandList(op.copyoutOperands(), ParallelOp::getCopyoutKeyword(),
|
|
|
|
printer);
|
|
|
|
|
2020-09-16 22:48:51 +08:00
|
|
|
// copyout_zero()?
|
|
|
|
printOperandList(op.copyoutZeroOperands(),
|
|
|
|
ParallelOp::getCopyoutZeroKeyword(), printer);
|
|
|
|
|
2020-08-12 23:48:24 +08:00
|
|
|
// create()?
|
|
|
|
printOperandList(op.createOperands(), ParallelOp::getCreateKeyword(),
|
|
|
|
printer);
|
|
|
|
|
2020-09-16 22:48:51 +08:00
|
|
|
// create_zero()?
|
|
|
|
printOperandList(op.createZeroOperands(), ParallelOp::getCreateZeroKeyword(),
|
|
|
|
printer);
|
|
|
|
|
2020-08-12 23:48:24 +08:00
|
|
|
// no_create()?
|
|
|
|
printOperandList(op.noCreateOperands(), ParallelOp::getNoCreateKeyword(),
|
|
|
|
printer);
|
|
|
|
|
|
|
|
// present()?
|
|
|
|
printOperandList(op.presentOperands(), ParallelOp::getPresentKeyword(),
|
|
|
|
printer);
|
|
|
|
|
|
|
|
// deviceptr()?
|
|
|
|
printOperandList(op.devicePtrOperands(), ParallelOp::getDevicePtrKeyword(),
|
|
|
|
printer);
|
|
|
|
|
|
|
|
// attach()?
|
|
|
|
printOperandList(op.attachOperands(), ParallelOp::getAttachKeyword(),
|
|
|
|
printer);
|
|
|
|
|
|
|
|
// private()?
|
|
|
|
printOperandList(op.gangPrivateOperands(), ParallelOp::getPrivateKeyword(),
|
|
|
|
printer);
|
|
|
|
|
|
|
|
// firstprivate()?
|
|
|
|
printOperandList(op.gangFirstPrivateOperands(),
|
|
|
|
ParallelOp::getFirstPrivateKeyword(), printer);
|
|
|
|
|
|
|
|
printer.printRegion(op.region(),
|
|
|
|
/*printEntryBlockArgs=*/false,
|
|
|
|
/*printBlockTerminators=*/true);
|
|
|
|
printer.printOptionalAttrDictWithKeyword(
|
2021-02-26 02:35:53 +08:00
|
|
|
op->getAttrs(), ParallelOp::getOperandSegmentSizeAttr());
|
2020-08-12 23:48:24 +08:00
|
|
|
}
|
|
|
|
|
2021-06-07 23:21:51 +08:00
|
|
|
unsigned ParallelOp::getNumDataOperands() {
|
|
|
|
return reductionOperands().size() + copyOperands().size() +
|
|
|
|
copyinOperands().size() + copyinReadonlyOperands().size() +
|
|
|
|
copyoutOperands().size() + copyoutZeroOperands().size() +
|
|
|
|
createOperands().size() + createZeroOperands().size() +
|
|
|
|
noCreateOperands().size() + presentOperands().size() +
|
|
|
|
devicePtrOperands().size() + attachOperands().size() +
|
|
|
|
gangPrivateOperands().size() + gangFirstPrivateOperands().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ParallelOp::getDataOperand(unsigned i) {
|
|
|
|
unsigned numOptional = async() ? 1 : 0;
|
|
|
|
numOptional += numGangs() ? 1 : 0;
|
|
|
|
numOptional += numWorkers() ? 1 : 0;
|
|
|
|
numOptional += vectorLength() ? 1 : 0;
|
|
|
|
numOptional += ifCond() ? 1 : 0;
|
|
|
|
numOptional += selfCond() ? 1 : 0;
|
|
|
|
return getOperand(waitOperands().size() + numOptional + i);
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:48:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LoopOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Parse acc.loop operation
|
2020-09-18 23:37:34 +08:00
|
|
|
/// operation := `acc.loop`
|
|
|
|
/// (`gang` ( `(` (`num=` value)? (`,` `static=` value `)`)? )? )?
|
|
|
|
/// (`vector` ( `(` value `)` )? )? (`worker` (`(` value `)`)? )?
|
|
|
|
/// (`vector_length` `(` value `)`)?
|
|
|
|
/// (`tile` `(` value-list `)`)?
|
|
|
|
/// (`private` `(` value-list `)`)?
|
|
|
|
/// (`reduction` `(` value-list `)`)?
|
|
|
|
/// region attr-dict?
|
2020-08-12 23:48:24 +08:00
|
|
|
static ParseResult parseLoopOp(OpAsmParser &parser, OperationState &result) {
|
|
|
|
Builder &builder = parser.getBuilder();
|
2020-09-15 23:41:50 +08:00
|
|
|
unsigned executionMapping = OpenACCExecMapping::NONE;
|
2020-08-12 23:48:24 +08:00
|
|
|
SmallVector<Type, 8> operandTypes;
|
|
|
|
SmallVector<OpAsmParser::OperandType, 8> privateOperands, reductionOperands;
|
2020-09-01 07:49:44 +08:00
|
|
|
SmallVector<OpAsmParser::OperandType, 8> tileOperands;
|
2020-09-23 22:26:09 +08:00
|
|
|
OptionalParseResult gangNum, gangStatic, worker, vector;
|
2020-08-12 23:48:24 +08:00
|
|
|
|
|
|
|
// gang?
|
2020-09-01 07:49:44 +08:00
|
|
|
if (succeeded(parser.parseOptionalKeyword(LoopOp::getGangKeyword())))
|
2020-08-12 23:48:24 +08:00
|
|
|
executionMapping |= OpenACCExecMapping::GANG;
|
|
|
|
|
2020-09-01 07:49:44 +08:00
|
|
|
// optional gang operand
|
|
|
|
if (succeeded(parser.parseOptionalLParen())) {
|
2020-09-23 22:26:09 +08:00
|
|
|
gangNum = parserOptionalOperandAndTypeWithPrefix(
|
|
|
|
parser, result, LoopOp::getGangNumKeyword());
|
|
|
|
if (gangNum.hasValue() && failed(*gangNum))
|
|
|
|
return failure();
|
|
|
|
parser.parseOptionalComma();
|
|
|
|
gangStatic = parserOptionalOperandAndTypeWithPrefix(
|
|
|
|
parser, result, LoopOp::getGangStaticKeyword());
|
|
|
|
if (gangStatic.hasValue() && failed(*gangStatic))
|
|
|
|
return failure();
|
2020-09-01 07:49:44 +08:00
|
|
|
parser.parseOptionalComma();
|
|
|
|
if (failed(parser.parseRParen()))
|
|
|
|
return failure();
|
|
|
|
}
|
2020-08-12 23:48:24 +08:00
|
|
|
|
|
|
|
// worker?
|
2020-09-01 07:49:44 +08:00
|
|
|
if (succeeded(parser.parseOptionalKeyword(LoopOp::getWorkerKeyword())))
|
2020-08-12 23:48:24 +08:00
|
|
|
executionMapping |= OpenACCExecMapping::WORKER;
|
|
|
|
|
2020-09-01 07:49:44 +08:00
|
|
|
// optional worker operand
|
2020-09-23 22:26:09 +08:00
|
|
|
worker = parseOptionalOperandAndType(parser, result);
|
|
|
|
if (worker.hasValue() && failed(*worker))
|
|
|
|
return failure();
|
2020-09-01 07:49:44 +08:00
|
|
|
|
|
|
|
// vector?
|
|
|
|
if (succeeded(parser.parseOptionalKeyword(LoopOp::getVectorKeyword())))
|
|
|
|
executionMapping |= OpenACCExecMapping::VECTOR;
|
|
|
|
|
|
|
|
// optional vector operand
|
2020-09-23 22:26:09 +08:00
|
|
|
vector = parseOptionalOperandAndType(parser, result);
|
|
|
|
if (vector.hasValue() && failed(*vector))
|
|
|
|
return failure();
|
2020-09-01 07:49:44 +08:00
|
|
|
|
|
|
|
// tile()?
|
|
|
|
if (failed(parseOperandList(parser, LoopOp::getTileKeyword(), tileOperands,
|
|
|
|
operandTypes, result)))
|
|
|
|
return failure();
|
2020-08-12 23:48:24 +08:00
|
|
|
|
|
|
|
// private()?
|
|
|
|
if (failed(parseOperandList(parser, LoopOp::getPrivateKeyword(),
|
|
|
|
privateOperands, operandTypes, result)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
// reduction()?
|
|
|
|
if (failed(parseOperandList(parser, LoopOp::getReductionKeyword(),
|
|
|
|
reductionOperands, operandTypes, result)))
|
|
|
|
return failure();
|
|
|
|
|
2020-09-15 23:41:50 +08:00
|
|
|
if (executionMapping != acc::OpenACCExecMapping::NONE)
|
2020-08-12 23:48:24 +08:00
|
|
|
result.addAttribute(LoopOp::getExecutionMappingAttrName(),
|
|
|
|
builder.getI64IntegerAttr(executionMapping));
|
|
|
|
|
|
|
|
// Parse optional results in case there is a reduce.
|
|
|
|
if (parser.parseOptionalArrowTypeList(result.types))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
if (failed(parseRegions<LoopOp>(parser, result)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
result.addAttribute(LoopOp::getOperandSegmentSizeAttr(),
|
|
|
|
builder.getI32VectorAttr(
|
2020-09-23 22:26:09 +08:00
|
|
|
{static_cast<int32_t>(gangNum.hasValue() ? 1 : 0),
|
|
|
|
static_cast<int32_t>(gangStatic.hasValue() ? 1 : 0),
|
|
|
|
static_cast<int32_t>(worker.hasValue() ? 1 : 0),
|
|
|
|
static_cast<int32_t>(vector.hasValue() ? 1 : 0),
|
2020-09-01 07:49:44 +08:00
|
|
|
static_cast<int32_t>(tileOperands.size()),
|
|
|
|
static_cast<int32_t>(privateOperands.size()),
|
2020-08-12 23:48:24 +08:00
|
|
|
static_cast<int32_t>(reductionOperands.size())}));
|
|
|
|
|
|
|
|
if (failed(parser.parseOptionalAttrDictWithKeyword(result.attributes)))
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print(OpAsmPrinter &printer, LoopOp &op) {
|
|
|
|
printer << LoopOp::getOperationName();
|
|
|
|
|
2020-09-15 23:41:50 +08:00
|
|
|
unsigned execMapping = op.exec_mapping();
|
2020-09-01 07:49:44 +08:00
|
|
|
if (execMapping & OpenACCExecMapping::GANG) {
|
|
|
|
printer << " " << LoopOp::getGangKeyword();
|
|
|
|
Value gangNum = op.gangNum();
|
|
|
|
Value gangStatic = op.gangStatic();
|
|
|
|
|
|
|
|
// Print optional gang operands
|
|
|
|
if (gangNum || gangStatic) {
|
|
|
|
printer << "(";
|
|
|
|
if (gangNum) {
|
2020-09-18 23:37:34 +08:00
|
|
|
printer << LoopOp::getGangNumKeyword() << "=" << gangNum << ": "
|
|
|
|
<< gangNum.getType();
|
2020-09-01 07:49:44 +08:00
|
|
|
if (gangStatic)
|
|
|
|
printer << ", ";
|
|
|
|
}
|
|
|
|
if (gangStatic)
|
2020-09-18 23:37:34 +08:00
|
|
|
printer << LoopOp::getGangStaticKeyword() << "=" << gangStatic << ": "
|
|
|
|
<< gangStatic.getType();
|
2020-09-01 07:49:44 +08:00
|
|
|
printer << ")";
|
|
|
|
}
|
|
|
|
}
|
2020-08-12 23:48:24 +08:00
|
|
|
|
2020-09-01 07:49:44 +08:00
|
|
|
if (execMapping & OpenACCExecMapping::WORKER) {
|
|
|
|
printer << " " << LoopOp::getWorkerKeyword();
|
|
|
|
|
|
|
|
// Print optional worker operand if present
|
|
|
|
if (Value workerNum = op.workerNum())
|
2020-09-18 23:37:34 +08:00
|
|
|
printer << "(" << workerNum << ": " << workerNum.getType() << ")";
|
2020-09-01 07:49:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (execMapping & OpenACCExecMapping::VECTOR) {
|
|
|
|
printer << " " << LoopOp::getVectorKeyword();
|
|
|
|
|
|
|
|
// Print optional vector operand if present
|
|
|
|
if (Value vectorLength = op.vectorLength())
|
2020-09-18 23:37:34 +08:00
|
|
|
printer << "(" << vectorLength << ": " << vectorLength.getType() << ")";
|
2020-09-01 07:49:44 +08:00
|
|
|
}
|
2020-08-12 23:48:24 +08:00
|
|
|
|
2020-09-01 07:49:44 +08:00
|
|
|
// tile()?
|
|
|
|
printOperandList(op.tileOperands(), LoopOp::getTileKeyword(), printer);
|
2020-08-12 23:48:24 +08:00
|
|
|
|
|
|
|
// private()?
|
|
|
|
printOperandList(op.privateOperands(), LoopOp::getPrivateKeyword(), printer);
|
|
|
|
|
|
|
|
// reduction()?
|
|
|
|
printOperandList(op.reductionOperands(), LoopOp::getReductionKeyword(),
|
|
|
|
printer);
|
|
|
|
|
|
|
|
if (op.getNumResults() > 0)
|
|
|
|
printer << " -> (" << op.getResultTypes() << ")";
|
|
|
|
|
|
|
|
printer.printRegion(op.region(),
|
|
|
|
/*printEntryBlockArgs=*/false,
|
|
|
|
/*printBlockTerminators=*/true);
|
|
|
|
|
|
|
|
printer.printOptionalAttrDictWithKeyword(
|
2021-02-26 02:35:53 +08:00
|
|
|
op->getAttrs(), {LoopOp::getExecutionMappingAttrName(),
|
|
|
|
LoopOp::getOperandSegmentSizeAttr()});
|
2020-08-12 23:48:24 +08:00
|
|
|
}
|
|
|
|
|
2020-09-15 23:41:50 +08:00
|
|
|
static LogicalResult verifyLoopOp(acc::LoopOp loopOp) {
|
|
|
|
// auto, independent and seq attribute are mutually exclusive.
|
|
|
|
if ((loopOp.auto_() && (loopOp.independent() || loopOp.seq())) ||
|
|
|
|
(loopOp.independent() && loopOp.seq())) {
|
|
|
|
loopOp.emitError("only one of " + acc::LoopOp::getAutoAttrName() + ", " +
|
|
|
|
acc::LoopOp::getIndependentAttrName() + ", " +
|
|
|
|
acc::LoopOp::getSeqAttrName() +
|
|
|
|
" can be present at the same time");
|
|
|
|
return failure();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gang, worker and vector are incompatible with seq.
|
|
|
|
if (loopOp.seq() && loopOp.exec_mapping() != OpenACCExecMapping::NONE) {
|
|
|
|
loopOp.emitError("gang, worker or vector cannot appear with the seq attr");
|
|
|
|
return failure();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check non-empty body().
|
|
|
|
if (loopOp.region().empty()) {
|
|
|
|
loopOp.emitError("expected non-empty body.");
|
|
|
|
return failure();
|
|
|
|
}
|
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2020-09-29 09:22:07 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DataOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static LogicalResult verify(acc::DataOp dataOp) {
|
|
|
|
// 2.6.5. Data Construct restriction
|
|
|
|
// At least one copy, copyin, copyout, create, no_create, present, deviceptr,
|
|
|
|
// attach, or default clause must appear on a data construct.
|
|
|
|
if (dataOp.getOperands().size() == 0 && !dataOp.defaultAttr())
|
|
|
|
return dataOp.emitError("at least one operand or the default attribute "
|
|
|
|
"must appear on the data operation");
|
2020-09-29 21:56:54 +08:00
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2021-06-04 22:25:50 +08:00
|
|
|
unsigned DataOp::getNumDataOperands() {
|
|
|
|
return copyOperands().size() + copyinOperands().size() +
|
|
|
|
copyinReadonlyOperands().size() + copyoutOperands().size() +
|
|
|
|
copyoutZeroOperands().size() + createOperands().size() +
|
|
|
|
createZeroOperands().size() + noCreateOperands().size() +
|
|
|
|
presentOperands().size() + deviceptrOperands().size() +
|
|
|
|
attachOperands().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value DataOp::getDataOperand(unsigned i) {
|
|
|
|
unsigned numOptional = ifCond() ? 1 : 0;
|
|
|
|
return getOperand(numOptional + i);
|
|
|
|
}
|
|
|
|
|
2020-10-10 09:02:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ExitDataOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static LogicalResult verify(acc::ExitDataOp op) {
|
|
|
|
// 2.6.6. Data Exit Directive restriction
|
|
|
|
// At least one copyout, delete, or detach clause must appear on an exit data
|
|
|
|
// directive.
|
|
|
|
if (op.copyoutOperands().empty() && op.deleteOperands().empty() &&
|
|
|
|
op.detachOperands().empty())
|
|
|
|
return op.emitError(
|
|
|
|
"at least one operand in copyout, delete or detach must appear on the "
|
|
|
|
"exit data operation");
|
|
|
|
|
|
|
|
// The async attribute represent the async clause without value. Therefore the
|
|
|
|
// attribute and operand cannot appear at the same time.
|
|
|
|
if (op.asyncOperand() && op.async())
|
|
|
|
return op.emitError("async attribute cannot appear with asyncOperand");
|
|
|
|
|
|
|
|
// The wait attribute represent the wait clause without values. Therefore the
|
|
|
|
// attribute and operands cannot appear at the same time.
|
|
|
|
if (!op.waitOperands().empty() && op.wait())
|
|
|
|
return op.emitError("wait attribute cannot appear with waitOperands");
|
2020-10-12 09:26:54 +08:00
|
|
|
|
|
|
|
if (op.waitDevnum() && op.waitOperands().empty())
|
|
|
|
return op.emitError("wait_devnum cannot appear without waitOperands");
|
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2021-05-12 23:31:18 +08:00
|
|
|
unsigned ExitDataOp::getNumDataOperands() {
|
|
|
|
return copyoutOperands().size() + deleteOperands().size() +
|
|
|
|
detachOperands().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ExitDataOp::getDataOperand(unsigned i) {
|
|
|
|
unsigned numOptional = ifCond() ? 1 : 0;
|
|
|
|
numOptional += asyncOperand() ? 1 : 0;
|
|
|
|
numOptional += waitDevnum() ? 1 : 0;
|
|
|
|
return getOperand(waitOperands().size() + numOptional + i);
|
|
|
|
}
|
|
|
|
|
2020-10-12 09:26:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2021-05-12 23:31:18 +08:00
|
|
|
// EnterDataOp
|
2020-10-12 09:26:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static LogicalResult verify(acc::EnterDataOp op) {
|
|
|
|
// 2.6.6. Data Enter Directive restriction
|
|
|
|
// At least one copyin, create, or attach clause must appear on an enter data
|
|
|
|
// directive.
|
|
|
|
if (op.copyinOperands().empty() && op.createOperands().empty() &&
|
|
|
|
op.createZeroOperands().empty() && op.attachOperands().empty())
|
|
|
|
return op.emitError(
|
|
|
|
"at least one operand in copyin, create, "
|
|
|
|
"create_zero or attach must appear on the enter data operation");
|
|
|
|
|
|
|
|
// The async attribute represent the async clause without value. Therefore the
|
|
|
|
// attribute and operand cannot appear at the same time.
|
|
|
|
if (op.asyncOperand() && op.async())
|
|
|
|
return op.emitError("async attribute cannot appear with asyncOperand");
|
|
|
|
|
|
|
|
// The wait attribute represent the wait clause without values. Therefore the
|
|
|
|
// attribute and operands cannot appear at the same time.
|
|
|
|
if (!op.waitOperands().empty() && op.wait())
|
|
|
|
return op.emitError("wait attribute cannot appear with waitOperands");
|
2020-10-10 09:02:29 +08:00
|
|
|
|
|
|
|
if (op.waitDevnum() && op.waitOperands().empty())
|
|
|
|
return op.emitError("wait_devnum cannot appear without waitOperands");
|
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2021-05-12 23:31:18 +08:00
|
|
|
unsigned EnterDataOp::getNumDataOperands() {
|
|
|
|
return copyinOperands().size() + createOperands().size() +
|
|
|
|
createZeroOperands().size() + attachOperands().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value EnterDataOp::getDataOperand(unsigned i) {
|
|
|
|
unsigned numOptional = ifCond() ? 1 : 0;
|
|
|
|
numOptional += asyncOperand() ? 1 : 0;
|
|
|
|
numOptional += waitDevnum() ? 1 : 0;
|
|
|
|
return getOperand(waitOperands().size() + numOptional + i);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:58:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InitOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static LogicalResult verify(acc::InitOp initOp) {
|
|
|
|
Operation *currOp = initOp;
|
|
|
|
while ((currOp = currOp->getParentOp())) {
|
2020-09-30 01:12:54 +08:00
|
|
|
if (isComputeOperation(currOp))
|
2020-09-29 22:58:46 +08:00
|
|
|
return initOp.emitOpError("cannot be nested in a compute operation");
|
2020-09-30 01:12:54 +08:00
|
|
|
}
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ShutdownOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static LogicalResult verify(acc::ShutdownOp op) {
|
|
|
|
Operation *currOp = op;
|
|
|
|
while ((currOp = currOp->getParentOp())) {
|
|
|
|
if (isComputeOperation(currOp))
|
|
|
|
return op.emitOpError("cannot be nested in a compute operation");
|
2020-09-29 22:58:46 +08:00
|
|
|
}
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2020-09-29 21:56:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UpdateOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static LogicalResult verify(acc::UpdateOp updateOp) {
|
|
|
|
// At least one of host or device should have a value.
|
|
|
|
if (updateOp.hostOperands().size() == 0 &&
|
|
|
|
updateOp.deviceOperands().size() == 0)
|
|
|
|
return updateOp.emitError("at least one value must be present in"
|
|
|
|
" hostOperands or deviceOperands");
|
|
|
|
|
|
|
|
// The async attribute represent the async clause without value. Therefore the
|
|
|
|
// attribute and operand cannot appear at the same time.
|
|
|
|
if (updateOp.asyncOperand() && updateOp.async())
|
|
|
|
return updateOp.emitError("async attribute cannot appear with "
|
|
|
|
" asyncOperand");
|
|
|
|
|
|
|
|
// The wait attribute represent the wait clause without values. Therefore the
|
|
|
|
// attribute and operands cannot appear at the same time.
|
|
|
|
if (updateOp.waitOperands().size() > 0 && updateOp.wait())
|
|
|
|
return updateOp.emitError("wait attribute cannot appear with waitOperands");
|
|
|
|
|
|
|
|
if (updateOp.waitDevnum() && updateOp.waitOperands().size() == 0)
|
|
|
|
return updateOp.emitError("wait_devnum cannot appear without waitOperands");
|
2020-09-29 09:22:07 +08:00
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2021-05-12 23:31:18 +08:00
|
|
|
unsigned UpdateOp::getNumDataOperands() {
|
|
|
|
return hostOperands().size() + deviceOperands().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value UpdateOp::getDataOperand(unsigned i) {
|
|
|
|
unsigned numOptional = asyncOperand() ? 1 : 0;
|
|
|
|
numOptional += waitDevnum() ? 1 : 0;
|
|
|
|
numOptional += ifCond() ? 1 : 0;
|
|
|
|
return getOperand(waitOperands().size() + deviceTypeOperands().size() +
|
|
|
|
numOptional + i);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:39:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// WaitOp
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static LogicalResult verify(acc::WaitOp waitOp) {
|
|
|
|
// The async attribute represent the async clause without value. Therefore the
|
|
|
|
// attribute and operand cannot appear at the same time.
|
|
|
|
if (waitOp.asyncOperand() && waitOp.async())
|
|
|
|
return waitOp.emitError("async attribute cannot appear with asyncOperand");
|
|
|
|
|
|
|
|
if (waitOp.waitDevnum() && waitOp.waitOperands().empty())
|
|
|
|
return waitOp.emitError("wait_devnum cannot appear without waitOperands");
|
|
|
|
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:48:24 +08:00
|
|
|
#define GET_OP_CLASSES
|
|
|
|
#include "mlir/Dialect/OpenACC/OpenACCOps.cpp.inc"
|