[MLIR] Add OpenMP dialect with barrier operation
Summary:
Barrier is a simple operation that takes no arguments and returns
nothing, but implies a side effect (synchronization of all threads)
Reviewers: jdoerfert
Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72400
2020-01-29 11:31:25 +00:00
|
|
|
//===- OpenMPDialect.cpp - MLIR Dialect for OpenMP implementation ---------===//
|
|
|
|
|
//
|
|
|
|
|
// Part of the LLVM 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
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// This file implements the OpenMP dialect and its operations.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
|
2021-07-08 10:59:02 +02:00
|
|
|
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
|
[mlir][OpenMP] Add custom parser and pretty printer for parallel construct
Reviewers: jdoerfert
Subscribers: yaxunl, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, sstefan1, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81264
2020-06-05 16:01:15 +01:00
|
|
|
#include "mlir/IR/Attributes.h"
|
2022-01-18 16:53:55 +00:00
|
|
|
#include "mlir/IR/DialectImplementation.h"
|
[MLIR] Add OpenMP dialect with barrier operation
Summary:
Barrier is a simple operation that takes no arguments and returns
nothing, but implies a side effect (synchronization of all threads)
Reviewers: jdoerfert
Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72400
2020-01-29 11:31:25 +00:00
|
|
|
#include "mlir/IR/OpImplementation.h"
|
[mlir][OpenMP] Add custom parser and pretty printer for parallel construct
Reviewers: jdoerfert
Subscribers: yaxunl, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, sstefan1, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81264
2020-06-05 16:01:15 +01:00
|
|
|
#include "mlir/IR/OperationSupport.h"
|
[MLIR] Add OpenMP dialect with barrier operation
Summary:
Barrier is a simple operation that takes no arguments and returns
nothing, but implies a side effect (synchronization of all threads)
Reviewers: jdoerfert
Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72400
2020-01-29 11:31:25 +00:00
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
#include "llvm/ADT/BitVector.h"
|
[mlir][OpenMP] Add custom parser and pretty printer for parallel construct
Reviewers: jdoerfert
Subscribers: yaxunl, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, sstefan1, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81264
2020-06-05 16:01:15 +01:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2021-03-17 08:55:42 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
[mlir][OpenMP] Add custom parser and pretty printer for parallel construct
Reviewers: jdoerfert
Subscribers: yaxunl, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, sstefan1, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81264
2020-06-05 16:01:15 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
[MLIR] [OpenMP] Add basic OpenMP parallel operation
Summary:
This includes a basic implementation for the OpenMP parallel
operation without a custom pretty-printer and parser.
The if, num_threads, private, shared, first_private, last_private,
proc_bind and default clauses are included in this implementation.
Currently the reduction clause is omitted as it is more complex and
requires analysis to see if we can share implementation with the loop
dialect. The allocate clause is also omitted.
A discussion about the design of this operation can be found here:
https://llvm.discourse.group/t/openmp-parallel-operation-design-issues/686
The current OpenMP Specification can be found here:
https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Reviewers: jdoerfert
Subscribers: mgorny, yaxunl, kristof.beyls, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79410
2020-05-05 13:04:32 +01:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2022-01-18 16:53:55 +00:00
|
|
|
#include "llvm/ADT/TypeSwitch.h"
|
[mlir][OpenMP] Add custom parser and pretty printer for parallel construct
Reviewers: jdoerfert
Subscribers: yaxunl, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, sstefan1, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81264
2020-06-05 16:01:15 +01:00
|
|
|
#include <cstddef>
|
[MLIR] [OpenMP] Add basic OpenMP parallel operation
Summary:
This includes a basic implementation for the OpenMP parallel
operation without a custom pretty-printer and parser.
The if, num_threads, private, shared, first_private, last_private,
proc_bind and default clauses are included in this implementation.
Currently the reduction clause is omitted as it is more complex and
requires analysis to see if we can share implementation with the loop
dialect. The allocate clause is also omitted.
A discussion about the design of this operation can be found here:
https://llvm.discourse.group/t/openmp-parallel-operation-design-issues/686
The current OpenMP Specification can be found here:
https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Reviewers: jdoerfert
Subscribers: mgorny, yaxunl, kristof.beyls, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79410
2020-05-05 13:04:32 +01:00
|
|
|
|
2021-06-28 22:54:11 +00:00
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
|
[MLIR] [OpenMP] Add basic OpenMP parallel operation
Summary:
This includes a basic implementation for the OpenMP parallel
operation without a custom pretty-printer and parser.
The if, num_threads, private, shared, first_private, last_private,
proc_bind and default clauses are included in this implementation.
Currently the reduction clause is omitted as it is more complex and
requires analysis to see if we can share implementation with the loop
dialect. The allocate clause is also omitted.
A discussion about the design of this operation can be found here:
https://llvm.discourse.group/t/openmp-parallel-operation-design-issues/686
The current OpenMP Specification can be found here:
https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Reviewers: jdoerfert
Subscribers: mgorny, yaxunl, kristof.beyls, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79410
2020-05-05 13:04:32 +01:00
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc"
|
2022-03-28 13:36:32 +05:30
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.cpp.inc"
|
2021-07-08 10:59:02 +02:00
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.cpp.inc"
|
[MLIR] [OpenMP] Add basic OpenMP parallel operation
Summary:
This includes a basic implementation for the OpenMP parallel
operation without a custom pretty-printer and parser.
The if, num_threads, private, shared, first_private, last_private,
proc_bind and default clauses are included in this implementation.
Currently the reduction clause is omitted as it is more complex and
requires analysis to see if we can share implementation with the loop
dialect. The allocate clause is also omitted.
A discussion about the design of this operation can be found here:
https://llvm.discourse.group/t/openmp-parallel-operation-design-issues/686
The current OpenMP Specification can be found here:
https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Reviewers: jdoerfert
Subscribers: mgorny, yaxunl, kristof.beyls, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79410
2020-05-05 13:04:32 +01:00
|
|
|
|
[MLIR] Add OpenMP dialect with barrier operation
Summary:
Barrier is a simple operation that takes no arguments and returns
nothing, but implies a side effect (synchronization of all threads)
Reviewers: jdoerfert
Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72400
2020-01-29 11:31:25 +00:00
|
|
|
using namespace mlir;
|
|
|
|
|
using namespace mlir::omp;
|
|
|
|
|
|
2021-07-08 10:59:02 +02:00
|
|
|
namespace {
|
|
|
|
|
/// Model for pointer-like types that already provide a `getElementType` method.
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct PointerLikeModel
|
|
|
|
|
: public PointerLikeType::ExternalModel<PointerLikeModel<T>, T> {
|
|
|
|
|
Type getElementType(Type pointer) const {
|
|
|
|
|
return pointer.cast<T>().getElementType();
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-12-07 18:27:58 +00:00
|
|
|
} // namespace
|
2021-07-08 10:59:02 +02:00
|
|
|
|
2020-08-07 02:41:44 +00:00
|
|
|
void OpenMPDialect::initialize() {
|
[MLIR] Add OpenMP dialect with barrier operation
Summary:
Barrier is a simple operation that takes no arguments and returns
nothing, but implies a side effect (synchronization of all threads)
Reviewers: jdoerfert
Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72400
2020-01-29 11:31:25 +00:00
|
|
|
addOperations<
|
|
|
|
|
#define GET_OP_LIST
|
|
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
|
|
|
|
|
>();
|
2022-01-18 16:53:55 +00:00
|
|
|
addAttributes<
|
|
|
|
|
#define GET_ATTRDEF_LIST
|
|
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
|
|
|
|
|
>();
|
2021-07-08 10:59:02 +02:00
|
|
|
|
|
|
|
|
LLVM::LLVMPointerType::attachInterface<
|
|
|
|
|
PointerLikeModel<LLVM::LLVMPointerType>>(*getContext());
|
|
|
|
|
MemRefType::attachInterface<PointerLikeModel<MemRefType>>(*getContext());
|
[MLIR] Add OpenMP dialect with barrier operation
Summary:
Barrier is a simple operation that takes no arguments and returns
nothing, but implies a side effect (synchronization of all threads)
Reviewers: jdoerfert
Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72400
2020-01-29 11:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Parser and printer for Allocate Clause
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2020-09-15 11:51:02 +01:00
|
|
|
/// Parse an allocate clause with allocators and a list of operands with types.
|
|
|
|
|
///
|
|
|
|
|
/// allocate-operand-list :: = allocate-operand |
|
|
|
|
|
/// allocator-operand `,` allocate-operand-list
|
|
|
|
|
/// allocate-operand :: = ssa-id-and-type -> ssa-id-and-type
|
|
|
|
|
/// ssa-id-and-type ::= ssa-id `:` type
|
|
|
|
|
static ParseResult parseAllocateAndAllocator(
|
|
|
|
|
OpAsmParser &parser,
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operandsAllocate,
|
2020-09-15 11:51:02 +01:00
|
|
|
SmallVectorImpl<Type> &typesAllocate,
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operandsAllocator,
|
2020-09-15 11:51:02 +01:00
|
|
|
SmallVectorImpl<Type> &typesAllocator) {
|
|
|
|
|
|
2022-02-19 10:00:03 +05:30
|
|
|
return parser.parseCommaSeparatedList([&]() -> ParseResult {
|
2022-03-21 21:42:13 +01:00
|
|
|
OpAsmParser::UnresolvedOperand operand;
|
2022-02-19 10:00:03 +05:30
|
|
|
Type type;
|
|
|
|
|
if (parser.parseOperand(operand) || parser.parseColonType(type))
|
|
|
|
|
return failure();
|
|
|
|
|
operandsAllocator.push_back(operand);
|
|
|
|
|
typesAllocator.push_back(type);
|
|
|
|
|
if (parser.parseArrow())
|
|
|
|
|
return failure();
|
|
|
|
|
if (parser.parseOperand(operand) || parser.parseColonType(type))
|
|
|
|
|
return failure();
|
2021-09-20 18:27:40 -07:00
|
|
|
|
2022-02-19 10:00:03 +05:30
|
|
|
operandsAllocate.push_back(operand);
|
|
|
|
|
typesAllocate.push_back(type);
|
|
|
|
|
return success();
|
|
|
|
|
});
|
2020-09-15 11:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
/// Print allocate clause
|
2022-02-19 10:00:03 +05:30
|
|
|
static void printAllocateAndAllocator(OpAsmPrinter &p, Operation *op,
|
2021-10-19 17:18:51 +05:30
|
|
|
OperandRange varsAllocate,
|
2022-02-19 10:00:03 +05:30
|
|
|
TypeRange typesAllocate,
|
|
|
|
|
OperandRange varsAllocator,
|
|
|
|
|
TypeRange typesAllocator) {
|
2021-10-19 17:18:51 +05:30
|
|
|
for (unsigned i = 0; i < varsAllocate.size(); ++i) {
|
2022-02-19 10:00:03 +05:30
|
|
|
std::string separator = i == varsAllocate.size() - 1 ? "" : ", ";
|
|
|
|
|
p << varsAllocator[i] << " : " << typesAllocator[i] << " -> ";
|
|
|
|
|
p << varsAllocate[i] << " : " << typesAllocate[i] << separator;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:37:55 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Parser and printer for a clause attribute (StringEnumAttr)
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-03-02 10:53:53 +05:30
|
|
|
template <typename ClauseAttr>
|
|
|
|
|
static ParseResult parseClauseAttr(AsmParser &parser, ClauseAttr &attr) {
|
|
|
|
|
using ClauseT = decltype(std::declval<ClauseAttr>().getValue());
|
|
|
|
|
StringRef enumStr;
|
|
|
|
|
SMLoc loc = parser.getCurrentLocation();
|
|
|
|
|
if (parser.parseKeyword(&enumStr))
|
|
|
|
|
return failure();
|
|
|
|
|
if (Optional<ClauseT> enumValue = symbolizeEnum<ClauseT>(enumStr)) {
|
|
|
|
|
attr = ClauseAttr::get(parser.getContext(), *enumValue);
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
return parser.emitError(loc, "invalid clause value: '") << enumStr << "'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename ClauseAttr>
|
|
|
|
|
void printClauseAttr(OpAsmPrinter &p, Operation *op, ClauseAttr attr) {
|
|
|
|
|
p << stringifyEnum(attr.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Parser and printer for Linear Clause
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
[mlir][OpenMP] Add custom parser and pretty printer for parallel construct
Reviewers: jdoerfert
Subscribers: yaxunl, guansong, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, sstefan1, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81264
2020-06-05 16:01:15 +01:00
|
|
|
|
2021-03-17 08:55:42 +00:00
|
|
|
/// linear ::= `linear` `(` linear-list `)`
|
|
|
|
|
/// linear-list := linear-val | linear-val linear-list
|
|
|
|
|
/// linear-val := ssa-id-and-type `=` ssa-id-and-type
|
|
|
|
|
static ParseResult
|
|
|
|
|
parseLinearClause(OpAsmParser &parser,
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &vars,
|
2021-03-17 08:55:42 +00:00
|
|
|
SmallVectorImpl<Type> &types,
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &stepVars) {
|
2021-03-17 08:55:42 +00:00
|
|
|
do {
|
2022-03-21 21:42:13 +01:00
|
|
|
OpAsmParser::UnresolvedOperand var;
|
2021-03-17 08:55:42 +00:00
|
|
|
Type type;
|
2022-03-21 21:42:13 +01:00
|
|
|
OpAsmParser::UnresolvedOperand stepVar;
|
2021-03-17 08:55:42 +00:00
|
|
|
if (parser.parseOperand(var) || parser.parseEqual() ||
|
|
|
|
|
parser.parseOperand(stepVar) || parser.parseColonType(type))
|
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
|
|
vars.push_back(var);
|
|
|
|
|
types.push_back(type);
|
|
|
|
|
stepVars.push_back(stepVar);
|
|
|
|
|
} while (succeeded(parser.parseOptionalComma()));
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
/// Print Linear Clause
|
2022-03-23 09:37:55 +05:30
|
|
|
static void printLinearClause(OpAsmPrinter &p, Operation *op,
|
|
|
|
|
ValueRange linearVars, TypeRange linearVarTypes,
|
|
|
|
|
ValueRange linearStepVars) {
|
2021-10-19 17:18:51 +05:30
|
|
|
size_t linearVarsSize = linearVars.size();
|
|
|
|
|
for (unsigned i = 0; i < linearVarsSize; ++i) {
|
2022-03-23 09:37:55 +05:30
|
|
|
std::string separator = i == linearVarsSize - 1 ? "" : ", ";
|
2021-10-19 17:18:51 +05:30
|
|
|
p << linearVars[i];
|
|
|
|
|
if (linearStepVars.size() > i)
|
|
|
|
|
p << " = " << linearStepVars[i];
|
|
|
|
|
p << " : " << linearVars[i].getType() << separator;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2022-03-02 10:53:53 +05:30
|
|
|
// Parser, printer and verifier for Schedule Clause
|
2021-10-19 17:18:51 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2021-05-26 10:35:45 +01:00
|
|
|
static ParseResult
|
|
|
|
|
verifyScheduleModifiers(OpAsmParser &parser,
|
|
|
|
|
SmallVectorImpl<SmallString<12>> &modifiers) {
|
|
|
|
|
if (modifiers.size() > 2)
|
|
|
|
|
return parser.emitError(parser.getNameLoc()) << " unexpected modifier(s)";
|
2022-01-02 22:02:14 +00:00
|
|
|
for (const auto &mod : modifiers) {
|
2021-05-26 10:35:45 +01:00
|
|
|
// Translate the string. If it has no value, then it was not a valid
|
|
|
|
|
// modifier!
|
|
|
|
|
auto symbol = symbolizeScheduleModifier(mod);
|
|
|
|
|
if (!symbol.hasValue())
|
|
|
|
|
return parser.emitError(parser.getNameLoc())
|
|
|
|
|
<< " unknown modifier type: " << mod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we have one modifier that is "simd", then stick a "none" modiifer in
|
|
|
|
|
// index 0.
|
|
|
|
|
if (modifiers.size() == 1) {
|
2022-01-18 16:53:55 +00:00
|
|
|
if (symbolizeScheduleModifier(modifiers[0]) == ScheduleModifier::simd) {
|
2021-05-26 10:35:45 +01:00
|
|
|
modifiers.push_back(modifiers[0]);
|
2022-01-18 16:53:55 +00:00
|
|
|
modifiers[0] = stringifyScheduleModifier(ScheduleModifier::none);
|
2021-05-26 10:35:45 +01:00
|
|
|
}
|
|
|
|
|
} else if (modifiers.size() == 2) {
|
|
|
|
|
// If there are two modifier:
|
|
|
|
|
// First modifier should not be simd, second one should be simd
|
2022-01-18 16:53:55 +00:00
|
|
|
if (symbolizeScheduleModifier(modifiers[0]) == ScheduleModifier::simd ||
|
|
|
|
|
symbolizeScheduleModifier(modifiers[1]) != ScheduleModifier::simd)
|
2021-05-26 10:35:45 +01:00
|
|
|
return parser.emitError(parser.getNameLoc())
|
|
|
|
|
<< " incorrect modifier order";
|
|
|
|
|
}
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 08:55:42 +00:00
|
|
|
/// schedule ::= `schedule` `(` sched-list `)`
|
2021-05-26 10:35:45 +01:00
|
|
|
/// sched-list ::= sched-val | sched-val sched-list |
|
|
|
|
|
/// sched-val `,` sched-modifier
|
2021-03-17 08:55:42 +00:00
|
|
|
/// sched-val ::= sched-with-chunk | sched-wo-chunk
|
|
|
|
|
/// sched-with-chunk ::= sched-with-chunk-types (`=` ssa-id-and-type)?
|
|
|
|
|
/// sched-with-chunk-types ::= `static` | `dynamic` | `guided`
|
|
|
|
|
/// sched-wo-chunk ::= `auto` | `runtime`
|
2021-05-26 10:35:45 +01:00
|
|
|
/// sched-modifier ::= sched-mod-val | sched-mod-val `,` sched-mod-val
|
|
|
|
|
/// sched-mod-val ::= `monotonic` | `nonmonotonic` | `simd` | `none`
|
2022-03-23 09:37:55 +05:30
|
|
|
static ParseResult parseScheduleClause(
|
|
|
|
|
OpAsmParser &parser, ClauseScheduleKindAttr &scheduleAttr,
|
|
|
|
|
ScheduleModifierAttr &schedule_modifier, UnitAttr &simdModifier,
|
|
|
|
|
Optional<OpAsmParser::UnresolvedOperand> &chunkSize, Type &chunkType) {
|
2021-03-17 08:55:42 +00:00
|
|
|
StringRef keyword;
|
|
|
|
|
if (parser.parseKeyword(&keyword))
|
|
|
|
|
return failure();
|
2022-03-23 09:37:55 +05:30
|
|
|
llvm::Optional<mlir::omp::ClauseScheduleKind> schedule =
|
|
|
|
|
symbolizeClauseScheduleKind(keyword);
|
|
|
|
|
if (!schedule)
|
|
|
|
|
return parser.emitError(parser.getNameLoc()) << " expected schedule kind";
|
2021-03-17 08:55:42 +00:00
|
|
|
|
2022-03-23 09:37:55 +05:30
|
|
|
scheduleAttr = ClauseScheduleKindAttr::get(parser.getContext(), *schedule);
|
|
|
|
|
switch (*schedule) {
|
|
|
|
|
case ClauseScheduleKind::Static:
|
|
|
|
|
case ClauseScheduleKind::Dynamic:
|
|
|
|
|
case ClauseScheduleKind::Guided:
|
2021-03-17 08:55:42 +00:00
|
|
|
if (succeeded(parser.parseOptionalEqual())) {
|
2022-03-21 21:42:13 +01:00
|
|
|
chunkSize = OpAsmParser::UnresolvedOperand{};
|
2022-01-19 12:36:14 +08:00
|
|
|
if (parser.parseOperand(*chunkSize) || parser.parseColonType(chunkType))
|
2021-03-17 08:55:42 +00:00
|
|
|
return failure();
|
|
|
|
|
} else {
|
|
|
|
|
chunkSize = llvm::NoneType::None;
|
|
|
|
|
}
|
2022-03-23 09:37:55 +05:30
|
|
|
break;
|
|
|
|
|
case ClauseScheduleKind::Auto:
|
|
|
|
|
case ClauseScheduleKind::Runtime:
|
2021-03-17 08:55:42 +00:00
|
|
|
chunkSize = llvm::NoneType::None;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 11:20:49 +01:00
|
|
|
// If there is a comma, we have one or more modifiers..
|
2022-03-23 09:37:55 +05:30
|
|
|
SmallVector<SmallString<12>> modifiers;
|
2021-05-26 10:35:45 +01:00
|
|
|
while (succeeded(parser.parseOptionalComma())) {
|
2021-04-06 11:20:49 +01:00
|
|
|
StringRef mod;
|
|
|
|
|
if (parser.parseKeyword(&mod))
|
|
|
|
|
return failure();
|
|
|
|
|
modifiers.push_back(mod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-26 10:35:45 +01:00
|
|
|
if (verifyScheduleModifiers(parser, modifiers))
|
|
|
|
|
return failure();
|
|
|
|
|
|
2022-03-23 09:37:55 +05:30
|
|
|
if (!modifiers.empty()) {
|
|
|
|
|
SMLoc loc = parser.getCurrentLocation();
|
|
|
|
|
if (Optional<ScheduleModifier> mod =
|
|
|
|
|
symbolizeScheduleModifier(modifiers[0])) {
|
|
|
|
|
schedule_modifier = ScheduleModifierAttr::get(parser.getContext(), *mod);
|
|
|
|
|
} else {
|
|
|
|
|
return parser.emitError(loc, "invalid schedule modifier");
|
|
|
|
|
}
|
|
|
|
|
// Only SIMD attribute is allowed here!
|
|
|
|
|
if (modifiers.size() > 1) {
|
|
|
|
|
assert(symbolizeScheduleModifier(modifiers[1]) == ScheduleModifier::simd);
|
|
|
|
|
simdModifier = UnitAttr::get(parser.getBuilder().getContext());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 08:55:42 +00:00
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
/// Print schedule clause
|
2022-03-23 09:37:55 +05:30
|
|
|
static void printScheduleClause(OpAsmPrinter &p, Operation *op,
|
|
|
|
|
ClauseScheduleKindAttr schedAttr,
|
|
|
|
|
ScheduleModifierAttr modifier, UnitAttr simd,
|
|
|
|
|
Value scheduleChunkVar,
|
|
|
|
|
Type scheduleChunkType) {
|
|
|
|
|
p << stringifyClauseScheduleKind(schedAttr.getValue());
|
2021-10-19 17:18:51 +05:30
|
|
|
if (scheduleChunkVar)
|
2022-01-19 12:36:14 +08:00
|
|
|
p << " = " << scheduleChunkVar << " : " << scheduleChunkVar.getType();
|
2022-01-18 16:53:55 +00:00
|
|
|
if (modifier)
|
2022-03-23 09:37:55 +05:30
|
|
|
p << ", " << stringifyScheduleModifier(modifier.getValue());
|
2021-05-26 10:35:45 +01:00
|
|
|
if (simd)
|
|
|
|
|
p << ", simd";
|
2021-10-19 17:18:51 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Parser, printer and verifier for ReductionVarList
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2021-07-08 10:59:02 +02:00
|
|
|
/// reduction-entry-list ::= reduction-entry
|
|
|
|
|
/// | reduction-entry-list `,` reduction-entry
|
|
|
|
|
/// reduction-entry ::= symbol-ref `->` ssa-id `:` type
|
2022-03-21 21:42:13 +01:00
|
|
|
static ParseResult
|
|
|
|
|
parseReductionVarList(OpAsmParser &parser,
|
|
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operands,
|
|
|
|
|
SmallVectorImpl<Type> &types,
|
|
|
|
|
ArrayAttr &redcuctionSymbols) {
|
2022-02-21 12:50:58 +05:30
|
|
|
SmallVector<SymbolRefAttr> reductionVec;
|
2021-07-08 10:59:02 +02:00
|
|
|
do {
|
2022-02-21 12:50:58 +05:30
|
|
|
if (parser.parseAttribute(reductionVec.emplace_back()) ||
|
|
|
|
|
parser.parseArrow() || parser.parseOperand(operands.emplace_back()) ||
|
2021-07-08 10:59:02 +02:00
|
|
|
parser.parseColonType(types.emplace_back()))
|
|
|
|
|
return failure();
|
|
|
|
|
} while (succeeded(parser.parseOptionalComma()));
|
2022-02-21 12:50:58 +05:30
|
|
|
SmallVector<Attribute> reductions(reductionVec.begin(), reductionVec.end());
|
|
|
|
|
redcuctionSymbols = ArrayAttr::get(parser.getContext(), reductions);
|
|
|
|
|
return success();
|
2021-07-08 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
/// Print Reduction clause
|
2022-02-21 12:50:58 +05:30
|
|
|
static void printReductionVarList(OpAsmPrinter &p, Operation *op,
|
|
|
|
|
OperandRange reductionVars,
|
|
|
|
|
TypeRange reductionTypes,
|
|
|
|
|
Optional<ArrayAttr> reductions) {
|
2021-10-19 17:18:51 +05:30
|
|
|
for (unsigned i = 0, e = reductions->size(); i < e; ++i) {
|
|
|
|
|
if (i != 0)
|
|
|
|
|
p << ", ";
|
2021-12-20 19:45:05 +00:00
|
|
|
p << (*reductions)[i] << " -> " << reductionVars[i] << " : "
|
|
|
|
|
<< reductionVars[i].getType();
|
2021-10-19 17:18:51 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Verifies Reduction Clause
|
|
|
|
|
static LogicalResult verifyReductionVarList(Operation *op,
|
|
|
|
|
Optional<ArrayAttr> reductions,
|
2021-12-20 19:45:05 +00:00
|
|
|
OperandRange reductionVars) {
|
2022-01-02 01:55:30 +00:00
|
|
|
if (!reductionVars.empty()) {
|
2021-12-20 19:45:05 +00:00
|
|
|
if (!reductions || reductions->size() != reductionVars.size())
|
2021-10-19 17:18:51 +05:30
|
|
|
return op->emitOpError()
|
|
|
|
|
<< "expected as many reduction symbol references "
|
|
|
|
|
"as reduction variables";
|
|
|
|
|
} else {
|
|
|
|
|
if (reductions)
|
|
|
|
|
return op->emitOpError() << "unexpected reduction symbol references";
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 22:10:45 +00:00
|
|
|
// TODO: The followings should be done in
|
|
|
|
|
// SymbolUserOpInterface::verifySymbolUses.
|
2021-10-19 17:18:51 +05:30
|
|
|
DenseSet<Value> accumulators;
|
2021-12-20 19:45:05 +00:00
|
|
|
for (auto args : llvm::zip(reductionVars, *reductions)) {
|
2021-10-19 17:18:51 +05:30
|
|
|
Value accum = std::get<0>(args);
|
|
|
|
|
|
|
|
|
|
if (!accumulators.insert(accum).second)
|
|
|
|
|
return op->emitOpError() << "accumulator variable used more than once";
|
|
|
|
|
|
|
|
|
|
Type varType = accum.getType().cast<PointerLikeType>();
|
|
|
|
|
auto symbolRef = std::get<1>(args).cast<SymbolRefAttr>();
|
|
|
|
|
auto decl =
|
|
|
|
|
SymbolTable::lookupNearestSymbolFrom<ReductionDeclareOp>(op, symbolRef);
|
|
|
|
|
if (!decl)
|
|
|
|
|
return op->emitOpError() << "expected symbol reference " << symbolRef
|
|
|
|
|
<< " to point to a reduction declaration";
|
|
|
|
|
|
|
|
|
|
if (decl.getAccumulatorType() && decl.getAccumulatorType() != varType)
|
|
|
|
|
return op->emitOpError()
|
|
|
|
|
<< "expected accumulator (" << varType
|
|
|
|
|
<< ") to be the same type as reduction declaration ("
|
|
|
|
|
<< decl.getAccumulatorType() << ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 19:08:29 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Parser, printer and verifier for Synchronization Hint (2.17.12)
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
/// Parses a Synchronization Hint clause. The value of hint is an integer
|
|
|
|
|
/// which is a combination of different hints from `omp_sync_hint_t`.
|
|
|
|
|
///
|
|
|
|
|
/// hint-clause = `hint` `(` hint-value `)`
|
|
|
|
|
static ParseResult parseSynchronizationHint(OpAsmParser &parser,
|
2022-03-02 10:53:53 +05:30
|
|
|
IntegerAttr &hintAttr) {
|
2021-10-19 19:08:29 +05:30
|
|
|
StringRef hintKeyword;
|
|
|
|
|
int64_t hint = 0;
|
|
|
|
|
do {
|
|
|
|
|
if (failed(parser.parseKeyword(&hintKeyword)))
|
|
|
|
|
return failure();
|
|
|
|
|
if (hintKeyword == "uncontended")
|
|
|
|
|
hint |= 1;
|
|
|
|
|
else if (hintKeyword == "contended")
|
|
|
|
|
hint |= 2;
|
|
|
|
|
else if (hintKeyword == "nonspeculative")
|
|
|
|
|
hint |= 4;
|
|
|
|
|
else if (hintKeyword == "speculative")
|
|
|
|
|
hint |= 8;
|
|
|
|
|
else
|
|
|
|
|
return parser.emitError(parser.getCurrentLocation())
|
|
|
|
|
<< hintKeyword << " is not a valid hint";
|
|
|
|
|
} while (succeeded(parser.parseOptionalComma()));
|
|
|
|
|
hintAttr = IntegerAttr::get(parser.getBuilder().getI64Type(), hint);
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Prints a Synchronization Hint clause
|
|
|
|
|
static void printSynchronizationHint(OpAsmPrinter &p, Operation *op,
|
|
|
|
|
IntegerAttr hintAttr) {
|
|
|
|
|
int64_t hint = hintAttr.getInt();
|
|
|
|
|
|
|
|
|
|
if (hint == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Helper function to get n-th bit from the right end of `value`
|
|
|
|
|
auto bitn = [](int value, int n) -> bool { return value & (1 << n); };
|
|
|
|
|
|
|
|
|
|
bool uncontended = bitn(hint, 0);
|
|
|
|
|
bool contended = bitn(hint, 1);
|
|
|
|
|
bool nonspeculative = bitn(hint, 2);
|
|
|
|
|
bool speculative = bitn(hint, 3);
|
|
|
|
|
|
|
|
|
|
SmallVector<StringRef> hints;
|
|
|
|
|
if (uncontended)
|
|
|
|
|
hints.push_back("uncontended");
|
|
|
|
|
if (contended)
|
|
|
|
|
hints.push_back("contended");
|
|
|
|
|
if (nonspeculative)
|
|
|
|
|
hints.push_back("nonspeculative");
|
|
|
|
|
if (speculative)
|
|
|
|
|
hints.push_back("speculative");
|
|
|
|
|
|
|
|
|
|
llvm::interleaveComma(hints, p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Verifies a synchronization hint clause
|
2021-10-27 12:18:00 +05:30
|
|
|
static LogicalResult verifySynchronizationHint(Operation *op, uint64_t hint) {
|
2021-10-19 19:08:29 +05:30
|
|
|
|
|
|
|
|
// Helper function to get n-th bit from the right end of `value`
|
|
|
|
|
auto bitn = [](int value, int n) -> bool { return value & (1 << n); };
|
|
|
|
|
|
|
|
|
|
bool uncontended = bitn(hint, 0);
|
|
|
|
|
bool contended = bitn(hint, 1);
|
|
|
|
|
bool nonspeculative = bitn(hint, 2);
|
|
|
|
|
bool speculative = bitn(hint, 3);
|
|
|
|
|
|
|
|
|
|
if (uncontended && contended)
|
|
|
|
|
return op->emitOpError() << "the hints omp_sync_hint_uncontended and "
|
|
|
|
|
"omp_sync_hint_contended cannot be combined";
|
|
|
|
|
if (nonspeculative && speculative)
|
|
|
|
|
return op->emitOpError() << "the hints omp_sync_hint_nonspeculative and "
|
|
|
|
|
"omp_sync_hint_speculative cannot be combined.";
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 13:36:32 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// ParallelOp
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
void ParallelOp::build(OpBuilder &builder, OperationState &state,
|
|
|
|
|
ArrayRef<NamedAttribute> attributes) {
|
|
|
|
|
ParallelOp::build(
|
|
|
|
|
builder, state, /*if_expr_var=*/nullptr, /*num_threads_var=*/nullptr,
|
|
|
|
|
/*allocate_vars=*/ValueRange(), /*allocators_vars=*/ValueRange(),
|
|
|
|
|
/*reduction_vars=*/ValueRange(), /*reductions=*/nullptr,
|
|
|
|
|
/*proc_bind_val=*/nullptr);
|
|
|
|
|
state.addAttributes(attributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogicalResult ParallelOp::verify() {
|
|
|
|
|
if (allocate_vars().size() != allocators_vars().size())
|
|
|
|
|
return emitError(
|
|
|
|
|
"expected equal sizes for allocate and allocator variables");
|
|
|
|
|
return verifyReductionVarList(*this, reductions(), reduction_vars());
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-06 18:51:35 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
2022-02-21 12:50:58 +05:30
|
|
|
// Verifier for SectionsOp
|
2021-11-06 18:51:35 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult SectionsOp::verify() {
|
|
|
|
|
if (allocate_vars().size() != allocators_vars().size())
|
|
|
|
|
return emitError(
|
2021-11-06 18:51:35 +05:30
|
|
|
"expected equal sizes for allocate and allocator variables");
|
|
|
|
|
|
2022-03-10 22:10:45 +00:00
|
|
|
return verifyReductionVarList(*this, reductions(), reduction_vars());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogicalResult SectionsOp::verifyRegions() {
|
2022-02-02 10:22:57 -08:00
|
|
|
for (auto &inst : *region().begin()) {
|
|
|
|
|
if (!(isa<SectionOp>(inst) || isa<TerminatorOp>(inst))) {
|
|
|
|
|
return emitOpError()
|
|
|
|
|
<< "expected omp.section op or terminator op inside region";
|
|
|
|
|
}
|
2021-11-06 18:51:35 +05:30
|
|
|
}
|
|
|
|
|
|
2022-03-10 22:10:45 +00:00
|
|
|
return success();
|
2021-11-06 18:51:35 +05:30
|
|
|
}
|
|
|
|
|
|
2022-03-23 15:41:09 +05:30
|
|
|
LogicalResult SingleOp::verify() {
|
|
|
|
|
// Check for allocate clause restrictions
|
|
|
|
|
if (allocate_vars().size() != allocators_vars().size())
|
|
|
|
|
return emitError(
|
|
|
|
|
"expected equal sizes for allocate and allocator variables");
|
|
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:37:55 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// WsLoopOp
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
/// loop-control ::= `(` ssa-id-list `)` `:` type `=` loop-bounds
|
2021-10-28 11:04:40 +05:30
|
|
|
/// loop-bounds := `(` ssa-id-list `)` to `(` ssa-id-list `)` inclusive? steps
|
2021-10-19 17:18:51 +05:30
|
|
|
/// steps := `step` `(`ssa-id-list`)`
|
2022-03-23 09:37:55 +05:30
|
|
|
ParseResult
|
|
|
|
|
parseWsLoopControl(OpAsmParser &parser, Region ®ion,
|
|
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &lowerBound,
|
|
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &upperBound,
|
|
|
|
|
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &steps,
|
|
|
|
|
SmallVectorImpl<Type> &loopVarTypes, UnitAttr &inclusive) {
|
2021-10-19 17:18:51 +05:30
|
|
|
// Parse an opening `(` followed by induction variables followed by `)`
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVector<OpAsmParser::UnresolvedOperand> ivs;
|
2021-10-19 17:18:51 +05:30
|
|
|
if (parser.parseRegionArgumentList(ivs, /*requiredOperandCount=*/-1,
|
|
|
|
|
OpAsmParser::Delimiter::Paren))
|
|
|
|
|
return failure();
|
|
|
|
|
|
2022-03-23 09:37:55 +05:30
|
|
|
size_t numIVs = ivs.size();
|
2021-10-19 17:18:51 +05:30
|
|
|
Type loopVarType;
|
|
|
|
|
if (parser.parseColonType(loopVarType))
|
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
|
|
// Parse loop bounds.
|
|
|
|
|
if (parser.parseEqual() ||
|
2022-03-23 09:37:55 +05:30
|
|
|
parser.parseOperandList(lowerBound, numIVs,
|
|
|
|
|
OpAsmParser::Delimiter::Paren))
|
2021-10-19 17:18:51 +05:30
|
|
|
return failure();
|
|
|
|
|
if (parser.parseKeyword("to") ||
|
2022-03-23 09:37:55 +05:30
|
|
|
parser.parseOperandList(upperBound, numIVs,
|
|
|
|
|
OpAsmParser::Delimiter::Paren))
|
2021-10-19 17:18:51 +05:30
|
|
|
return failure();
|
|
|
|
|
|
2021-10-28 11:04:40 +05:30
|
|
|
if (succeeded(parser.parseOptionalKeyword("inclusive"))) {
|
2022-03-23 09:37:55 +05:30
|
|
|
inclusive = UnitAttr::get(parser.getBuilder().getContext());
|
2021-10-28 11:04:40 +05:30
|
|
|
}
|
|
|
|
|
|
2021-10-19 17:18:51 +05:30
|
|
|
// Parse step values.
|
|
|
|
|
if (parser.parseKeyword("step") ||
|
2022-03-23 09:37:55 +05:30
|
|
|
parser.parseOperandList(steps, numIVs, OpAsmParser::Delimiter::Paren))
|
2021-10-19 17:18:51 +05:30
|
|
|
return failure();
|
|
|
|
|
|
2021-03-17 08:55:42 +00:00
|
|
|
// Now parse the body.
|
2022-03-23 09:37:55 +05:30
|
|
|
loopVarTypes = SmallVector<Type>(numIVs, loopVarType);
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVector<OpAsmParser::UnresolvedOperand> blockArgs(ivs);
|
2022-03-23 09:37:55 +05:30
|
|
|
if (parser.parseRegion(region, blockArgs, loopVarTypes))
|
2021-03-17 08:55:42 +00:00
|
|
|
return failure();
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:37:55 +05:30
|
|
|
void printWsLoopControl(OpAsmPrinter &p, Operation *op, Region ®ion,
|
|
|
|
|
ValueRange lowerBound, ValueRange upperBound,
|
|
|
|
|
ValueRange steps, TypeRange loopVarTypes,
|
|
|
|
|
UnitAttr inclusive) {
|
|
|
|
|
auto args = region.front().getArguments();
|
|
|
|
|
p << " (" << args << ") : " << args[0].getType() << " = (" << lowerBound
|
|
|
|
|
<< ") to (" << upperBound << ") ";
|
|
|
|
|
if (inclusive)
|
2021-10-28 11:04:40 +05:30
|
|
|
p << "inclusive ";
|
2022-03-23 09:37:55 +05:30
|
|
|
p << "step (" << steps << ") ";
|
|
|
|
|
p.printRegion(region, /*printEntryBlockArgs=*/false);
|
2021-03-17 08:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-15 09:41:04 -04:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// SimdLoopOp
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
/// Parses an OpenMP Simd construct [2.9.3.1]
|
|
|
|
|
///
|
|
|
|
|
/// simdloop ::= `omp.simdloop` loop-control clause-list
|
|
|
|
|
/// loop-control ::= `(` ssa-id-list `)` `:` type `=` loop-bounds
|
|
|
|
|
/// loop-bounds := `(` ssa-id-list `)` to `(` ssa-id-list `)` steps
|
|
|
|
|
/// steps := `step` `(`ssa-id-list`)`
|
|
|
|
|
/// clause-list ::= clause clause-list | empty
|
|
|
|
|
/// clause ::= TODO
|
|
|
|
|
ParseResult SimdLoopOp::parse(OpAsmParser &parser, OperationState &result) {
|
|
|
|
|
// Parse an opening `(` followed by induction variables followed by `)`
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVector<OpAsmParser::UnresolvedOperand> ivs;
|
2022-03-15 09:41:04 -04:00
|
|
|
if (parser.parseRegionArgumentList(ivs, /*requiredOperandCount=*/-1,
|
|
|
|
|
OpAsmParser::Delimiter::Paren))
|
|
|
|
|
return failure();
|
|
|
|
|
int numIVs = static_cast<int>(ivs.size());
|
|
|
|
|
Type loopVarType;
|
|
|
|
|
if (parser.parseColonType(loopVarType))
|
|
|
|
|
return failure();
|
|
|
|
|
// Parse loop bounds.
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVector<OpAsmParser::UnresolvedOperand> lower;
|
2022-03-15 09:41:04 -04:00
|
|
|
if (parser.parseEqual() ||
|
|
|
|
|
parser.parseOperandList(lower, numIVs, OpAsmParser::Delimiter::Paren) ||
|
|
|
|
|
parser.resolveOperands(lower, loopVarType, result.operands))
|
|
|
|
|
return failure();
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVector<OpAsmParser::UnresolvedOperand> upper;
|
2022-03-15 09:41:04 -04:00
|
|
|
if (parser.parseKeyword("to") ||
|
|
|
|
|
parser.parseOperandList(upper, numIVs, OpAsmParser::Delimiter::Paren) ||
|
|
|
|
|
parser.resolveOperands(upper, loopVarType, result.operands))
|
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
|
|
// Parse step values.
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVector<OpAsmParser::UnresolvedOperand> steps;
|
2022-03-15 09:41:04 -04:00
|
|
|
if (parser.parseKeyword("step") ||
|
|
|
|
|
parser.parseOperandList(steps, numIVs, OpAsmParser::Delimiter::Paren) ||
|
|
|
|
|
parser.resolveOperands(steps, loopVarType, result.operands))
|
|
|
|
|
return failure();
|
|
|
|
|
|
|
|
|
|
SmallVector<int> segments{numIVs, numIVs, numIVs};
|
|
|
|
|
// TODO: Add parseClauses() when we support clauses
|
|
|
|
|
result.addAttribute("operand_segment_sizes",
|
|
|
|
|
parser.getBuilder().getI32VectorAttr(segments));
|
|
|
|
|
|
|
|
|
|
// Now parse the body.
|
|
|
|
|
Region *body = result.addRegion();
|
|
|
|
|
SmallVector<Type> ivTypes(numIVs, loopVarType);
|
2022-03-21 21:42:13 +01:00
|
|
|
SmallVector<OpAsmParser::UnresolvedOperand> blockArgs(ivs);
|
2022-03-15 09:41:04 -04:00
|
|
|
if (parser.parseRegion(*body, blockArgs, ivTypes))
|
|
|
|
|
return failure();
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimdLoopOp::print(OpAsmPrinter &p) {
|
|
|
|
|
auto args = getRegion().front().getArguments();
|
|
|
|
|
p << " (" << args << ") : " << args[0].getType() << " = (" << lowerBound()
|
|
|
|
|
<< ") to (" << upperBound() << ") ";
|
|
|
|
|
p << "step (" << step() << ") ";
|
|
|
|
|
|
|
|
|
|
p.printRegion(region(), /*printEntryBlockArgs=*/false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Verifier for Simd construct [2.9.3.1]
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
LogicalResult SimdLoopOp::verify() {
|
|
|
|
|
if (this->lowerBound().empty()) {
|
|
|
|
|
return emitOpError() << "empty lowerbound for simd loop operation";
|
|
|
|
|
}
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-08 10:59:02 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// ReductionOp
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
static ParseResult parseAtomicReductionRegion(OpAsmParser &parser,
|
|
|
|
|
Region ®ion) {
|
|
|
|
|
if (parser.parseOptionalKeyword("atomic"))
|
|
|
|
|
return success();
|
|
|
|
|
return parser.parseRegion(region);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void printAtomicReductionRegion(OpAsmPrinter &printer,
|
|
|
|
|
ReductionDeclareOp op, Region ®ion) {
|
|
|
|
|
if (region.empty())
|
|
|
|
|
return;
|
|
|
|
|
printer << "atomic ";
|
|
|
|
|
printer.printRegion(region);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 22:10:45 +00:00
|
|
|
LogicalResult ReductionDeclareOp::verifyRegions() {
|
2022-02-02 10:22:57 -08:00
|
|
|
if (initializerRegion().empty())
|
|
|
|
|
return emitOpError() << "expects non-empty initializer region";
|
|
|
|
|
Block &initializerEntryBlock = initializerRegion().front();
|
2021-07-08 10:59:02 +02:00
|
|
|
if (initializerEntryBlock.getNumArguments() != 1 ||
|
2022-02-02 10:22:57 -08:00
|
|
|
initializerEntryBlock.getArgument(0).getType() != type()) {
|
|
|
|
|
return emitOpError() << "expects initializer region with one argument "
|
|
|
|
|
"of the reduction type";
|
2021-07-08 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
for (YieldOp yieldOp : initializerRegion().getOps<YieldOp>()) {
|
2021-07-08 10:59:02 +02:00
|
|
|
if (yieldOp.results().size() != 1 ||
|
2022-02-02 10:22:57 -08:00
|
|
|
yieldOp.results().getTypes()[0] != type())
|
|
|
|
|
return emitOpError() << "expects initializer region to yield a value "
|
|
|
|
|
"of the reduction type";
|
2021-07-08 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
if (reductionRegion().empty())
|
|
|
|
|
return emitOpError() << "expects non-empty reduction region";
|
|
|
|
|
Block &reductionEntryBlock = reductionRegion().front();
|
2021-07-08 10:59:02 +02:00
|
|
|
if (reductionEntryBlock.getNumArguments() != 2 ||
|
|
|
|
|
reductionEntryBlock.getArgumentTypes()[0] !=
|
|
|
|
|
reductionEntryBlock.getArgumentTypes()[1] ||
|
2022-02-02 10:22:57 -08:00
|
|
|
reductionEntryBlock.getArgumentTypes()[0] != type())
|
|
|
|
|
return emitOpError() << "expects reduction region with two arguments of "
|
|
|
|
|
"the reduction type";
|
|
|
|
|
for (YieldOp yieldOp : reductionRegion().getOps<YieldOp>()) {
|
2021-07-08 10:59:02 +02:00
|
|
|
if (yieldOp.results().size() != 1 ||
|
2022-02-02 10:22:57 -08:00
|
|
|
yieldOp.results().getTypes()[0] != type())
|
|
|
|
|
return emitOpError() << "expects reduction region to yield a value "
|
|
|
|
|
"of the reduction type";
|
2021-07-08 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
if (atomicReductionRegion().empty())
|
2021-07-08 10:59:02 +02:00
|
|
|
return success();
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
Block &atomicReductionEntryBlock = atomicReductionRegion().front();
|
2021-07-08 10:59:02 +02:00
|
|
|
if (atomicReductionEntryBlock.getNumArguments() != 2 ||
|
|
|
|
|
atomicReductionEntryBlock.getArgumentTypes()[0] !=
|
|
|
|
|
atomicReductionEntryBlock.getArgumentTypes()[1])
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitOpError() << "expects atomic reduction region with two "
|
|
|
|
|
"arguments of the same type";
|
2021-07-08 10:59:02 +02:00
|
|
|
auto ptrType = atomicReductionEntryBlock.getArgumentTypes()[0]
|
|
|
|
|
.dyn_cast<PointerLikeType>();
|
2022-02-02 10:22:57 -08:00
|
|
|
if (!ptrType || ptrType.getElementType() != type())
|
|
|
|
|
return emitOpError() << "expects atomic reduction region arguments to "
|
|
|
|
|
"be accumulators containing the reduction type";
|
2021-07-08 10:59:02 +02:00
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult ReductionOp::verify() {
|
2022-03-28 13:36:32 +05:30
|
|
|
auto *op = (*this)->getParentWithTrait<ReductionClauseInterface::Trait>();
|
|
|
|
|
if (!op)
|
|
|
|
|
return emitOpError() << "must be used within an operation supporting "
|
|
|
|
|
"reduction clause interface";
|
|
|
|
|
while (op) {
|
|
|
|
|
for (const auto &var :
|
|
|
|
|
cast<ReductionClauseInterface>(op).getReductionVars())
|
|
|
|
|
if (var == accumulator())
|
|
|
|
|
return success();
|
|
|
|
|
op = op->getParentWithTrait<ReductionClauseInterface::Trait>();
|
|
|
|
|
}
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitOpError() << "the accumulator is not used by the parent";
|
2021-07-08 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-12 23:50:27 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// TaskOp
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
LogicalResult TaskOp::verify() {
|
|
|
|
|
return verifyReductionVarList(*this, in_reductions(), in_reduction_vars());
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 20:29:27 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// WsLoopOp
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
void WsLoopOp::build(OpBuilder &builder, OperationState &state,
|
|
|
|
|
ValueRange lowerBound, ValueRange upperBound,
|
|
|
|
|
ValueRange step, ArrayRef<NamedAttribute> attributes) {
|
2022-02-28 14:08:31 +05:30
|
|
|
build(builder, state, lowerBound, upperBound, step,
|
|
|
|
|
/*linear_vars=*/ValueRange(),
|
|
|
|
|
/*linear_step_vars=*/ValueRange(), /*reduction_vars=*/ValueRange(),
|
|
|
|
|
/*reductions=*/nullptr, /*schedule_val=*/nullptr,
|
|
|
|
|
/*schedule_chunk_var=*/nullptr, /*schedule_modifier=*/nullptr,
|
|
|
|
|
/*simd_modifier=*/false, /*collapse_val=*/nullptr, /*nowait=*/false,
|
|
|
|
|
/*ordered_val=*/nullptr, /*order_val=*/nullptr, /*inclusive=*/false);
|
2021-03-17 08:55:42 +00:00
|
|
|
state.addAttributes(attributes);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult WsLoopOp::verify() {
|
|
|
|
|
return verifyReductionVarList(*this, reductions(), reduction_vars());
|
2021-07-08 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-12 10:47:30 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Verifier for critical construct (2.17.1)
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult CriticalDeclareOp::verify() {
|
2022-03-02 10:53:53 +05:30
|
|
|
return verifySynchronizationHint(*this, hint_val());
|
2021-10-20 18:02:21 +05:30
|
|
|
}
|
2021-10-12 10:47:30 +00:00
|
|
|
|
2022-03-10 22:10:45 +00:00
|
|
|
LogicalResult
|
|
|
|
|
CriticalOp::verifySymbolUses(SymbolTableCollection &symbol_table) {
|
2022-02-02 10:22:57 -08:00
|
|
|
if (nameAttr()) {
|
|
|
|
|
SymbolRefAttr symbolRef = nameAttr();
|
2022-03-10 22:10:45 +00:00
|
|
|
auto decl = symbol_table.lookupNearestSymbolFrom<CriticalDeclareOp>(
|
2022-02-02 10:22:57 -08:00
|
|
|
*this, symbolRef);
|
2021-09-02 14:17:07 +00:00
|
|
|
if (!decl) {
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitOpError() << "expected symbol reference " << symbolRef
|
|
|
|
|
<< " to point to a critical declaration";
|
2021-09-02 14:17:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 22:06:39 +01:00
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 16:30:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// Verifier for ordered construct
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult OrderedOp::verify() {
|
|
|
|
|
auto container = (*this)->getParentOfType<WsLoopOp>();
|
2021-10-21 16:30:46 +08:00
|
|
|
if (!container || !container.ordered_valAttr() ||
|
|
|
|
|
container.ordered_valAttr().getInt() == 0)
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitOpError() << "ordered depend directive must be closely "
|
|
|
|
|
<< "nested inside a worksharing-loop with ordered "
|
|
|
|
|
<< "clause with parameter present";
|
2021-10-21 16:30:46 +08:00
|
|
|
|
|
|
|
|
if (container.ordered_valAttr().getInt() !=
|
2022-02-02 10:22:57 -08:00
|
|
|
(int64_t)num_loops_val().getValue())
|
|
|
|
|
return emitOpError() << "number of variables in depend clause does not "
|
|
|
|
|
<< "match number of iteration variables in the "
|
|
|
|
|
<< "doacross loop";
|
2021-10-21 16:30:46 +08:00
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult OrderedRegionOp::verify() {
|
2021-10-21 16:30:46 +08:00
|
|
|
// TODO: The code generation for ordered simd directive is not supported yet.
|
2022-02-02 10:22:57 -08:00
|
|
|
if (simd())
|
2021-10-21 16:30:46 +08:00
|
|
|
return failure();
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
if (auto container = (*this)->getParentOfType<WsLoopOp>()) {
|
2021-10-21 16:30:46 +08:00
|
|
|
if (!container.ordered_valAttr() ||
|
|
|
|
|
container.ordered_valAttr().getInt() != 0)
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitOpError() << "ordered region must be closely nested inside "
|
|
|
|
|
<< "a worksharing-loop region with an ordered "
|
|
|
|
|
<< "clause without parameter present";
|
2021-10-21 16:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 12:18:00 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
2022-03-02 10:53:53 +05:30
|
|
|
// Verifier for AtomicReadOp
|
2021-10-27 12:18:00 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult AtomicReadOp::verify() {
|
2022-03-02 10:53:53 +05:30
|
|
|
if (auto mo = memory_order_val()) {
|
2022-03-09 15:03:17 +05:30
|
|
|
if (*mo == ClauseMemoryOrderKind::Acq_rel ||
|
|
|
|
|
*mo == ClauseMemoryOrderKind::Release) {
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitError(
|
2021-10-27 12:18:00 +05:30
|
|
|
"memory-order must not be acq_rel or release for atomic reads");
|
2022-01-18 16:53:55 +00:00
|
|
|
}
|
2021-10-27 12:18:00 +05:30
|
|
|
}
|
2022-02-02 10:22:57 -08:00
|
|
|
if (x() == v())
|
|
|
|
|
return emitError(
|
2022-01-10 15:26:20 +05:30
|
|
|
"read and write must not be to the same location for atomic reads");
|
2022-03-02 10:53:53 +05:30
|
|
|
return verifySynchronizationHint(*this, hint_val());
|
2021-10-27 12:18:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2022-03-02 10:53:53 +05:30
|
|
|
// Verifier for AtomicWriteOp
|
2021-10-27 12:18:00 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult AtomicWriteOp::verify() {
|
2022-03-02 10:53:53 +05:30
|
|
|
if (auto mo = memory_order_val()) {
|
2022-03-09 15:03:17 +05:30
|
|
|
if (*mo == ClauseMemoryOrderKind::Acq_rel ||
|
|
|
|
|
*mo == ClauseMemoryOrderKind::Acquire) {
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitError(
|
2021-10-27 12:18:00 +05:30
|
|
|
"memory-order must not be acq_rel or acquire for atomic writes");
|
2022-01-18 16:53:55 +00:00
|
|
|
}
|
2021-10-27 12:18:00 +05:30
|
|
|
}
|
2022-03-02 10:53:53 +05:30
|
|
|
return verifySynchronizationHint(*this, hint_val());
|
2021-10-27 12:18:00 +05:30
|
|
|
}
|
|
|
|
|
|
2021-12-09 11:05:55 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
2022-03-02 10:53:53 +05:30
|
|
|
// Verifier for AtomicUpdateOp
|
2021-12-09 11:05:55 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-02-02 10:22:57 -08:00
|
|
|
LogicalResult AtomicUpdateOp::verify() {
|
2022-03-02 10:53:53 +05:30
|
|
|
if (auto mo = memory_order_val()) {
|
2022-03-09 15:03:17 +05:30
|
|
|
if (*mo == ClauseMemoryOrderKind::Acq_rel ||
|
|
|
|
|
*mo == ClauseMemoryOrderKind::Acquire) {
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitError(
|
2021-12-09 11:05:55 +05:30
|
|
|
"memory-order must not be acq_rel or acquire for atomic updates");
|
2022-01-18 16:53:55 +00:00
|
|
|
}
|
2021-12-09 11:05:55 +05:30
|
|
|
}
|
2022-02-15 17:31:31 +05:30
|
|
|
|
|
|
|
|
if (x().getType().cast<PointerLikeType>().getElementType() !=
|
|
|
|
|
region().getArgument(0).getType()) {
|
|
|
|
|
return emitError("the type of the operand must be a pointer type whose "
|
|
|
|
|
"element type is the same as that of the region argument");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 22:10:45 +00:00
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogicalResult AtomicUpdateOp::verifyRegions() {
|
|
|
|
|
if (region().getNumArguments() != 1)
|
|
|
|
|
return emitError("the region must accept exactly one argument");
|
|
|
|
|
|
2022-03-10 18:28:08 +05:30
|
|
|
if (region().front().getOperations().size() < 2)
|
|
|
|
|
return emitError() << "the update region must have at least two operations "
|
|
|
|
|
"(binop and terminator)";
|
|
|
|
|
|
2022-02-15 17:31:31 +05:30
|
|
|
YieldOp yieldOp = *region().getOps<YieldOp>().begin();
|
|
|
|
|
|
|
|
|
|
if (yieldOp.results().size() != 1)
|
|
|
|
|
return emitError("only updated value must be returned");
|
|
|
|
|
if (yieldOp.results().front().getType() != region().getArgument(0).getType())
|
|
|
|
|
return emitError("input and yielded value must have the same type");
|
2021-12-09 11:05:55 +05:30
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 18:42:39 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
2022-03-02 10:53:53 +05:30
|
|
|
// Verifier for AtomicCaptureOp
|
2022-01-24 18:42:39 +05:30
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-03-21 16:20:54 +05:30
|
|
|
Operation *AtomicCaptureOp::getFirstOp() {
|
|
|
|
|
return &getRegion().front().getOperations().front();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Operation *AtomicCaptureOp::getSecondOp() {
|
|
|
|
|
auto &ops = getRegion().front().getOperations();
|
|
|
|
|
return ops.getNextNode(ops.front());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AtomicReadOp AtomicCaptureOp::getAtomicReadOp() {
|
|
|
|
|
if (auto op = dyn_cast<AtomicReadOp>(getFirstOp()))
|
|
|
|
|
return op;
|
|
|
|
|
return dyn_cast<AtomicReadOp>(getSecondOp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AtomicWriteOp AtomicCaptureOp::getAtomicWriteOp() {
|
|
|
|
|
if (auto op = dyn_cast<AtomicWriteOp>(getFirstOp()))
|
|
|
|
|
return op;
|
|
|
|
|
return dyn_cast<AtomicWriteOp>(getSecondOp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AtomicUpdateOp AtomicCaptureOp::getAtomicUpdateOp() {
|
|
|
|
|
if (auto op = dyn_cast<AtomicUpdateOp>(getFirstOp()))
|
|
|
|
|
return op;
|
|
|
|
|
return dyn_cast<AtomicUpdateOp>(getSecondOp());
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 22:10:45 +00:00
|
|
|
LogicalResult AtomicCaptureOp::verifyRegions() {
|
2022-02-02 10:22:57 -08:00
|
|
|
Block::OpListType &ops = region().front().getOperations();
|
2022-01-24 18:42:39 +05:30
|
|
|
if (ops.size() != 3)
|
2022-02-02 10:22:57 -08:00
|
|
|
return emitError()
|
2022-01-24 18:42:39 +05:30
|
|
|
<< "expected three operations in omp.atomic.capture region (one "
|
|
|
|
|
"terminator, and two atomic ops)";
|
|
|
|
|
auto &firstOp = ops.front();
|
|
|
|
|
auto &secondOp = *ops.getNextNode(firstOp);
|
|
|
|
|
auto firstReadStmt = dyn_cast<AtomicReadOp>(firstOp);
|
|
|
|
|
auto firstUpdateStmt = dyn_cast<AtomicUpdateOp>(firstOp);
|
|
|
|
|
auto secondReadStmt = dyn_cast<AtomicReadOp>(secondOp);
|
|
|
|
|
auto secondUpdateStmt = dyn_cast<AtomicUpdateOp>(secondOp);
|
|
|
|
|
auto secondWriteStmt = dyn_cast<AtomicWriteOp>(secondOp);
|
|
|
|
|
|
|
|
|
|
if (!((firstUpdateStmt && secondReadStmt) ||
|
|
|
|
|
(firstReadStmt && secondUpdateStmt) ||
|
|
|
|
|
(firstReadStmt && secondWriteStmt)))
|
2022-02-02 10:22:57 -08:00
|
|
|
return ops.front().emitError()
|
2022-01-24 18:42:39 +05:30
|
|
|
<< "invalid sequence of operations in the capture region";
|
|
|
|
|
if (firstUpdateStmt && secondReadStmt &&
|
|
|
|
|
firstUpdateStmt.x() != secondReadStmt.x())
|
2022-02-02 10:22:57 -08:00
|
|
|
return firstUpdateStmt.emitError()
|
2022-01-24 18:42:39 +05:30
|
|
|
<< "updated variable in omp.atomic.update must be captured in "
|
|
|
|
|
"second operation";
|
|
|
|
|
if (firstReadStmt && secondUpdateStmt &&
|
|
|
|
|
firstReadStmt.x() != secondUpdateStmt.x())
|
2022-02-02 10:22:57 -08:00
|
|
|
return firstReadStmt.emitError()
|
2022-01-24 18:42:39 +05:30
|
|
|
<< "captured variable in omp.atomic.read must be updated in second "
|
|
|
|
|
"operation";
|
|
|
|
|
if (firstReadStmt && secondWriteStmt &&
|
|
|
|
|
firstReadStmt.x() != secondWriteStmt.address())
|
2022-02-02 10:22:57 -08:00
|
|
|
return firstReadStmt.emitError()
|
2022-01-24 18:42:39 +05:30
|
|
|
<< "captured variable in omp.atomic.read must be updated in "
|
|
|
|
|
"second operation";
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 16:53:55 +00:00
|
|
|
#define GET_ATTRDEF_CLASSES
|
|
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
|
|
|
|
|
|
[MLIR] Add OpenMP dialect with barrier operation
Summary:
Barrier is a simple operation that takes no arguments and returns
nothing, but implies a side effect (synchronization of all threads)
Reviewers: jdoerfert
Subscribers: mgorny, guansong, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72400
2020-01-29 11:31:25 +00:00
|
|
|
#define GET_OP_CLASSES
|
|
|
|
|
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
|