26#include "llvm/ADT/ArrayRef.h"
27#include "llvm/ADT/PostOrderIterator.h"
28#include "llvm/ADT/STLExtras.h"
29#include "llvm/ADT/STLForwardCompat.h"
30#include "llvm/ADT/SmallString.h"
31#include "llvm/ADT/StringExtras.h"
32#include "llvm/ADT/StringRef.h"
33#include "llvm/ADT/TypeSwitch.h"
34#include "llvm/ADT/bit.h"
35#include "llvm/Support/InterleavedRange.h"
41#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
42#include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc"
43#include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.cpp.inc"
44#include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.cpp.inc"
51 return attrs.empty() ?
nullptr : ArrayAttr::get(context, attrs);
65struct MemRefPointerLikeModel
66 :
public PointerLikeType::ExternalModel<MemRefPointerLikeModel,
69 return llvm::cast<MemRefType>(pointer).getElementType();
73struct LLVMPointerPointerLikeModel
74 :
public PointerLikeType::ExternalModel<LLVMPointerPointerLikeModel,
75 LLVM::LLVMPointerType> {
100 bool isRegionArgOfOp;
110 assert(isRegionArgOfOp &&
"Must describe a region operand");
113 size_t &getArgIdx() {
114 assert(isRegionArgOfOp &&
"Must describe a region operand");
119 assert(!isRegionArgOfOp &&
"Must describe a operation of a region");
123 assert(!isRegionArgOfOp &&
"Must describe a operation of a region");
126 bool isLoopOp()
const {
127 assert(!isRegionArgOfOp &&
"Must describe a operation of a region");
128 return isa<CanonicalLoopOp>(op);
130 Region *&getParentRegion() {
131 assert(!isRegionArgOfOp &&
"Must describe a operation of a region");
134 size_t &getLoopDepth() {
135 assert(!isRegionArgOfOp &&
"Must describe a operation of a region");
139 void skipIf(
bool v =
true) { skip = skip || v; }
157 llvm::ReversePostOrderTraversal<Block *> traversal(&r->
getBlocks().front());
160 size_t sequentialIdx = -1;
161 bool isOnlyContainerOp =
true;
162 for (
Block *
b : traversal) {
164 if (&op == o && !found) {
168 if (op.getNumRegions()) {
171 isOnlyContainerOp =
false;
173 if (found && !isOnlyContainerOp)
178 Component &containerOpInRegion = components.emplace_back();
179 containerOpInRegion.isRegionArgOfOp =
false;
180 containerOpInRegion.isUnique = isOnlyContainerOp;
181 containerOpInRegion.getContainerOp() = o;
182 containerOpInRegion.getOpPos() = sequentialIdx;
183 containerOpInRegion.getParentRegion() = r;
188 Component ®ionArgOfOperation = components.emplace_back();
189 regionArgOfOperation.isRegionArgOfOp =
true;
190 regionArgOfOperation.isUnique =
true;
191 regionArgOfOperation.getArgIdx() = 0;
192 regionArgOfOperation.getOwnerOp() = parent;
204 for (
auto [idx, region] : llvm::enumerate(o->
getRegions())) {
208 llvm_unreachable(
"Region not child of its parent operation");
210 regionArgOfOperation.isUnique =
false;
211 regionArgOfOperation.getArgIdx() = getRegionIndex(parent, r);
219 for (Component &c : components)
220 c.skipIf(c.isRegionArgOfOp && c.isUnique);
223 size_t numSurroundingLoops = 0;
224 for (Component &c : llvm::reverse(components)) {
229 if (c.isRegionArgOfOp) {
230 numSurroundingLoops = 0;
237 numSurroundingLoops = 0;
239 c.getLoopDepth() = numSurroundingLoops;
242 if (isa<CanonicalLoopOp>(c.getContainerOp()))
243 numSurroundingLoops += 1;
248 bool isLoopNest =
false;
249 for (Component &c : components) {
250 if (c.skip || c.isRegionArgOfOp)
253 if (!isLoopNest && c.getLoopDepth() >= 1) {
256 }
else if (isLoopNest) {
258 c.skipIf(c.isUnique);
262 if (c.getLoopDepth() == 0)
269 for (Component &c : components)
270 c.skipIf(!c.isRegionArgOfOp && c.isUnique &&
271 !isa<CanonicalLoopOp>(c.getContainerOp()));
275 bool newRegion =
true;
276 for (Component &c : llvm::reverse(components)) {
277 c.skipIf(newRegion && c.isUnique);
284 if (!c.isRegionArgOfOp && c.getContainerOp())
290 llvm::raw_svector_ostream NameOS(Name);
291 for (
auto &c : llvm::reverse(components)) {
295 if (c.isRegionArgOfOp)
296 NameOS <<
"_r" << c.getArgIdx();
297 else if (c.getLoopDepth() >= 1)
298 NameOS <<
"_d" << c.getLoopDepth();
300 NameOS <<
"_s" << c.getOpPos();
303 return NameOS.str().str();
306void OpenMPDialect::initialize() {
309#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
312#define GET_ATTRDEF_LIST
313#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
316#define GET_TYPEDEF_LIST
317#include "mlir/Dialect/OpenMP/OpenMPOpsTypes.cpp.inc"
320 declarePromisedInterface<ConvertToLLVMPatternInterface, OpenMPDialect>();
322 MemRefType::attachInterface<MemRefPointerLikeModel>(*
getContext());
323 LLVM::LLVMPointerType::attachInterface<LLVMPointerPointerLikeModel>(
328 mlir::ModuleOp::attachInterface<mlir::omp::OffloadModuleDefaultModel>(
334 mlir::LLVM::GlobalOp::attachInterface<
337 mlir::LLVM::LLVMFuncOp::attachInterface<
340 mlir::func::FuncOp::attachInterface<
366 allocatorVars.push_back(operand);
367 allocatorTypes.push_back(type);
373 allocateVars.push_back(operand);
374 allocateTypes.push_back(type);
385 for (
unsigned i = 0; i < allocateVars.size(); ++i) {
386 std::string separator = i == allocateVars.size() - 1 ?
"" :
", ";
387 p << allocatorVars[i] <<
" : " << allocatorTypes[i] <<
" -> ";
388 p << allocateVars[i] <<
" : " << allocateTypes[i] << separator;
396template <
typename ClauseAttr>
398 using ClauseT =
decltype(std::declval<ClauseAttr>().getValue());
403 if (std::optional<ClauseT> enumValue = symbolizeEnum<ClauseT>(enumStr)) {
404 attr = ClauseAttr::get(parser.
getContext(), *enumValue);
407 return parser.
emitError(loc,
"invalid clause value: '") << enumStr <<
"'";
410template <
typename ClauseAttr>
412 p << stringifyEnum(attr.getValue());
435 linearVars.push_back(var);
436 linearTypes.push_back(type);
437 linearStepVars.push_back(stepVar);
446 size_t linearVarsSize = linearVars.size();
447 for (
unsigned i = 0; i < linearVarsSize; ++i) {
448 std::string separator = i == linearVarsSize - 1 ?
"" :
", ";
450 if (linearStepVars.size() > i)
451 p <<
" = " << linearStepVars[i];
452 p <<
" : " << linearVars[i].getType() << separator;
465 for (
const auto &it : nontemporalVars)
466 if (!nontemporalItems.insert(it).second)
467 return op->
emitOpError() <<
"nontemporal variable used more than once";
476 std::optional<ArrayAttr> alignments,
479 if (!alignedVars.empty()) {
480 if (!alignments || alignments->size() != alignedVars.size())
482 <<
"expected as many alignment values as aligned variables";
485 return op->
emitOpError() <<
"unexpected alignment values attribute";
491 for (
auto it : alignedVars)
492 if (!alignedItems.insert(it).second)
493 return op->
emitOpError() <<
"aligned variable used more than once";
499 for (
unsigned i = 0; i < (*alignments).size(); ++i) {
500 if (
auto intAttr = llvm::dyn_cast<IntegerAttr>((*alignments)[i])) {
501 if (intAttr.getValue().sle(0))
502 return op->
emitOpError() <<
"alignment should be greater than 0";
504 return op->
emitOpError() <<
"expected integer alignment";
521 if (parser.parseOperand(alignedVars.emplace_back()) ||
522 parser.parseColonType(alignedTypes.emplace_back()) ||
523 parser.parseArrow() ||
524 parser.parseAttribute(alignmentVec.emplace_back())) {
531 alignmentsAttr = ArrayAttr::get(parser.getContext(), alignments);
538 std::optional<ArrayAttr> alignments) {
539 for (
unsigned i = 0; i < alignedVars.size(); ++i) {
542 p << alignedVars[i] <<
" : " << alignedVars[i].
getType();
543 p <<
" -> " << (*alignments)[i];
554 if (modifiers.size() > 2)
556 for (
const auto &mod : modifiers) {
559 auto symbol = symbolizeScheduleModifier(mod);
562 <<
" unknown modifier type: " << mod;
567 if (modifiers.size() == 1) {
568 if (symbolizeScheduleModifier(modifiers[0]) == ScheduleModifier::simd) {
569 modifiers.push_back(modifiers[0]);
570 modifiers[0] = stringifyScheduleModifier(ScheduleModifier::none);
572 }
else if (modifiers.size() == 2) {
575 if (symbolizeScheduleModifier(modifiers[0]) == ScheduleModifier::simd ||
576 symbolizeScheduleModifier(modifiers[1]) != ScheduleModifier::simd)
578 <<
" incorrect modifier order";
594 ScheduleModifierAttr &scheduleMod, UnitAttr &scheduleSimd,
595 std::optional<OpAsmParser::UnresolvedOperand> &chunkSize,
600 std::optional<mlir::omp::ClauseScheduleKind> schedule =
601 symbolizeClauseScheduleKind(keyword);
605 scheduleAttr = ClauseScheduleKindAttr::get(parser.
getContext(), *schedule);
607 case ClauseScheduleKind::Static:
608 case ClauseScheduleKind::Dynamic:
609 case ClauseScheduleKind::Guided:
615 chunkSize = std::nullopt;
618 case ClauseScheduleKind::Auto:
619 case ClauseScheduleKind::Runtime:
620 case ClauseScheduleKind::Distribute:
621 chunkSize = std::nullopt;
630 modifiers.push_back(mod);
636 if (!modifiers.empty()) {
638 if (std::optional<ScheduleModifier> mod =
639 symbolizeScheduleModifier(modifiers[0])) {
640 scheduleMod = ScheduleModifierAttr::get(parser.
getContext(), *mod);
642 return parser.
emitError(loc,
"invalid schedule modifier");
645 if (modifiers.size() > 1) {
646 assert(symbolizeScheduleModifier(modifiers[1]) == ScheduleModifier::simd);
656 ClauseScheduleKindAttr scheduleKind,
657 ScheduleModifierAttr scheduleMod,
658 UnitAttr scheduleSimd,
Value scheduleChunk,
659 Type scheduleChunkType) {
660 p << stringifyClauseScheduleKind(scheduleKind.getValue());
662 p <<
" = " << scheduleChunk <<
" : " << scheduleChunk.
getType();
664 p <<
", " << stringifyScheduleModifier(scheduleMod.getValue());
676 ClauseOrderKindAttr &order,
677 OrderModifierAttr &orderMod) {
682 if (std::optional<OrderModifier> enumValue =
683 symbolizeOrderModifier(enumStr)) {
684 orderMod = OrderModifierAttr::get(parser.
getContext(), *enumValue);
691 if (std::optional<ClauseOrderKind> enumValue =
692 symbolizeClauseOrderKind(enumStr)) {
693 order = ClauseOrderKindAttr::get(parser.
getContext(), *enumValue);
696 return parser.
emitError(loc,
"invalid clause value: '") << enumStr <<
"'";
700 ClauseOrderKindAttr order,
701 OrderModifierAttr orderMod) {
703 p << stringifyOrderModifier(orderMod.getValue()) <<
":";
705 p << stringifyClauseOrderKind(order.getValue());
708template <
typename ClauseTypeAttr,
typename ClauseType>
711 std::optional<OpAsmParser::UnresolvedOperand> &operand,
713 std::optional<ClauseType> (*symbolizeClause)(StringRef),
714 StringRef clauseName) {
717 if (std::optional<ClauseType> enumValue = symbolizeClause(enumStr)) {
718 prescriptiveness = ClauseTypeAttr::get(parser.
getContext(), *enumValue);
723 <<
"invalid " << clauseName <<
" modifier : '" << enumStr <<
"'";
733 <<
"expected " << clauseName <<
" operand";
736 if (operand.has_value()) {
744template <
typename ClauseTypeAttr,
typename ClauseType>
747 ClauseTypeAttr prescriptiveness,
Value operand,
749 StringRef (*stringifyClauseType)(ClauseType)) {
751 if (prescriptiveness)
752 p << stringifyClauseType(prescriptiveness.getValue()) <<
", ";
755 p << operand <<
": " << operandType;
765 std::optional<OpAsmParser::UnresolvedOperand> &grainsize,
766 Type &grainsizeType) {
768 parser, grainsizeMod, grainsize, grainsizeType,
769 &symbolizeClauseGrainsizeType,
"grainsize");
773 ClauseGrainsizeTypeAttr grainsizeMod,
776 p, op, grainsizeMod, grainsize, grainsizeType,
777 &stringifyClauseGrainsizeType);
787 std::optional<OpAsmParser::UnresolvedOperand> &numTasks,
788 Type &numTasksType) {
790 parser, numTasksMod, numTasks, numTasksType, &symbolizeClauseNumTasksType,
795 ClauseNumTasksTypeAttr numTasksMod,
798 p, op, numTasksMod, numTasks, numTasksType, &stringifyClauseNumTasksType);
807 SmallVectorImpl<OpAsmParser::UnresolvedOperand> &vars;
808 SmallVectorImpl<Type> &types;
809 MapParseArgs(SmallVectorImpl<OpAsmParser::UnresolvedOperand> &vars,
810 SmallVectorImpl<Type> &types)
811 : vars(vars), types(types) {}
813struct PrivateParseArgs {
814 llvm::SmallVectorImpl<OpAsmParser::UnresolvedOperand> &vars;
815 llvm::SmallVectorImpl<Type> &types;
817 UnitAttr &needsBarrier;
819 PrivateParseArgs(SmallVectorImpl<OpAsmParser::UnresolvedOperand> &vars,
820 SmallVectorImpl<Type> &types,
ArrayAttr &syms,
821 UnitAttr &needsBarrier,
823 : vars(vars), types(types), syms(syms), needsBarrier(needsBarrier),
824 mapIndices(mapIndices) {}
827struct ReductionParseArgs {
828 SmallVectorImpl<OpAsmParser::UnresolvedOperand> &vars;
829 SmallVectorImpl<Type> &types;
832 ReductionModifierAttr *modifier;
833 ReductionParseArgs(SmallVectorImpl<OpAsmParser::UnresolvedOperand> &vars,
835 ArrayAttr &syms, ReductionModifierAttr *mod =
nullptr)
836 : vars(vars), types(types), byref(byref), syms(syms), modifier(mod) {}
839struct AllRegionParseArgs {
840 std::optional<MapParseArgs> hasDeviceAddrArgs;
841 std::optional<MapParseArgs> hostEvalArgs;
842 std::optional<ReductionParseArgs> inReductionArgs;
843 std::optional<MapParseArgs> mapArgs;
844 std::optional<PrivateParseArgs> privateArgs;
845 std::optional<ReductionParseArgs> reductionArgs;
846 std::optional<ReductionParseArgs> taskReductionArgs;
847 std::optional<MapParseArgs> useDeviceAddrArgs;
848 std::optional<MapParseArgs> useDevicePtrArgs;
853 return "private_barrier";
863 ReductionModifierAttr *modifier =
nullptr,
864 UnitAttr *needsBarrier =
nullptr) {
868 unsigned regionArgOffset = regionPrivateArgs.size();
878 std::optional<ReductionModifier> enumValue =
879 symbolizeReductionModifier(enumStr);
880 if (!enumValue.has_value())
882 *modifier = ReductionModifierAttr::get(parser.
getContext(), *enumValue);
889 isByRefVec.push_back(
890 parser.parseOptionalKeyword(
"byref").succeeded());
892 if (symbols && parser.parseAttribute(symbolVec.emplace_back()))
895 if (parser.parseOperand(operands.emplace_back()) ||
896 parser.parseArrow() ||
897 parser.parseArgument(regionPrivateArgs.emplace_back()))
901 if (parser.parseOptionalLSquare().succeeded()) {
902 if (parser.parseKeyword(
"map_idx") || parser.parseEqual() ||
903 parser.parseInteger(mapIndicesVec.emplace_back()) ||
904 parser.parseRSquare())
907 mapIndicesVec.push_back(-1);
919 if (parser.parseType(types.emplace_back()))
926 if (operands.size() != types.size())
935 *needsBarrier = mlir::UnitAttr::get(parser.
getContext());
938 auto *argsBegin = regionPrivateArgs.begin();
940 argsBegin + regionArgOffset + types.size());
941 for (
auto [prv, type] : llvm::zip_equal(argsSubrange, types)) {
947 *symbols = ArrayAttr::get(parser.
getContext(), symbolAttrs);
950 if (!mapIndicesVec.empty())
963 StringRef keyword, std::optional<MapParseArgs> mapArgs) {
978 StringRef keyword, std::optional<PrivateParseArgs> privateArgs) {
984 parser, privateArgs->vars, privateArgs->types, entryBlockArgs,
985 &privateArgs->syms, privateArgs->mapIndices,
nullptr,
986 nullptr, &privateArgs->needsBarrier)))
995 StringRef keyword, std::optional<ReductionParseArgs> reductionArgs) {
1000 parser, reductionArgs->vars, reductionArgs->types, entryBlockArgs,
1001 &reductionArgs->syms,
nullptr, &reductionArgs->byref,
1002 reductionArgs->modifier)))
1009 AllRegionParseArgs args) {
1013 args.hasDeviceAddrArgs)))
1015 <<
"invalid `has_device_addr` format";
1018 args.hostEvalArgs)))
1020 <<
"invalid `host_eval` format";
1023 args.inReductionArgs)))
1025 <<
"invalid `in_reduction` format";
1030 <<
"invalid `map_entries` format";
1035 <<
"invalid `private` format";
1038 args.reductionArgs)))
1040 <<
"invalid `reduction` format";
1043 args.taskReductionArgs)))
1045 <<
"invalid `task_reduction` format";
1048 args.useDeviceAddrArgs)))
1050 <<
"invalid `use_device_addr` format";
1053 args.useDevicePtrArgs)))
1055 <<
"invalid `use_device_addr` format";
1057 return parser.
parseRegion(region, entryBlockArgs);
1076 AllRegionParseArgs args;
1077 args.hasDeviceAddrArgs.emplace(hasDeviceAddrVars, hasDeviceAddrTypes);
1078 args.hostEvalArgs.emplace(hostEvalVars, hostEvalTypes);
1079 args.inReductionArgs.emplace(inReductionVars, inReductionTypes,
1080 inReductionByref, inReductionSyms);
1081 args.mapArgs.emplace(mapVars, mapTypes);
1082 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1083 privateNeedsBarrier, &privateMaps);
1094 UnitAttr &privateNeedsBarrier) {
1095 AllRegionParseArgs args;
1096 args.inReductionArgs.emplace(inReductionVars, inReductionTypes,
1097 inReductionByref, inReductionSyms);
1098 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1099 privateNeedsBarrier);
1110 UnitAttr &privateNeedsBarrier, ReductionModifierAttr &reductionMod,
1114 AllRegionParseArgs args;
1115 args.inReductionArgs.emplace(inReductionVars, inReductionTypes,
1116 inReductionByref, inReductionSyms);
1117 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1118 privateNeedsBarrier);
1119 args.reductionArgs.emplace(reductionVars, reductionTypes, reductionByref,
1120 reductionSyms, &reductionMod);
1128 UnitAttr &privateNeedsBarrier) {
1129 AllRegionParseArgs args;
1130 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1131 privateNeedsBarrier);
1139 UnitAttr &privateNeedsBarrier, ReductionModifierAttr &reductionMod,
1143 AllRegionParseArgs args;
1144 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1145 privateNeedsBarrier);
1146 args.reductionArgs.emplace(reductionVars, reductionTypes, reductionByref,
1147 reductionSyms, &reductionMod);
1156 AllRegionParseArgs args;
1157 args.taskReductionArgs.emplace(taskReductionVars, taskReductionTypes,
1158 taskReductionByref, taskReductionSyms);
1168 AllRegionParseArgs args;
1169 args.useDeviceAddrArgs.emplace(useDeviceAddrVars, useDeviceAddrTypes);
1170 args.useDevicePtrArgs.emplace(useDevicePtrVars, useDevicePtrTypes);
1179struct MapPrintArgs {
1184struct PrivatePrintArgs {
1188 UnitAttr needsBarrier;
1192 : vars(vars), types(types), syms(syms), needsBarrier(needsBarrier),
1193 mapIndices(mapIndices) {}
1195struct ReductionPrintArgs {
1200 ReductionModifierAttr modifier;
1202 ArrayAttr syms, ReductionModifierAttr mod =
nullptr)
1203 : vars(vars), types(types), byref(byref), syms(syms), modifier(mod) {}
1205struct AllRegionPrintArgs {
1206 std::optional<MapPrintArgs> hasDeviceAddrArgs;
1207 std::optional<MapPrintArgs> hostEvalArgs;
1208 std::optional<ReductionPrintArgs> inReductionArgs;
1209 std::optional<MapPrintArgs> mapArgs;
1210 std::optional<PrivatePrintArgs> privateArgs;
1211 std::optional<ReductionPrintArgs> reductionArgs;
1212 std::optional<ReductionPrintArgs> taskReductionArgs;
1213 std::optional<MapPrintArgs> useDeviceAddrArgs;
1214 std::optional<MapPrintArgs> useDevicePtrArgs;
1223 ReductionModifierAttr modifier =
nullptr, UnitAttr needsBarrier =
nullptr) {
1224 if (argsSubrange.empty())
1227 p << clauseName <<
"(";
1230 p <<
"mod: " << stringifyReductionModifier(modifier.getValue()) <<
", ";
1234 symbols = ArrayAttr::get(ctx, values);
1247 llvm::interleaveComma(llvm::zip_equal(operands, argsSubrange, symbols,
1248 mapIndices.asArrayRef(),
1249 byref.asArrayRef()),
1251 auto [op, arg, sym, map, isByRef] = t;
1257 p << op <<
" -> " << arg;
1260 p <<
" [map_idx=" << map <<
"]";
1263 llvm::interleaveComma(types, p);
1271 StringRef clauseName,
ValueRange argsSubrange,
1272 std::optional<MapPrintArgs> mapArgs) {
1279 StringRef clauseName,
ValueRange argsSubrange,
1280 std::optional<PrivatePrintArgs> privateArgs) {
1283 p, ctx, clauseName, argsSubrange, privateArgs->vars, privateArgs->types,
1284 privateArgs->syms, privateArgs->mapIndices,
nullptr,
1285 nullptr, privateArgs->needsBarrier);
1291 std::optional<ReductionPrintArgs> reductionArgs) {
1294 reductionArgs->vars, reductionArgs->types,
1295 reductionArgs->syms,
nullptr,
1296 reductionArgs->byref, reductionArgs->modifier);
1300 const AllRegionPrintArgs &args) {
1301 auto iface = llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op);
1305 iface.getHasDeviceAddrBlockArgs(),
1306 args.hasDeviceAddrArgs);
1310 args.inReductionArgs);
1316 args.reductionArgs);
1318 iface.getTaskReductionBlockArgs(),
1319 args.taskReductionArgs);
1321 iface.getUseDeviceAddrBlockArgs(),
1322 args.useDeviceAddrArgs);
1324 iface.getUseDevicePtrBlockArgs(), args.useDevicePtrArgs);
1340 AllRegionPrintArgs args;
1341 args.hasDeviceAddrArgs.emplace(hasDeviceAddrVars, hasDeviceAddrTypes);
1342 args.hostEvalArgs.emplace(hostEvalVars, hostEvalTypes);
1343 args.inReductionArgs.emplace(inReductionVars, inReductionTypes,
1344 inReductionByref, inReductionSyms);
1345 args.mapArgs.emplace(mapVars, mapTypes);
1346 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1347 privateNeedsBarrier, privateMaps);
1355 ArrayAttr privateSyms, UnitAttr privateNeedsBarrier) {
1356 AllRegionPrintArgs args;
1357 args.inReductionArgs.emplace(inReductionVars, inReductionTypes,
1358 inReductionByref, inReductionSyms);
1359 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1360 privateNeedsBarrier,
1369 ArrayAttr privateSyms, UnitAttr privateNeedsBarrier,
1370 ReductionModifierAttr reductionMod,
ValueRange reductionVars,
1373 AllRegionPrintArgs args;
1374 args.inReductionArgs.emplace(inReductionVars, inReductionTypes,
1375 inReductionByref, inReductionSyms);
1376 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1377 privateNeedsBarrier,
1379 args.reductionArgs.emplace(reductionVars, reductionTypes, reductionByref,
1380 reductionSyms, reductionMod);
1387 UnitAttr privateNeedsBarrier) {
1388 AllRegionPrintArgs args;
1389 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1390 privateNeedsBarrier,
1398 ReductionModifierAttr reductionMod,
ValueRange reductionVars,
1401 AllRegionPrintArgs args;
1402 args.privateArgs.emplace(privateVars, privateTypes, privateSyms,
1403 privateNeedsBarrier,
1405 args.reductionArgs.emplace(reductionVars, reductionTypes, reductionByref,
1406 reductionSyms, reductionMod);
1416 AllRegionPrintArgs args;
1417 args.taskReductionArgs.emplace(taskReductionVars, taskReductionTypes,
1418 taskReductionByref, taskReductionSyms);
1428 AllRegionPrintArgs args;
1429 args.useDeviceAddrArgs.emplace(useDeviceAddrVars, useDeviceAddrTypes);
1430 args.useDevicePtrArgs.emplace(useDevicePtrVars, useDevicePtrTypes);
1439 if (!reductionVars.empty()) {
1440 if (!reductionSyms || reductionSyms->size() != reductionVars.size())
1442 <<
"expected as many reduction symbol references "
1443 "as reduction variables";
1444 if (reductionByref && reductionByref->size() != reductionVars.size())
1445 return op->
emitError() <<
"expected as many reduction variable by "
1446 "reference attributes as reduction variables";
1449 return op->
emitOpError() <<
"unexpected reduction symbol references";
1456 for (
auto args : llvm::zip(reductionVars, *reductionSyms)) {
1457 Value accum = std::get<0>(args);
1459 if (!accumulators.insert(accum).second)
1460 return op->
emitOpError() <<
"accumulator variable used more than once";
1463 auto symbolRef = llvm::cast<SymbolRefAttr>(std::get<1>(args));
1467 return op->
emitOpError() <<
"expected symbol reference " << symbolRef
1468 <<
" to point to a reduction declaration";
1470 if (decl.getAccumulatorType() && decl.getAccumulatorType() != varType)
1472 <<
"expected accumulator (" << varType
1473 <<
") to be the same type as reduction declaration ("
1474 << decl.getAccumulatorType() <<
")";
1493 if (parser.parseOperand(copyprivateVars.emplace_back()) ||
1494 parser.parseArrow() ||
1495 parser.parseAttribute(symsVec.emplace_back()) ||
1496 parser.parseColonType(copyprivateTypes.emplace_back()))
1502 copyprivateSyms = ArrayAttr::get(parser.
getContext(), syms);
1510 std::optional<ArrayAttr> copyprivateSyms) {
1511 if (!copyprivateSyms.has_value())
1513 llvm::interleaveComma(
1514 llvm::zip(copyprivateVars, *copyprivateSyms, copyprivateTypes), p,
1515 [&](
const auto &args) {
1516 p << std::get<0>(args) <<
" -> " << std::get<1>(args) <<
" : "
1517 << std::get<2>(args);
1524 std::optional<ArrayAttr> copyprivateSyms) {
1525 size_t copyprivateSymsSize =
1526 copyprivateSyms.has_value() ? copyprivateSyms->size() : 0;
1527 if (copyprivateSymsSize != copyprivateVars.size())
1528 return op->
emitOpError() <<
"inconsistent number of copyprivate vars (= "
1529 << copyprivateVars.size()
1530 <<
") and functions (= " << copyprivateSymsSize
1531 <<
"), both must be equal";
1532 if (!copyprivateSyms.has_value())
1535 for (
auto copyprivateVarAndSym :
1536 llvm::zip(copyprivateVars, *copyprivateSyms)) {
1538 llvm::cast<SymbolRefAttr>(std::get<1>(copyprivateVarAndSym));
1539 std::optional<std::variant<mlir::func::FuncOp, mlir::LLVM::LLVMFuncOp>>
1541 if (mlir::func::FuncOp mlirFuncOp =
1544 funcOp = mlirFuncOp;
1545 else if (mlir::LLVM::LLVMFuncOp llvmFuncOp =
1548 funcOp = llvmFuncOp;
1550 auto getNumArguments = [&] {
1551 return std::visit([](
auto &f) {
return f.getNumArguments(); }, *funcOp);
1554 auto getArgumentType = [&](
unsigned i) {
1555 return std::visit([i](
auto &f) {
return f.getArgumentTypes()[i]; },
1560 return op->
emitOpError() <<
"expected symbol reference " << symbolRef
1561 <<
" to point to a copy function";
1563 if (getNumArguments() != 2)
1565 <<
"expected copy function " << symbolRef <<
" to have 2 operands";
1567 Type argTy = getArgumentType(0);
1568 if (argTy != getArgumentType(1))
1569 return op->
emitOpError() <<
"expected copy function " << symbolRef
1570 <<
" arguments to have the same type";
1572 Type varType = std::get<0>(copyprivateVarAndSym).getType();
1573 if (argTy != varType)
1575 <<
"expected copy function arguments' type (" << argTy
1576 <<
") to be the same as copyprivate variable's type (" << varType
1597 if (parser.parseKeyword(&keyword) || parser.parseArrow() ||
1598 parser.parseOperand(dependVars.emplace_back()) ||
1599 parser.parseColonType(dependTypes.emplace_back()))
1601 if (std::optional<ClauseTaskDepend> keywordDepend =
1602 (symbolizeClauseTaskDepend(keyword)))
1603 kindsVec.emplace_back(
1604 ClauseTaskDependAttr::get(parser.getContext(), *keywordDepend));
1611 dependKinds = ArrayAttr::get(parser.
getContext(), kinds);
1618 std::optional<ArrayAttr> dependKinds) {
1620 for (
unsigned i = 0, e = dependKinds->size(); i < e; ++i) {
1623 p << stringifyClauseTaskDepend(
1624 llvm::cast<mlir::omp::ClauseTaskDependAttr>((*dependKinds)[i])
1626 <<
" -> " << dependVars[i] <<
" : " << dependTypes[i];
1632 std::optional<ArrayAttr> dependKinds,
1634 if (!dependVars.empty()) {
1635 if (!dependKinds || dependKinds->size() != dependVars.size())
1636 return op->
emitOpError() <<
"expected as many depend values"
1637 " as depend variables";
1639 if (dependKinds && !dependKinds->empty())
1640 return op->
emitOpError() <<
"unexpected depend values";
1656 IntegerAttr &hintAttr) {
1657 StringRef hintKeyword;
1663 auto parseKeyword = [&]() -> ParseResult {
1666 if (hintKeyword ==
"uncontended")
1668 else if (hintKeyword ==
"contended")
1670 else if (hintKeyword ==
"nonspeculative")
1672 else if (hintKeyword ==
"speculative")
1676 << hintKeyword <<
" is not a valid hint";
1687 IntegerAttr hintAttr) {
1688 int64_t hint = hintAttr.getInt();
1696 auto bitn = [](
int value,
int n) ->
bool {
return value & (1 << n); };
1698 bool uncontended = bitn(hint, 0);
1699 bool contended = bitn(hint, 1);
1700 bool nonspeculative = bitn(hint, 2);
1701 bool speculative = bitn(hint, 3);
1705 hints.push_back(
"uncontended");
1707 hints.push_back(
"contended");
1709 hints.push_back(
"nonspeculative");
1711 hints.push_back(
"speculative");
1713 llvm::interleaveComma(hints, p);
1720 auto bitn = [](
int value,
int n) ->
bool {
return value & (1 << n); };
1722 bool uncontended = bitn(hint, 0);
1723 bool contended = bitn(hint, 1);
1724 bool nonspeculative = bitn(hint, 2);
1725 bool speculative = bitn(hint, 3);
1727 if (uncontended && contended)
1728 return op->
emitOpError() <<
"the hints omp_sync_hint_uncontended and "
1729 "omp_sync_hint_contended cannot be combined";
1730 if (nonspeculative && speculative)
1731 return op->
emitOpError() <<
"the hints omp_sync_hint_nonspeculative and "
1732 "omp_sync_hint_speculative cannot be combined.";
1743 return (value & flag) == flag;
1751static ParseResult parseMapClause(
OpAsmParser &parser,
1752 ClauseMapFlagsAttr &mapType) {
1753 ClauseMapFlags mapTypeBits = ClauseMapFlags::none;
1756 auto parseTypeAndMod = [&]() -> ParseResult {
1757 StringRef mapTypeMod;
1761 if (mapTypeMod ==
"always")
1762 mapTypeBits |= ClauseMapFlags::always;
1764 if (mapTypeMod ==
"implicit")
1765 mapTypeBits |= ClauseMapFlags::implicit;
1767 if (mapTypeMod ==
"ompx_hold")
1768 mapTypeBits |= ClauseMapFlags::ompx_hold;
1770 if (mapTypeMod ==
"close")
1771 mapTypeBits |= ClauseMapFlags::close;
1773 if (mapTypeMod ==
"present")
1774 mapTypeBits |= ClauseMapFlags::present;
1776 if (mapTypeMod ==
"to")
1777 mapTypeBits |= ClauseMapFlags::to;
1779 if (mapTypeMod ==
"from")
1780 mapTypeBits |= ClauseMapFlags::from;
1782 if (mapTypeMod ==
"tofrom")
1783 mapTypeBits |= ClauseMapFlags::to | ClauseMapFlags::from;
1785 if (mapTypeMod ==
"delete")
1786 mapTypeBits |= ClauseMapFlags::del;
1788 if (mapTypeMod ==
"storage")
1789 mapTypeBits |= ClauseMapFlags::storage;
1791 if (mapTypeMod ==
"return_param")
1792 mapTypeBits |= ClauseMapFlags::return_param;
1794 if (mapTypeMod ==
"private")
1795 mapTypeBits |= ClauseMapFlags::priv;
1797 if (mapTypeMod ==
"literal")
1798 mapTypeBits |= ClauseMapFlags::literal;
1800 if (mapTypeMod ==
"attach")
1801 mapTypeBits |= ClauseMapFlags::attach;
1803 if (mapTypeMod ==
"attach_always")
1804 mapTypeBits |= ClauseMapFlags::attach_always;
1806 if (mapTypeMod ==
"attach_none")
1807 mapTypeBits |= ClauseMapFlags::attach_none;
1809 if (mapTypeMod ==
"attach_auto")
1810 mapTypeBits |= ClauseMapFlags::attach_auto;
1812 if (mapTypeMod ==
"ref_ptr")
1813 mapTypeBits |= ClauseMapFlags::ref_ptr;
1815 if (mapTypeMod ==
"ref_ptee")
1816 mapTypeBits |= ClauseMapFlags::ref_ptee;
1818 if (mapTypeMod ==
"ref_ptr_ptee")
1819 mapTypeBits |= ClauseMapFlags::ref_ptr_ptee;
1821 if (mapTypeMod ==
"is_device_ptr")
1822 mapTypeBits |= ClauseMapFlags::is_device_ptr;
1839 ClauseMapFlagsAttr mapType) {
1841 ClauseMapFlags mapFlags = mapType.getValue();
1846 mapTypeStrs.push_back(
"always");
1848 mapTypeStrs.push_back(
"implicit");
1850 mapTypeStrs.push_back(
"ompx_hold");
1852 mapTypeStrs.push_back(
"close");
1854 mapTypeStrs.push_back(
"present");
1863 mapTypeStrs.push_back(
"tofrom");
1865 mapTypeStrs.push_back(
"from");
1867 mapTypeStrs.push_back(
"to");
1870 mapTypeStrs.push_back(
"delete");
1872 mapTypeStrs.push_back(
"return_param");
1874 mapTypeStrs.push_back(
"storage");
1876 mapTypeStrs.push_back(
"private");
1878 mapTypeStrs.push_back(
"literal");
1880 mapTypeStrs.push_back(
"attach");
1882 mapTypeStrs.push_back(
"attach_always");
1884 mapTypeStrs.push_back(
"attach_none");
1886 mapTypeStrs.push_back(
"attach_auto");
1888 mapTypeStrs.push_back(
"ref_ptr");
1890 mapTypeStrs.push_back(
"ref_ptee");
1892 mapTypeStrs.push_back(
"ref_ptr_ptee");
1894 mapTypeStrs.push_back(
"is_device_ptr");
1895 if (mapFlags == ClauseMapFlags::none)
1896 mapTypeStrs.push_back(
"none");
1898 for (
unsigned int i = 0; i < mapTypeStrs.size(); ++i) {
1899 p << mapTypeStrs[i];
1900 if (i + 1 < mapTypeStrs.size()) {
1906static ParseResult parseMembersIndex(
OpAsmParser &parser,
1910 auto parseIndices = [&]() -> ParseResult {
1915 APInt(64, value,
false)));
1929 memberIdxs.push_back(ArrayAttr::get(parser.
getContext(), values));
1933 if (!memberIdxs.empty())
1934 membersIdx = ArrayAttr::get(parser.
getContext(), memberIdxs);
1944 llvm::interleaveComma(membersIdx, p, [&p](
Attribute v) {
1946 auto memberIdx = cast<ArrayAttr>(v);
1947 llvm::interleaveComma(memberIdx.getValue(), p, [&p](
Attribute v2) {
1948 p << cast<IntegerAttr>(v2).getInt();
1955 VariableCaptureKindAttr mapCaptureType) {
1956 std::string typeCapStr;
1957 llvm::raw_string_ostream typeCap(typeCapStr);
1958 if (mapCaptureType.getValue() == mlir::omp::VariableCaptureKind::ByRef)
1960 if (mapCaptureType.getValue() == mlir::omp::VariableCaptureKind::ByCopy)
1961 typeCap <<
"ByCopy";
1962 if (mapCaptureType.getValue() == mlir::omp::VariableCaptureKind::VLAType)
1963 typeCap <<
"VLAType";
1964 if (mapCaptureType.getValue() == mlir::omp::VariableCaptureKind::This)
1970 VariableCaptureKindAttr &mapCaptureType) {
1971 StringRef mapCaptureKey;
1975 if (mapCaptureKey ==
"This")
1976 mapCaptureType = mlir::omp::VariableCaptureKindAttr::get(
1977 parser.
getContext(), mlir::omp::VariableCaptureKind::This);
1978 if (mapCaptureKey ==
"ByRef")
1979 mapCaptureType = mlir::omp::VariableCaptureKindAttr::get(
1980 parser.
getContext(), mlir::omp::VariableCaptureKind::ByRef);
1981 if (mapCaptureKey ==
"ByCopy")
1982 mapCaptureType = mlir::omp::VariableCaptureKindAttr::get(
1983 parser.
getContext(), mlir::omp::VariableCaptureKind::ByCopy);
1984 if (mapCaptureKey ==
"VLAType")
1985 mapCaptureType = mlir::omp::VariableCaptureKindAttr::get(
1986 parser.
getContext(), mlir::omp::VariableCaptureKind::VLAType);
1995 for (
auto mapOp : mapVars) {
1996 if (!mapOp.getDefiningOp())
1999 if (
auto mapInfoOp = mapOp.getDefiningOp<mlir::omp::MapInfoOp>()) {
2000 mlir::omp::ClauseMapFlags mapTypeBits = mapInfoOp.getMapType();
2003 bool from =
mapTypeToBool(mapTypeBits, ClauseMapFlags::from);
2006 bool always =
mapTypeToBool(mapTypeBits, ClauseMapFlags::always);
2007 bool close =
mapTypeToBool(mapTypeBits, ClauseMapFlags::close);
2008 bool implicit =
mapTypeToBool(mapTypeBits, ClauseMapFlags::implicit);
2010 if ((isa<TargetDataOp>(op) || isa<TargetOp>(op)) && del)
2012 "to, from, tofrom and alloc map types are permitted");
2014 if (isa<TargetEnterDataOp>(op) && (from || del))
2015 return emitError(op->
getLoc(),
"to and alloc map types are permitted");
2017 if (isa<TargetExitDataOp>(op) && to)
2019 "from, release and delete map types are permitted");
2021 if (isa<TargetUpdateOp>(op)) {
2024 "at least one of to or from map types must be "
2025 "specified, other map types are not permitted");
2030 "at least one of to or from map types must be "
2031 "specified, other map types are not permitted");
2034 auto updateVar = mapInfoOp.getVarPtr();
2036 if ((to && from) || (to && updateFromVars.contains(updateVar)) ||
2037 (from && updateToVars.contains(updateVar))) {
2040 "either to or from map types can be specified, not both");
2043 if (always || close || implicit) {
2046 "present, mapper and iterator map type modifiers are permitted");
2049 to ? updateToVars.insert(updateVar) : updateFromVars.insert(updateVar);
2051 }
else if (!isa<DeclareMapperInfoOp>(op)) {
2053 "map argument is not a map entry operation");
2061 std::optional<DenseI64ArrayAttr> privateMapIndices =
2062 targetOp.getPrivateMapsAttr();
2065 if (!privateMapIndices.has_value() || !privateMapIndices.value())
2070 if (privateMapIndices.value().size() !=
2071 static_cast<int64_t>(privateVars.size()))
2072 return emitError(targetOp.getLoc(),
"sizes of `private` operand range and "
2073 "`private_maps` attribute mismatch");
2083 StringRef clauseName,
2085 for (
Value var : vars)
2086 if (!llvm::isa_and_present<MapInfoOp>(var.getDefiningOp()))
2088 <<
"'" << clauseName
2089 <<
"' arguments must be defined by 'omp.map.info' ops";
2093LogicalResult MapInfoOp::verify() {
2094 if (getMapperId() &&
2096 *
this, getMapperIdAttr())) {
2111 const TargetDataOperands &clauses) {
2112 TargetDataOp::build(builder, state, clauses.device, clauses.ifExpr,
2113 clauses.mapVars, clauses.useDeviceAddrVars,
2114 clauses.useDevicePtrVars);
2117LogicalResult TargetDataOp::verify() {
2118 if (getMapVars().empty() && getUseDevicePtrVars().empty() &&
2119 getUseDeviceAddrVars().empty()) {
2120 return ::emitError(this->getLoc(),
2121 "At least one of map, use_device_ptr_vars, or "
2122 "use_device_addr_vars operand must be present");
2126 getUseDevicePtrVars())))
2130 getUseDeviceAddrVars())))
2140void TargetEnterDataOp::build(
2144 TargetEnterDataOp::build(builder, state,
2146 clauses.dependVars, clauses.device, clauses.ifExpr,
2147 clauses.mapVars, clauses.nowait);
2150LogicalResult TargetEnterDataOp::verify() {
2151 LogicalResult verifyDependVars =
2153 return failed(verifyDependVars) ? verifyDependVars
2164 TargetExitDataOp::build(builder, state,
2166 clauses.dependVars, clauses.device, clauses.ifExpr,
2167 clauses.mapVars, clauses.nowait);
2170LogicalResult TargetExitDataOp::verify() {
2171 LogicalResult verifyDependVars =
2173 return failed(verifyDependVars) ? verifyDependVars
2184 TargetUpdateOp::build(builder, state,
makeArrayAttr(ctx, clauses.dependKinds),
2185 clauses.dependVars, clauses.device, clauses.ifExpr,
2186 clauses.mapVars, clauses.nowait);
2189LogicalResult TargetUpdateOp::verify() {
2190 LogicalResult verifyDependVars =
2192 return failed(verifyDependVars) ? verifyDependVars
2201 const TargetOperands &clauses) {
2205 TargetOp::build(builder, state, {}, {},
2207 clauses.dependVars, clauses.device, clauses.hasDeviceAddrVars,
2208 clauses.hostEvalVars, clauses.ifExpr,
2210 nullptr, clauses.isDevicePtrVars,
2211 clauses.mapVars, clauses.nowait, clauses.privateVars,
2213 clauses.privateNeedsBarrier, clauses.threadLimit,
2217LogicalResult TargetOp::verify() {
2222 getHasDeviceAddrVars())))
2231LogicalResult TargetOp::verifyRegions() {
2232 auto teamsOps = getOps<TeamsOp>();
2233 if (std::distance(teamsOps.begin(), teamsOps.end()) > 1)
2234 return emitError(
"target containing multiple 'omp.teams' nested ops");
2237 Operation *capturedOp = getInnermostCapturedOmpOp();
2238 TargetRegionFlags execFlags = getKernelExecFlags(capturedOp);
2239 for (
Value hostEvalArg :
2240 cast<BlockArgOpenMPOpInterface>(getOperation()).getHostEvalBlockArgs()) {
2242 if (
auto teamsOp = dyn_cast<TeamsOp>(user)) {
2243 if (llvm::is_contained({teamsOp.getNumTeamsLower(),
2244 teamsOp.getNumTeamsUpper(),
2245 teamsOp.getThreadLimit()},
2249 return emitOpError() <<
"host_eval argument only legal as 'num_teams' "
2250 "and 'thread_limit' in 'omp.teams'";
2252 if (
auto parallelOp = dyn_cast<ParallelOp>(user)) {
2253 if (bitEnumContainsAny(execFlags, TargetRegionFlags::spmd) &&
2254 parallelOp->isAncestor(capturedOp) &&
2255 hostEvalArg == parallelOp.getNumThreads())
2259 <<
"host_eval argument only legal as 'num_threads' in "
2260 "'omp.parallel' when representing target SPMD";
2262 if (
auto loopNestOp = dyn_cast<LoopNestOp>(user)) {
2263 if (bitEnumContainsAny(execFlags, TargetRegionFlags::trip_count) &&
2264 loopNestOp.getOperation() == capturedOp &&
2265 (llvm::is_contained(loopNestOp.getLoopLowerBounds(), hostEvalArg) ||
2266 llvm::is_contained(loopNestOp.getLoopUpperBounds(), hostEvalArg) ||
2267 llvm::is_contained(loopNestOp.getLoopSteps(), hostEvalArg)))
2270 return emitOpError() <<
"host_eval argument only legal as loop bounds "
2271 "and steps in 'omp.loop_nest' when trip count "
2272 "must be evaluated in the host";
2275 return emitOpError() <<
"host_eval argument illegal use in '"
2276 << user->getName() <<
"' operation";
2285 assert(rootOp &&
"expected valid operation");
2302 bool isOmpDialect = op->
getDialect() == ompDialect;
2304 if (!isOmpDialect || !hasRegions)
2311 if (checkSingleMandatoryExec) {
2316 if (successor->isReachable(parentBlock))
2319 for (
Block &block : *parentRegion)
2321 !domInfo.
dominates(parentBlock, &block))
2328 if (&sibling != op && !siblingAllowedFn(&sibling))
2341Operation *TargetOp::getInnermostCapturedOmpOp() {
2342 auto *ompDialect =
getContext()->getLoadedDialect<omp::OpenMPDialect>();
2354 if (
auto memOp = dyn_cast<MemoryEffectOpInterface>(sibling)) {
2357 memOp.getEffects(effects);
2358 return !llvm::any_of(
2360 return isa<MemoryEffects::Write>(effect.
getEffect()) &&
2361 isa<SideEffects::AutomaticAllocationScopeResource>(
2371 WsloopOp *wsLoopOp) {
2373 if (teamsOp.getNumTeamsUpper())
2377 if (teamsOp.getNumReductionVars())
2379 if (wsLoopOp->getNumReductionVars())
2383 OffloadModuleInterface offloadMod =
2387 auto ompFlags = offloadMod.getFlags();
2390 return ompFlags.getAssumeTeamsOversubscription() &&
2391 ompFlags.getAssumeThreadsOversubscription();
2394TargetRegionFlags TargetOp::getKernelExecFlags(
Operation *capturedOp) {
2399 assert((!capturedOp ||
2400 (targetOp && targetOp.getInnermostCapturedOmpOp() == capturedOp)) &&
2401 "unexpected captured op");
2404 if (!isa_and_present<LoopNestOp>(capturedOp))
2405 return TargetRegionFlags::generic;
2409 cast<LoopNestOp>(capturedOp).gatherWrappers(loopWrappers);
2410 assert(!loopWrappers.empty());
2412 LoopWrapperInterface *innermostWrapper = loopWrappers.begin();
2413 if (isa<SimdOp>(innermostWrapper))
2414 innermostWrapper = std::next(innermostWrapper);
2416 auto numWrappers = std::distance(innermostWrapper, loopWrappers.end());
2417 if (numWrappers != 1 && numWrappers != 2)
2418 return TargetRegionFlags::generic;
2421 if (numWrappers == 2) {
2422 WsloopOp *wsloopOp = dyn_cast<WsloopOp>(innermostWrapper);
2424 return TargetRegionFlags::generic;
2426 innermostWrapper = std::next(innermostWrapper);
2427 if (!isa<DistributeOp>(innermostWrapper))
2428 return TargetRegionFlags::generic;
2431 if (!isa_and_present<ParallelOp>(parallelOp))
2432 return TargetRegionFlags::generic;
2434 TeamsOp teamsOp = dyn_cast<TeamsOp>(parallelOp->
getParentOp());
2436 return TargetRegionFlags::generic;
2438 if (teamsOp->getParentOp() == targetOp.getOperation()) {
2439 TargetRegionFlags
result =
2440 TargetRegionFlags::spmd | TargetRegionFlags::trip_count;
2447 else if (isa<DistributeOp, LoopOp>(innermostWrapper)) {
2449 if (!isa_and_present<TeamsOp>(teamsOp))
2450 return TargetRegionFlags::generic;
2452 if (teamsOp->
getParentOp() != targetOp.getOperation())
2453 return TargetRegionFlags::generic;
2455 if (isa<LoopOp>(innermostWrapper))
2456 return TargetRegionFlags::spmd | TargetRegionFlags::trip_count;
2466 Dialect *ompDialect = targetOp->getDialect();
2470 return sibling && (ompDialect != sibling->
getDialect() ||
2474 TargetRegionFlags
result =
2475 TargetRegionFlags::generic | TargetRegionFlags::trip_count;
2480 while (nestedCapture->
getParentOp() != capturedOp)
2483 return isa<ParallelOp>(nestedCapture) ?
result | TargetRegionFlags::spmd
2487 else if (isa<WsloopOp>(innermostWrapper)) {
2489 if (!isa_and_present<ParallelOp>(parallelOp))
2490 return TargetRegionFlags::generic;
2492 if (parallelOp->
getParentOp() == targetOp.getOperation())
2493 return TargetRegionFlags::spmd;
2496 return TargetRegionFlags::generic;
2505 ParallelOp::build(builder, state,
ValueRange(),
2516 const ParallelOperands &clauses) {
2518 ParallelOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
2519 clauses.ifExpr, clauses.numThreads, clauses.privateVars,
2521 clauses.privateNeedsBarrier, clauses.procBindKind,
2522 clauses.reductionMod, clauses.reductionVars,
2527template <
typename OpType>
2529 auto privateVars = op.getPrivateVars();
2530 auto privateSyms = op.getPrivateSymsAttr();
2532 if (privateVars.empty() && (privateSyms ==
nullptr || privateSyms.empty()))
2535 auto numPrivateVars = privateVars.size();
2536 auto numPrivateSyms = (privateSyms ==
nullptr) ? 0 : privateSyms.size();
2538 if (numPrivateVars != numPrivateSyms)
2539 return op.emitError() <<
"inconsistent number of private variables and "
2540 "privatizer op symbols, private vars: "
2542 <<
" vs. privatizer op symbols: " << numPrivateSyms;
2544 for (
auto privateVarInfo : llvm::zip_equal(privateVars, privateSyms)) {
2545 Type varType = std::get<0>(privateVarInfo).getType();
2546 SymbolRefAttr privateSym = cast<SymbolRefAttr>(std::get<1>(privateVarInfo));
2547 PrivateClauseOp privatizerOp =
2550 if (privatizerOp ==
nullptr)
2551 return op.emitError() <<
"failed to lookup privatizer op with symbol: '"
2552 << privateSym <<
"'";
2554 Type privatizerType = privatizerOp.getArgType();
2556 if (privatizerType && (varType != privatizerType))
2557 return op.emitError()
2558 <<
"type mismatch between a "
2559 << (privatizerOp.getDataSharingType() ==
2560 DataSharingClauseType::Private
2563 <<
" variable and its privatizer op, var type: " << varType
2564 <<
" vs. privatizer op type: " << privatizerType;
2570LogicalResult ParallelOp::verify() {
2571 if (getAllocateVars().size() != getAllocatorVars().size())
2573 "expected equal sizes for allocate and allocator variables");
2579 getReductionByref());
2582LogicalResult ParallelOp::verifyRegions() {
2583 auto distChildOps = getOps<DistributeOp>();
2584 int numDistChildOps = std::distance(distChildOps.begin(), distChildOps.end());
2585 if (numDistChildOps > 1)
2587 <<
"multiple 'omp.distribute' nested inside of 'omp.parallel'";
2589 if (numDistChildOps == 1) {
2592 <<
"'omp.composite' attribute missing from composite operation";
2594 auto *ompDialect =
getContext()->getLoadedDialect<OpenMPDialect>();
2595 Operation &distributeOp = **distChildOps.begin();
2597 if (&childOp == &distributeOp || ompDialect != childOp.getDialect())
2601 return emitError() <<
"unexpected OpenMP operation inside of composite "
2603 << childOp.getName();
2605 }
else if (isComposite()) {
2607 <<
"'omp.composite' attribute present in non-composite operation";
2624 const TeamsOperands &clauses) {
2627 TeamsOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
2628 clauses.ifExpr, clauses.numTeamsLower, clauses.numTeamsUpper,
2630 nullptr, clauses.reductionMod,
2631 clauses.reductionVars,
2634 clauses.threadLimit);
2637LogicalResult TeamsOp::verify() {
2646 return emitError(
"expected to be nested inside of omp.target or not nested "
2647 "in any OpenMP dialect operations");
2650 if (
auto numTeamsLowerBound = getNumTeamsLower()) {
2651 auto numTeamsUpperBound = getNumTeamsUpper();
2652 if (!numTeamsUpperBound)
2653 return emitError(
"expected num_teams upper bound to be defined if the "
2654 "lower bound is defined");
2655 if (numTeamsLowerBound.getType() != numTeamsUpperBound.getType())
2657 "expected num_teams upper bound and lower bound to be the same type");
2661 if (getAllocateVars().size() != getAllocatorVars().size())
2663 "expected equal sizes for allocate and allocator variables");
2666 getReductionByref());
2674 return getParentOp().getPrivateVars();
2678 return getParentOp().getReductionVars();
2686 const SectionsOperands &clauses) {
2689 SectionsOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
2692 clauses.reductionMod, clauses.reductionVars,
2697LogicalResult SectionsOp::verify() {
2698 if (getAllocateVars().size() != getAllocatorVars().size())
2700 "expected equal sizes for allocate and allocator variables");
2703 getReductionByref());
2706LogicalResult SectionsOp::verifyRegions() {
2707 for (
auto &inst : *getRegion().begin()) {
2708 if (!(isa<SectionOp>(inst) || isa<TerminatorOp>(inst))) {
2710 <<
"expected omp.section op or terminator op inside region";
2722 const SingleOperands &clauses) {
2725 SingleOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
2726 clauses.copyprivateVars,
2727 makeArrayAttr(ctx, clauses.copyprivateSyms), clauses.nowait,
2732LogicalResult SingleOp::verify() {
2734 if (getAllocateVars().size() != getAllocatorVars().size())
2736 "expected equal sizes for allocate and allocator variables");
2739 getCopyprivateSyms());
2747 const WorkshareOperands &clauses) {
2748 WorkshareOp::build(builder, state, clauses.nowait);
2755LogicalResult WorkshareLoopWrapperOp::verify() {
2756 if (!(*this)->getParentOfType<WorkshareOp>())
2757 return emitOpError() <<
"must be nested in an omp.workshare";
2761LogicalResult WorkshareLoopWrapperOp::verifyRegions() {
2762 if (isa_and_nonnull<LoopWrapperInterface>((*this)->getParentOp()) ||
2764 return emitOpError() <<
"expected to be a standalone loop wrapper";
2773LogicalResult LoopWrapperInterface::verifyImpl() {
2777 return emitOpError() <<
"loop wrapper must also have the `NoTerminator` "
2778 "and `SingleBlock` traits";
2781 return emitOpError() <<
"loop wrapper does not contain exactly one region";
2784 if (range_size(region.
getOps()) != 1)
2786 <<
"loop wrapper does not contain exactly one nested op";
2789 if (!isa<LoopNestOp, LoopWrapperInterface>(firstOp))
2790 return emitOpError() <<
"nested in loop wrapper is not another loop "
2791 "wrapper or `omp.loop_nest`";
2801 const LoopOperands &clauses) {
2804 LoopOp::build(builder, state, clauses.bindKind, clauses.privateVars,
2806 clauses.privateNeedsBarrier, clauses.order, clauses.orderMod,
2807 clauses.reductionMod, clauses.reductionVars,
2812LogicalResult LoopOp::verify() {
2814 getReductionByref());
2817LogicalResult LoopOp::verifyRegions() {
2818 if (llvm::isa_and_nonnull<LoopWrapperInterface>((*this)->getParentOp()) ||
2820 return emitOpError() <<
"expected to be a standalone loop wrapper";
2831 build(builder, state, {}, {},
2834 false,
nullptr,
nullptr,
2835 nullptr, {},
nullptr,
2846 const WsloopOperands &clauses) {
2851 {}, {}, clauses.linearVars,
2852 clauses.linearStepVars, clauses.linearVarTypes, clauses.nowait,
2853 clauses.order, clauses.orderMod, clauses.ordered, clauses.privateVars,
2854 makeArrayAttr(ctx, clauses.privateSyms), clauses.privateNeedsBarrier,
2855 clauses.reductionMod, clauses.reductionVars,
2857 makeArrayAttr(ctx, clauses.reductionSyms), clauses.scheduleKind,
2858 clauses.scheduleChunk, clauses.scheduleMod, clauses.scheduleSimd);
2861LogicalResult WsloopOp::verify() {
2863 getReductionByref());
2866LogicalResult WsloopOp::verifyRegions() {
2867 bool isCompositeChildLeaf =
2868 llvm::dyn_cast_if_present<LoopWrapperInterface>((*this)->getParentOp());
2870 if (LoopWrapperInterface nested = getNestedWrapper()) {
2873 <<
"'omp.composite' attribute missing from composite wrapper";
2877 if (!isa<SimdOp>(nested))
2878 return emitError() <<
"only supported nested wrapper is 'omp.simd'";
2880 }
else if (isComposite() && !isCompositeChildLeaf) {
2882 <<
"'omp.composite' attribute present in non-composite wrapper";
2883 }
else if (!isComposite() && isCompositeChildLeaf) {
2885 <<
"'omp.composite' attribute missing from composite wrapper";
2896 const SimdOperands &clauses) {
2899 builder, state, clauses.alignedVars,
2901 clauses.linearVars, clauses.linearStepVars, clauses.linearVarTypes,
2902 clauses.nontemporalVars, clauses.order, clauses.orderMod,
2903 clauses.privateVars,
makeArrayAttr(ctx, clauses.privateSyms),
2904 clauses.privateNeedsBarrier, clauses.reductionMod, clauses.reductionVars,
2910LogicalResult SimdOp::verify() {
2911 if (getSimdlen().has_value() && getSafelen().has_value() &&
2912 getSimdlen().value() > getSafelen().value())
2914 <<
"simdlen clause and safelen clause are both present, but the "
2915 "simdlen value is not less than or equal to safelen value";
2923 bool isCompositeChildLeaf =
2924 llvm::dyn_cast_if_present<LoopWrapperInterface>((*this)->getParentOp());
2926 if (!isComposite() && isCompositeChildLeaf)
2928 <<
"'omp.composite' attribute missing from composite wrapper";
2930 if (isComposite() && !isCompositeChildLeaf)
2932 <<
"'omp.composite' attribute present in non-composite wrapper";
2936 std::optional<ArrayAttr> privateSyms = getPrivateSyms();
2938 for (
const Attribute &sym : *privateSyms) {
2939 auto symRef = cast<SymbolRefAttr>(sym);
2940 omp::PrivateClauseOp privatizer =
2942 getOperation(), symRef);
2944 return emitError() <<
"Cannot find privatizer '" << symRef <<
"'";
2945 if (privatizer.getDataSharingType() ==
2946 DataSharingClauseType::FirstPrivate)
2947 return emitError() <<
"FIRSTPRIVATE cannot be used with SIMD";
2954LogicalResult SimdOp::verifyRegions() {
2955 if (getNestedWrapper())
2956 return emitOpError() <<
"must wrap an 'omp.loop_nest' directly";
2966 const DistributeOperands &clauses) {
2967 DistributeOp::build(builder, state, clauses.allocateVars,
2968 clauses.allocatorVars, clauses.distScheduleStatic,
2969 clauses.distScheduleChunkSize, clauses.order,
2970 clauses.orderMod, clauses.privateVars,
2972 clauses.privateNeedsBarrier);
2975LogicalResult DistributeOp::verify() {
2976 if (this->getDistScheduleChunkSize() && !this->getDistScheduleStatic())
2978 "dist_schedule_static being present";
2980 if (getAllocateVars().size() != getAllocatorVars().size())
2982 "expected equal sizes for allocate and allocator variables");
2987LogicalResult DistributeOp::verifyRegions() {
2988 if (LoopWrapperInterface nested = getNestedWrapper()) {
2991 <<
"'omp.composite' attribute missing from composite wrapper";
2994 if (isa<WsloopOp>(nested)) {
2996 if (!llvm::dyn_cast_if_present<ParallelOp>(parentOp) ||
2997 !cast<ComposableOpInterface>(parentOp).isComposite()) {
2998 return emitError() <<
"an 'omp.wsloop' nested wrapper is only allowed "
2999 "when a composite 'omp.parallel' is the direct "
3002 }
else if (!isa<SimdOp>(nested))
3003 return emitError() <<
"only supported nested wrappers are 'omp.simd' and "
3005 }
else if (isComposite()) {
3007 <<
"'omp.composite' attribute present in non-composite wrapper";
3017LogicalResult DeclareMapperInfoOp::verify() {
3021LogicalResult DeclareMapperOp::verifyRegions() {
3022 if (!llvm::isa_and_present<DeclareMapperInfoOp>(
3023 getRegion().getBlocks().front().getTerminator()))
3024 return emitOpError() <<
"expected terminator to be a DeclareMapperInfoOp";
3033LogicalResult DeclareReductionOp::verifyRegions() {
3034 if (!getAllocRegion().empty()) {
3035 for (YieldOp yieldOp : getAllocRegion().getOps<YieldOp>()) {
3036 if (yieldOp.getResults().size() != 1 ||
3037 yieldOp.getResults().getTypes()[0] !=
getType())
3038 return emitOpError() <<
"expects alloc region to yield a value "
3039 "of the reduction type";
3043 if (getInitializerRegion().empty())
3044 return emitOpError() <<
"expects non-empty initializer region";
3045 Block &initializerEntryBlock = getInitializerRegion().
front();
3048 if (!getAllocRegion().empty())
3049 return emitOpError() <<
"expects two arguments to the initializer region "
3050 "when an allocation region is used";
3052 if (getAllocRegion().empty())
3053 return emitOpError() <<
"expects one argument to the initializer region "
3054 "when no allocation region is used";
3057 <<
"expects one or two arguments to the initializer region";
3061 if (arg.getType() !=
getType())
3062 return emitOpError() <<
"expects initializer region argument to match "
3063 "the reduction type";
3065 for (YieldOp yieldOp : getInitializerRegion().getOps<YieldOp>()) {
3066 if (yieldOp.getResults().size() != 1 ||
3067 yieldOp.getResults().getTypes()[0] !=
getType())
3068 return emitOpError() <<
"expects initializer region to yield a value "
3069 "of the reduction type";
3072 if (getReductionRegion().empty())
3073 return emitOpError() <<
"expects non-empty reduction region";
3074 Block &reductionEntryBlock = getReductionRegion().
front();
3079 return emitOpError() <<
"expects reduction region with two arguments of "
3080 "the reduction type";
3081 for (YieldOp yieldOp : getReductionRegion().getOps<YieldOp>()) {
3082 if (yieldOp.getResults().size() != 1 ||
3083 yieldOp.getResults().getTypes()[0] !=
getType())
3084 return emitOpError() <<
"expects reduction region to yield a value "
3085 "of the reduction type";
3088 if (!getAtomicReductionRegion().empty()) {
3089 Block &atomicReductionEntryBlock = getAtomicReductionRegion().
front();
3093 return emitOpError() <<
"expects atomic reduction region with two "
3094 "arguments of the same type";
3095 auto ptrType = llvm::dyn_cast<PointerLikeType>(
3098 (ptrType.getElementType() && ptrType.getElementType() !=
getType()))
3099 return emitOpError() <<
"expects atomic reduction region arguments to "
3100 "be accumulators containing the reduction type";
3103 if (getCleanupRegion().empty())
3105 Block &cleanupEntryBlock = getCleanupRegion().
front();
3108 return emitOpError() <<
"expects cleanup region with one argument "
3109 "of the reduction type";
3119 const TaskOperands &clauses) {
3121 TaskOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
3122 makeArrayAttr(ctx, clauses.dependKinds), clauses.dependVars,
3123 clauses.final, clauses.ifExpr, clauses.inReductionVars,
3125 makeArrayAttr(ctx, clauses.inReductionSyms), clauses.mergeable,
3126 clauses.priority, clauses.privateVars,
3128 clauses.privateNeedsBarrier, clauses.untied,
3129 clauses.eventHandle);
3132LogicalResult TaskOp::verify() {
3133 LogicalResult verifyDependVars =
3135 return failed(verifyDependVars)
3138 getInReductionVars(),
3139 getInReductionByref());
3147 const TaskgroupOperands &clauses) {
3149 TaskgroupOp::build(builder, state, clauses.allocateVars,
3150 clauses.allocatorVars, clauses.taskReductionVars,
3155LogicalResult TaskgroupOp::verify() {
3157 getTaskReductionVars(),
3158 getTaskReductionByref());
3166 const TaskloopOperands &clauses) {
3169 builder, state, clauses.allocateVars, clauses.allocatorVars,
3170 clauses.final, clauses.grainsizeMod, clauses.grainsize, clauses.ifExpr,
3171 clauses.inReductionVars,
3173 makeArrayAttr(ctx, clauses.inReductionSyms), clauses.mergeable,
3174 clauses.nogroup, clauses.numTasksMod, clauses.numTasks, clauses.priority,
3175 clauses.privateVars,
3177 clauses.privateNeedsBarrier, clauses.reductionMod, clauses.reductionVars,
3182LogicalResult TaskloopOp::verify() {
3183 if (getAllocateVars().size() != getAllocatorVars().size())
3185 "expected equal sizes for allocate and allocator variables");
3187 getReductionVars(), getReductionByref())) ||
3189 getInReductionVars(),
3190 getInReductionByref())))
3193 if (!getReductionVars().empty() && getNogroup())
3194 return emitError(
"if a reduction clause is present on the taskloop "
3195 "directive, the nogroup clause must not be specified");
3196 for (
auto var : getReductionVars()) {
3197 if (llvm::is_contained(getInReductionVars(), var))
3198 return emitError(
"the same list item cannot appear in both a reduction "
3199 "and an in_reduction clause");
3202 if (getGrainsize() && getNumTasks()) {
3204 "the grainsize clause and num_tasks clause are mutually exclusive and "
3205 "may not appear on the same taskloop directive");
3211LogicalResult TaskloopOp::verifyRegions() {
3212 if (LoopWrapperInterface nested = getNestedWrapper()) {
3215 <<
"'omp.composite' attribute missing from composite wrapper";
3219 if (!isa<SimdOp>(nested))
3220 return emitError() <<
"only supported nested wrapper is 'omp.simd'";
3221 }
else if (isComposite()) {
3223 <<
"'omp.composite' attribute present in non-composite wrapper";
3247 for (
auto &iv : ivs)
3248 iv.type = loopVarType;
3253 result.addAttribute(
"loop_inclusive", UnitAttr::get(ctx));
3269 "collapse_num_loops",
3274 auto parseTiles = [&]() -> ParseResult {
3278 tiles.push_back(
tile);
3287 if (tiles.size() > 0)
3306 Region ®ion = getRegion();
3308 p <<
" (" << args <<
") : " << args[0].getType() <<
" = ("
3309 << getLoopLowerBounds() <<
") to (" << getLoopUpperBounds() <<
") ";
3310 if (getLoopInclusive())
3312 p <<
"step (" << getLoopSteps() <<
") ";
3313 if (
int64_t numCollapse = getCollapseNumLoops())
3314 if (numCollapse > 1)
3315 p <<
"collapse(" << numCollapse <<
") ";
3318 p <<
"tiles(" << tiles.value() <<
") ";
3324 const LoopNestOperands &clauses) {
3326 LoopNestOp::build(builder, state, clauses.collapseNumLoops,
3327 clauses.loopLowerBounds, clauses.loopUpperBounds,
3328 clauses.loopSteps, clauses.loopInclusive,
3332LogicalResult LoopNestOp::verify() {
3333 if (getLoopLowerBounds().empty())
3334 return emitOpError() <<
"must represent at least one loop";
3336 if (getLoopLowerBounds().size() != getIVs().size())
3337 return emitOpError() <<
"number of range arguments and IVs do not match";
3339 for (
auto [lb, iv] : llvm::zip_equal(getLoopLowerBounds(), getIVs())) {
3340 if (lb.getType() != iv.getType())
3342 <<
"range argument type does not match corresponding IV type";
3345 uint64_t numIVs = getIVs().size();
3347 if (
const auto &numCollapse = getCollapseNumLoops())
3348 if (numCollapse > numIVs)
3350 <<
"collapse value is larger than the number of loops";
3353 if (tiles.value().size() > numIVs)
3354 return emitOpError() <<
"too few canonical loops for tile dimensions";
3356 if (!llvm::dyn_cast_if_present<LoopWrapperInterface>((*this)->getParentOp()))
3357 return emitOpError() <<
"expects parent op to be a loop wrapper";
3362void LoopNestOp::gatherWrappers(
3365 while (
auto wrapper =
3366 llvm::dyn_cast_if_present<LoopWrapperInterface>(parent)) {
3367 wrappers.push_back(wrapper);
3376std::tuple<NewCliOp, OpOperand *, OpOperand *>
3382 return {{},
nullptr,
nullptr};
3385 "Unexpected type of cli");
3391 auto op = cast<LoopTransformationInterface>(use.getOwner());
3393 unsigned opnum = use.getOperandNumber();
3394 if (op.isGeneratee(opnum)) {
3395 assert(!gen &&
"Each CLI may have at most one def");
3397 }
else if (op.isApplyee(opnum)) {
3398 assert(!cons &&
"Each CLI may have at most one consumer");
3401 llvm_unreachable(
"Unexpected operand for a CLI");
3405 return {create, gen, cons};
3428 std::string cliName{
"cli"};
3432 .Case([&](CanonicalLoopOp op) {
3435 .Case([&](UnrollHeuristicOp op) -> std::string {
3436 llvm_unreachable(
"heuristic unrolling does not generate a loop");
3438 .Case([&](TileOp op) -> std::string {
3439 auto [generateesFirst, generateesCount] =
3440 op.getGenerateesODSOperandIndexAndLength();
3441 unsigned firstGrid = generateesFirst;
3442 unsigned firstIntratile = generateesFirst + generateesCount / 2;
3443 unsigned end = generateesFirst + generateesCount;
3444 unsigned opnum =
generator->getOperandNumber();
3446 if (firstGrid <= opnum && opnum < firstIntratile) {
3447 unsigned gridnum = opnum - firstGrid + 1;
3448 return (
"grid" + Twine(gridnum)).str();
3450 if (firstIntratile <= opnum && opnum < end) {
3451 unsigned intratilenum = opnum - firstIntratile + 1;
3452 return (
"intratile" + Twine(intratilenum)).str();
3454 llvm_unreachable(
"Unexpected generatee argument");
3456 .DefaultUnreachable(
"TODO: Custom name for this operation");
3459 setNameFn(
result, cliName);
3462LogicalResult NewCliOp::verify() {
3463 Value cli = getResult();
3466 "Unexpected type of cli");
3472 auto op = cast<mlir::omp::LoopTransformationInterface>(use.getOwner());
3474 unsigned opnum = use.getOperandNumber();
3475 if (op.isGeneratee(opnum)) {
3478 emitOpError(
"CLI must have at most one generator");
3480 .
append(
"first generator here:");
3482 .
append(
"second generator here:");
3487 }
else if (op.isApplyee(opnum)) {
3490 emitOpError(
"CLI must have at most one consumer");
3492 .
append(
"first consumer here:")
3496 .
append(
"second consumer here:")
3503 llvm_unreachable(
"Unexpected operand for a CLI");
3511 .
append(
"see consumer here: ")
3534 setNameFn(&getRegion().front(),
"body_entry");
3537void CanonicalLoopOp::getAsmBlockArgumentNames(
Region ®ion,
3545 p <<
'(' << getCli() <<
')';
3546 p <<
' ' << getInductionVar() <<
" : " << getInductionVar().getType()
3547 <<
" in range(" << getTripCount() <<
") ";
3557 CanonicalLoopInfoType cliType =
3558 CanonicalLoopInfoType::get(parser.
getContext());
3583 if (parser.
parseRegion(*region, {inductionVariable}))
3588 result.operands.append(cliOperand);
3594 return mlir::success();
3597LogicalResult CanonicalLoopOp::verify() {
3600 if (!getRegion().empty()) {
3601 Region ®ion = getRegion();
3604 "Canonical loop region must have exactly one argument");
3608 "Region argument must be the same type as the trip count");
3614Value CanonicalLoopOp::getInductionVar() {
return getRegion().getArgument(0); }
3616std::pair<unsigned, unsigned>
3617CanonicalLoopOp::getApplyeesODSOperandIndexAndLength() {
3622std::pair<unsigned, unsigned>
3623CanonicalLoopOp::getGenerateesODSOperandIndexAndLength() {
3624 return getODSOperandIndexAndLength(odsIndex_cli);
3638 p <<
'(' << getApplyee() <<
')';
3645 auto cliType = CanonicalLoopInfoType::get(parser.
getContext());
3668 return mlir::success();
3671std::pair<unsigned, unsigned>
3672UnrollHeuristicOp ::getApplyeesODSOperandIndexAndLength() {
3673 return getODSOperandIndexAndLength(odsIndex_applyee);
3676std::pair<unsigned, unsigned>
3677UnrollHeuristicOp::getGenerateesODSOperandIndexAndLength() {
3688 if (!generatees.empty())
3689 p <<
'(' << llvm::interleaved(generatees) <<
')';
3691 if (!applyees.empty())
3692 p <<
" <- (" << llvm::interleaved(applyees) <<
')';
3723LogicalResult TileOp::verify() {
3724 if (getApplyees().empty())
3725 return emitOpError() <<
"must apply to at least one loop";
3727 if (getSizes().size() != getApplyees().size())
3728 return emitOpError() <<
"there must be one tile size for each applyee";
3730 if (!getGeneratees().empty() &&
3731 2 * getSizes().size() != getGeneratees().size())
3733 <<
"expecting two times the number of generatees than applyees";
3737 Value parent = getApplyees().front();
3738 for (
auto &&applyee : llvm::drop_begin(getApplyees())) {
3739 auto [parentCreate, parentGen, parentCons] =
decodeCli(parent);
3740 auto [create, gen, cons] =
decodeCli(applyee);
3743 return emitOpError() <<
"applyee CLI has no generator";
3745 auto parentLoop = dyn_cast_or_null<CanonicalLoopOp>(parentGen->getOwner());
3748 <<
"currently only supports omp.canonical_loop as applyee";
3750 parentIVs.insert(parentLoop.getInductionVar());
3753 return emitOpError() <<
"applyee CLI has no generator";
3754 auto loop = dyn_cast_or_null<CanonicalLoopOp>(gen->getOwner());
3757 <<
"currently only supports omp.canonical_loop as applyee";
3763 auto &parentBody = parentLoop.getRegion();
3764 if (!parentBody.hasOneBlock())
3766 auto &parentBlock = parentBody.getBlocks().front();
3768 auto nestedLoopIt = parentBlock.begin();
3769 if (nestedLoopIt == parentBlock.end() ||
3770 (&*nestedLoopIt != loop.getOperation()))
3773 auto termIt = std::next(nestedLoopIt);
3774 if (termIt == parentBlock.end() || !isa<TerminatorOp>(termIt))
3777 if (std::next(termIt) != parentBlock.end())
3782 if (!isPerfectlyNested)
3783 return emitOpError() <<
"tiled loop nest must be perfectly nested";
3785 if (parentIVs.contains(loop.getTripCount()))
3786 return emitOpError() <<
"tiled loop nest must be rectangular";
3805std::pair<unsigned, unsigned> TileOp ::getApplyeesODSOperandIndexAndLength() {
3806 return getODSOperandIndexAndLength(odsIndex_applyees);
3809std::pair<unsigned, unsigned> TileOp::getGenerateesODSOperandIndexAndLength() {
3810 return getODSOperandIndexAndLength(odsIndex_generatees);
3818 const CriticalDeclareOperands &clauses) {
3819 CriticalDeclareOp::build(builder, state, clauses.symName, clauses.hint);
3822LogicalResult CriticalDeclareOp::verify() {
3827 if (getNameAttr()) {
3828 SymbolRefAttr symbolRef = getNameAttr();
3832 return emitOpError() <<
"expected symbol reference " << symbolRef
3833 <<
" to point to a critical declaration";
3853 return op.
emitOpError() <<
"must be nested inside of a loop";
3857 if (
auto wsloopOp = dyn_cast<WsloopOp>(wrapper)) {
3858 IntegerAttr orderedAttr = wsloopOp.getOrderedAttr();
3860 return op.
emitOpError() <<
"the enclosing worksharing-loop region must "
3861 "have an ordered clause";
3863 if (hasRegion && orderedAttr.getInt() != 0)
3864 return op.
emitOpError() <<
"the enclosing loop's ordered clause must not "
3865 "have a parameter present";
3867 if (!hasRegion && orderedAttr.getInt() == 0)
3868 return op.
emitOpError() <<
"the enclosing loop's ordered clause must "
3869 "have a parameter present";
3870 }
else if (!isa<SimdOp>(wrapper)) {
3871 return op.
emitOpError() <<
"must be nested inside of a worksharing, simd "
3872 "or worksharing simd loop";
3878 const OrderedOperands &clauses) {
3879 OrderedOp::build(builder, state, clauses.doacrossDependType,
3880 clauses.doacrossNumLoops, clauses.doacrossDependVars);
3883LogicalResult OrderedOp::verify() {
3887 auto wrapper = (*this)->getParentOfType<WsloopOp>();
3888 if (!wrapper || *wrapper.getOrdered() != *getDoacrossNumLoops())
3889 return emitOpError() <<
"number of variables in depend clause does not "
3890 <<
"match number of iteration variables in the "
3897 const OrderedRegionOperands &clauses) {
3898 OrderedRegionOp::build(builder, state, clauses.parLevelSimd);
3908 const TaskwaitOperands &clauses) {
3910 TaskwaitOp::build(builder, state,
nullptr,
3918LogicalResult AtomicReadOp::verify() {
3919 if (verifyCommon().
failed())
3920 return mlir::failure();
3922 if (
auto mo = getMemoryOrder()) {
3923 if (*mo == ClauseMemoryOrderKind::Acq_rel ||
3924 *mo == ClauseMemoryOrderKind::Release) {
3926 "memory-order must not be acq_rel or release for atomic reads");
3936LogicalResult AtomicWriteOp::verify() {
3937 if (verifyCommon().
failed())
3938 return mlir::failure();
3940 if (
auto mo = getMemoryOrder()) {
3941 if (*mo == ClauseMemoryOrderKind::Acq_rel ||
3942 *mo == ClauseMemoryOrderKind::Acquire) {
3944 "memory-order must not be acq_rel or acquire for atomic writes");
3954LogicalResult AtomicUpdateOp::canonicalize(AtomicUpdateOp op,
3960 if (
Value writeVal = op.getWriteOpVal()) {
3962 op, op.getX(), writeVal, op.getHintAttr(), op.getMemoryOrderAttr());
3968LogicalResult AtomicUpdateOp::verify() {
3969 if (verifyCommon().
failed())
3970 return mlir::failure();
3972 if (
auto mo = getMemoryOrder()) {
3973 if (*mo == ClauseMemoryOrderKind::Acq_rel ||
3974 *mo == ClauseMemoryOrderKind::Acquire) {
3976 "memory-order must not be acq_rel or acquire for atomic updates");
3983LogicalResult AtomicUpdateOp::verifyRegions() {
return verifyRegionsCommon(); }
3989AtomicReadOp AtomicCaptureOp::getAtomicReadOp() {
3990 if (
auto op = dyn_cast<AtomicReadOp>(getFirstOp()))
3992 return dyn_cast<AtomicReadOp>(getSecondOp());
3995AtomicWriteOp AtomicCaptureOp::getAtomicWriteOp() {
3996 if (
auto op = dyn_cast<AtomicWriteOp>(getFirstOp()))
3998 return dyn_cast<AtomicWriteOp>(getSecondOp());
4001AtomicUpdateOp AtomicCaptureOp::getAtomicUpdateOp() {
4002 if (
auto op = dyn_cast<AtomicUpdateOp>(getFirstOp()))
4004 return dyn_cast<AtomicUpdateOp>(getSecondOp());
4007LogicalResult AtomicCaptureOp::verify() {
4011LogicalResult AtomicCaptureOp::verifyRegions() {
4012 if (verifyRegionsCommon().
failed())
4013 return mlir::failure();
4015 if (getFirstOp()->getAttr(
"hint") || getSecondOp()->getAttr(
"hint"))
4017 "operations inside capture region must not have hint clause");
4019 if (getFirstOp()->getAttr(
"memory_order") ||
4020 getSecondOp()->getAttr(
"memory_order"))
4022 "operations inside capture region must not have memory_order clause");
4031 const CancelOperands &clauses) {
4032 CancelOp::build(builder, state, clauses.cancelDirective, clauses.ifExpr);
4045LogicalResult CancelOp::verify() {
4046 ClauseCancellationConstructType cct = getCancelDirective();
4049 if (!structuralParent)
4050 return emitOpError() <<
"Orphaned cancel construct";
4052 if ((cct == ClauseCancellationConstructType::Parallel) &&
4053 !mlir::isa<ParallelOp>(structuralParent)) {
4054 return emitOpError() <<
"cancel parallel must appear "
4055 <<
"inside a parallel region";
4057 if (cct == ClauseCancellationConstructType::Loop) {
4060 auto wsloopOp = mlir::dyn_cast<WsloopOp>(structuralParent->
getParentOp());
4064 <<
"cancel loop must appear inside a worksharing-loop region";
4066 if (wsloopOp.getNowaitAttr()) {
4067 return emitError() <<
"A worksharing construct that is canceled "
4068 <<
"must not have a nowait clause";
4070 if (wsloopOp.getOrderedAttr()) {
4071 return emitError() <<
"A worksharing construct that is canceled "
4072 <<
"must not have an ordered clause";
4075 }
else if (cct == ClauseCancellationConstructType::Sections) {
4079 mlir::dyn_cast<SectionsOp>(structuralParent->
getParentOp());
4081 return emitOpError() <<
"cancel sections must appear "
4082 <<
"inside a sections region";
4084 if (sectionsOp.getNowait()) {
4085 return emitError() <<
"A sections construct that is canceled "
4086 <<
"must not have a nowait clause";
4089 if ((cct == ClauseCancellationConstructType::Taskgroup) &&
4090 (!mlir::isa<omp::TaskOp>(structuralParent) &&
4091 !mlir::isa<omp::TaskloopOp>(structuralParent->
getParentOp()))) {
4092 return emitOpError() <<
"cancel taskgroup must appear "
4093 <<
"inside a task region";
4103 const CancellationPointOperands &clauses) {
4104 CancellationPointOp::build(builder, state, clauses.cancelDirective);
4107LogicalResult CancellationPointOp::verify() {
4108 ClauseCancellationConstructType cct = getCancelDirective();
4111 if (!structuralParent)
4112 return emitOpError() <<
"Orphaned cancellation point";
4114 if ((cct == ClauseCancellationConstructType::Parallel) &&
4115 !mlir::isa<ParallelOp>(structuralParent)) {
4116 return emitOpError() <<
"cancellation point parallel must appear "
4117 <<
"inside a parallel region";
4121 if ((cct == ClauseCancellationConstructType::Loop) &&
4122 !mlir::isa<WsloopOp>(structuralParent->
getParentOp())) {
4123 return emitOpError() <<
"cancellation point loop must appear "
4124 <<
"inside a worksharing-loop region";
4126 if ((cct == ClauseCancellationConstructType::Sections) &&
4127 !mlir::isa<omp::SectionOp>(structuralParent)) {
4128 return emitOpError() <<
"cancellation point sections must appear "
4129 <<
"inside a sections region";
4131 if ((cct == ClauseCancellationConstructType::Taskgroup) &&
4132 !mlir::isa<omp::TaskOp>(structuralParent)) {
4133 return emitOpError() <<
"cancellation point taskgroup must appear "
4134 <<
"inside a task region";
4143LogicalResult MapBoundsOp::verify() {
4144 auto extent = getExtent();
4146 if (!extent && !upperbound)
4147 return emitError(
"expected extent or upperbound.");
4154 PrivateClauseOp::build(
4155 odsBuilder, odsState, symName, type,
4156 DataSharingClauseTypeAttr::get(odsBuilder.
getContext(),
4157 DataSharingClauseType::Private));
4160LogicalResult PrivateClauseOp::verifyRegions() {
4161 Type argType = getArgType();
4162 auto verifyTerminator = [&](
Operation *terminator,
4163 bool yieldsValue) -> LogicalResult {
4167 if (!llvm::isa<YieldOp>(terminator))
4169 <<
"expected exit block terminator to be an `omp.yield` op.";
4171 YieldOp yieldOp = llvm::cast<YieldOp>(terminator);
4172 TypeRange yieldedTypes = yieldOp.getResults().getTypes();
4175 if (yieldedTypes.empty())
4179 <<
"Did not expect any values to be yielded.";
4182 if (yieldedTypes.size() == 1 && yieldedTypes.front() == argType)
4186 <<
"Invalid yielded value. Expected type: " << argType
4189 if (yieldedTypes.empty())
4192 error << yieldedTypes;
4198 StringRef regionName,
4199 bool yieldsValue) -> LogicalResult {
4200 assert(!region.
empty());
4204 <<
"`" << regionName <<
"`: "
4205 <<
"expected " << expectedNumArgs
4208 for (
Block &block : region) {
4210 if (!block.mightHaveTerminator())
4213 if (
failed(verifyTerminator(block.getTerminator(), yieldsValue)))
4221 for (
Region *region : getRegions())
4222 for (
Type ty : region->getArgumentTypes())
4224 return emitError() <<
"Region argument type mismatch: got " << ty
4225 <<
" expected " << argType <<
".";
4228 if (!initRegion.
empty() &&
4233 DataSharingClauseType dsType = getDataSharingType();
4235 if (dsType == DataSharingClauseType::Private && !getCopyRegion().empty())
4236 return emitError(
"`private` clauses do not require a `copy` region.");
4238 if (dsType == DataSharingClauseType::FirstPrivate && getCopyRegion().empty())
4240 "`firstprivate` clauses require at least a `copy` region.");
4242 if (dsType == DataSharingClauseType::FirstPrivate &&
4247 if (!getDeallocRegion().empty() &&
4260 const MaskedOperands &clauses) {
4261 MaskedOp::build(builder, state, clauses.filteredThreadId);
4269 const ScanOperands &clauses) {
4270 ScanOp::build(builder, state, clauses.inclusiveVars, clauses.exclusiveVars);
4273LogicalResult ScanOp::verify() {
4274 if (hasExclusiveVars() == hasInclusiveVars())
4276 "Exactly one of EXCLUSIVE or INCLUSIVE clause is expected");
4277 if (WsloopOp parentWsLoopOp = (*this)->getParentOfType<WsloopOp>()) {
4278 if (parentWsLoopOp.getReductionModAttr() &&
4279 parentWsLoopOp.getReductionModAttr().getValue() ==
4280 ReductionModifier::inscan)
4283 if (SimdOp parentSimdOp = (*this)->getParentOfType<SimdOp>()) {
4284 if (parentSimdOp.getReductionModAttr() &&
4285 parentSimdOp.getReductionModAttr().getValue() ==
4286 ReductionModifier::inscan)
4289 return emitError(
"SCAN directive needs to be enclosed within a parent "
4290 "worksharing loop construct or SIMD construct with INSCAN "
4291 "reduction modifier");
4296LogicalResult AllocateDirOp::verify() {
4297 std::optional<uint64_t> align = this->getAlign();
4299 if (align.has_value()) {
4300 if ((align.value() > 0) && !llvm::has_single_bit(align.value()))
4301 return emitError() <<
"ALIGN value : " << align.value()
4302 <<
" must be power of 2";
4312mlir::Type omp::TargetAllocMemOp::getAllocatedType() {
4313 return getInTypeAttr().getValue();
4322 bool hasOperands =
false;
4323 std::int32_t typeparamsSize = 0;
4329 return mlir::failure();
4331 return mlir::failure();
4333 return mlir::failure();
4337 return mlir::failure();
4338 result.addAttribute(
"in_type", mlir::TypeAttr::get(intype));
4345 return mlir::failure();
4346 typeparamsSize = operands.size();
4349 std::int32_t shapeSize = 0;
4353 return mlir::failure();
4354 shapeSize = operands.size() - typeparamsSize;
4356 for (std::int32_t i = typeparamsSize, end = operands.size(); i != end; ++i)
4357 typeVec.push_back(idxTy);
4363 return mlir::failure();
4368 return mlir::failure();
4371 result.addAttribute(
"operandSegmentSizes",
4375 return mlir::failure();
4376 return mlir::success();
4391 if (!getTypeparams().empty()) {
4392 p <<
'(' << getTypeparams() <<
" : " << getTypeparams().getTypes() <<
')';
4399 {
"in_type",
"operandSegmentSizes"});
4402llvm::LogicalResult omp::TargetAllocMemOp::verify() {
4404 if (!mlir::dyn_cast<IntegerType>(outType))
4406 return mlir::success();
4413LogicalResult WorkdistributeOp::verify() {
4415 Region ®ion = getRegion();
4420 if (entryBlock.
empty())
4421 return emitOpError(
"region must contain a structured block");
4423 bool hasTerminator =
false;
4424 for (
Block &block : region) {
4425 if (isa<TerminatorOp>(block.back())) {
4426 if (hasTerminator) {
4427 return emitOpError(
"region must have exactly one terminator");
4429 hasTerminator =
true;
4432 if (!hasTerminator) {
4433 return emitOpError(
"region must be terminated with omp.terminator");
4437 if (isa<BarrierOp>(op)) {
4439 "explicit barriers are not allowed in workdistribute region");
4442 if (isa<ParallelOp>(op)) {
4444 "nested parallel constructs not allowed in workdistribute");
4446 if (isa<TeamsOp>(op)) {
4448 "nested teams constructs not allowed in workdistribute");
4452 if (walkResult.wasInterrupted())
4456 if (!llvm::dyn_cast<TeamsOp>(parentOp))
4457 return emitOpError(
"workdistribute must be nested under teams");
4461#define GET_ATTRDEF_CLASSES
4462#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
4464#define GET_OP_CLASSES
4465#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
4467#define GET_TYPEDEF_CLASSES
4468#include "mlir/Dialect/OpenMP/OpenMPOpsTypes.cpp.inc"
static SmallVector< Value > getTileSizes(Location loc, amx::TileType tType, RewriterBase &rewriter)
Maps the 2-dim vector shape to the two 16-bit tile sizes.
p<< " : "<< getMemRefType()<< ", "<< getType();}static LogicalResult verifyVectorMemoryOp(Operation *op, MemRefType memrefType, VectorType vectorType) { if(memrefType.getElementType() !=vectorType.getElementType()) return op-> emitOpError("requires memref and vector types of the same elemental type")
Given a list of lists of parsed operands, populates uniqueOperands with unique operands.
static std::optional< int64_t > getUpperBound(Value iv)
Gets the constant upper bound on an affine.for iv.
static LogicalResult verifyRegion(emitc::SwitchOp op, Region ®ion, const Twine &name)
static Type getElementType(Type type)
Determine the element type of type.
static ze_device_handle_t getDevice(const uint32_t driverIdx=0, const int32_t devIdx=0)
static const mlir::GenInfo * generator
static LogicalResult verifyNontemporalClause(Operation *op, OperandRange nontemporalVars)
static DenseI64ArrayAttr makeDenseI64ArrayAttr(MLIRContext *ctx, const ArrayRef< int64_t > intArray)
static constexpr StringRef getPrivateNeedsBarrierSpelling()
static LogicalResult verifyMapClause(Operation *op, OperandRange mapVars)
static LogicalResult verifyReductionVarList(Operation *op, std::optional< ArrayAttr > reductionSyms, OperandRange reductionVars, std::optional< ArrayRef< bool > > reductionByref)
Verifies Reduction Clause.
static ParseResult parseInReductionPrivateRegion(OpAsmParser &parser, Region ®ion, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &inReductionVars, SmallVectorImpl< Type > &inReductionTypes, DenseBoolArrayAttr &inReductionByref, ArrayAttr &inReductionSyms, llvm::SmallVectorImpl< OpAsmParser::UnresolvedOperand > &privateVars, llvm::SmallVectorImpl< Type > &privateTypes, ArrayAttr &privateSyms, UnitAttr &privateNeedsBarrier)
static ArrayAttr makeArrayAttr(MLIRContext *context, llvm::ArrayRef< Attribute > attrs)
static ParseResult parseClauseAttr(AsmParser &parser, ClauseAttr &attr)
static void printAllocateAndAllocator(OpAsmPrinter &p, Operation *op, OperandRange allocateVars, TypeRange allocateTypes, OperandRange allocatorVars, TypeRange allocatorTypes)
Print allocate clause.
static DenseBoolArrayAttr makeDenseBoolArrayAttr(MLIRContext *ctx, const ArrayRef< bool > boolArray)
static std::string generateLoopNestingName(StringRef prefix, CanonicalLoopOp op)
Generate a name of a canonical loop nest of the format <prefix>(_r<idx>_s<idx>)*.
static void printClauseWithRegionArgs(OpAsmPrinter &p, MLIRContext *ctx, StringRef clauseName, ValueRange argsSubrange, ValueRange operands, TypeRange types, ArrayAttr symbols=nullptr, DenseI64ArrayAttr mapIndices=nullptr, DenseBoolArrayAttr byref=nullptr, ReductionModifierAttr modifier=nullptr, UnitAttr needsBarrier=nullptr)
static void printBlockArgClause(OpAsmPrinter &p, MLIRContext *ctx, StringRef clauseName, ValueRange argsSubrange, std::optional< MapPrintArgs > mapArgs)
static void printBlockArgRegion(OpAsmPrinter &p, Operation *op, Region ®ion, const AllRegionPrintArgs &args)
static ParseResult parseGranularityClause(OpAsmParser &parser, ClauseTypeAttr &prescriptiveness, std::optional< OpAsmParser::UnresolvedOperand > &operand, Type &operandType, std::optional< ClauseType >(*symbolizeClause)(StringRef), StringRef clauseName)
static ParseResult parseBlockArgRegion(OpAsmParser &parser, Region ®ion, AllRegionParseArgs args)
static ParseResult parseLoopTransformClis(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &generateesOperands, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &applyeesOperands)
static ParseResult parseSynchronizationHint(OpAsmParser &parser, IntegerAttr &hintAttr)
Parses a Synchronization Hint clause.
static ParseResult parseLinearClause(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &linearVars, SmallVectorImpl< Type > &linearTypes, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &linearStepVars)
linear ::= linear ( linear-list ) linear-list := linear-val | linear-val linear-list linear-val := ss...
static void printScheduleClause(OpAsmPrinter &p, Operation *op, ClauseScheduleKindAttr scheduleKind, ScheduleModifierAttr scheduleMod, UnitAttr scheduleSimd, Value scheduleChunk, Type scheduleChunkType)
Print schedule clause.
static void printCopyprivate(OpAsmPrinter &p, Operation *op, OperandRange copyprivateVars, TypeRange copyprivateTypes, std::optional< ArrayAttr > copyprivateSyms)
Print Copyprivate clause.
static ParseResult parseOrderClause(OpAsmParser &parser, ClauseOrderKindAttr &order, OrderModifierAttr &orderMod)
static bool mapTypeToBool(ClauseMapFlags value, ClauseMapFlags flag)
static void printAlignedClause(OpAsmPrinter &p, Operation *op, ValueRange alignedVars, TypeRange alignedTypes, std::optional< ArrayAttr > alignments)
Print Aligned Clause.
static LogicalResult verifySynchronizationHint(Operation *op, uint64_t hint)
Verifies a synchronization hint clause.
static ParseResult parseUseDeviceAddrUseDevicePtrRegion(OpAsmParser &parser, Region ®ion, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &useDeviceAddrVars, SmallVectorImpl< Type > &useDeviceAddrTypes, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &useDevicePtrVars, SmallVectorImpl< Type > &useDevicePtrTypes)
static void printLinearClause(OpAsmPrinter &p, Operation *op, ValueRange linearVars, TypeRange linearTypes, ValueRange linearStepVars)
Print Linear Clause.
*attr dict without keyword *static mlir::ParseResult parseTargetAllocMemOp(mlir::OpAsmParser &parser, mlir::OperationState &result)
operation ::= res = (omp.target_alloc_mem) $device : devicetype, $in_type ( ( $typeparams ) )?...
static Operation * findCapturedOmpOp(Operation *rootOp, bool checkSingleMandatoryExec, llvm::function_ref< bool(Operation *)> siblingAllowedFn)
static void printInReductionPrivateReductionRegion(OpAsmPrinter &p, Operation *op, Region ®ion, ValueRange inReductionVars, TypeRange inReductionTypes, DenseBoolArrayAttr inReductionByref, ArrayAttr inReductionSyms, ValueRange privateVars, TypeRange privateTypes, ArrayAttr privateSyms, UnitAttr privateNeedsBarrier, ReductionModifierAttr reductionMod, ValueRange reductionVars, TypeRange reductionTypes, DenseBoolArrayAttr reductionByref, ArrayAttr reductionSyms)
static void printInReductionPrivateRegion(OpAsmPrinter &p, Operation *op, Region ®ion, ValueRange inReductionVars, TypeRange inReductionTypes, DenseBoolArrayAttr inReductionByref, ArrayAttr inReductionSyms, ValueRange privateVars, TypeRange privateTypes, ArrayAttr privateSyms, UnitAttr privateNeedsBarrier)
static void printSynchronizationHint(OpAsmPrinter &p, Operation *op, IntegerAttr hintAttr)
Prints a Synchronization Hint clause.
static void printGranularityClause(OpAsmPrinter &p, Operation *op, ClauseTypeAttr prescriptiveness, Value operand, mlir::Type operandType, StringRef(*stringifyClauseType)(ClauseType))
static void printDependVarList(OpAsmPrinter &p, Operation *op, OperandRange dependVars, TypeRange dependTypes, std::optional< ArrayAttr > dependKinds)
Print Depend clause.
static void printTargetOpRegion(OpAsmPrinter &p, Operation *op, Region ®ion, ValueRange hasDeviceAddrVars, TypeRange hasDeviceAddrTypes, ValueRange hostEvalVars, TypeRange hostEvalTypes, ValueRange inReductionVars, TypeRange inReductionTypes, DenseBoolArrayAttr inReductionByref, ArrayAttr inReductionSyms, ValueRange mapVars, TypeRange mapTypes, ValueRange privateVars, TypeRange privateTypes, ArrayAttr privateSyms, UnitAttr privateNeedsBarrier, DenseI64ArrayAttr privateMaps)
static Operation * getParentInSameDialect(Operation *thisOp)
static LogicalResult verifyCopyprivateVarList(Operation *op, OperandRange copyprivateVars, std::optional< ArrayAttr > copyprivateSyms)
Verifies CopyPrivate Clause.
static LogicalResult verifyAlignedClause(Operation *op, std::optional< ArrayAttr > alignments, OperandRange alignedVars)
static ParseResult parseTargetOpRegion(OpAsmParser &parser, Region ®ion, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &hasDeviceAddrVars, SmallVectorImpl< Type > &hasDeviceAddrTypes, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &hostEvalVars, SmallVectorImpl< Type > &hostEvalTypes, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &inReductionVars, SmallVectorImpl< Type > &inReductionTypes, DenseBoolArrayAttr &inReductionByref, ArrayAttr &inReductionSyms, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &mapVars, SmallVectorImpl< Type > &mapTypes, llvm::SmallVectorImpl< OpAsmParser::UnresolvedOperand > &privateVars, llvm::SmallVectorImpl< Type > &privateTypes, ArrayAttr &privateSyms, UnitAttr &privateNeedsBarrier, DenseI64ArrayAttr &privateMaps)
static ParseResult parsePrivateRegion(OpAsmParser &parser, Region ®ion, llvm::SmallVectorImpl< OpAsmParser::UnresolvedOperand > &privateVars, llvm::SmallVectorImpl< Type > &privateTypes, ArrayAttr &privateSyms, UnitAttr &privateNeedsBarrier)
static void printNumTasksClause(OpAsmPrinter &p, Operation *op, ClauseNumTasksTypeAttr numTasksMod, Value numTasks, mlir::Type numTasksType)
static void printLoopTransformClis(OpAsmPrinter &p, TileOp op, OperandRange generatees, OperandRange applyees)
static void printPrivateRegion(OpAsmPrinter &p, Operation *op, Region ®ion, ValueRange privateVars, TypeRange privateTypes, ArrayAttr privateSyms, UnitAttr privateNeedsBarrier)
static void printPrivateReductionRegion(OpAsmPrinter &p, Operation *op, Region ®ion, ValueRange privateVars, TypeRange privateTypes, ArrayAttr privateSyms, UnitAttr privateNeedsBarrier, ReductionModifierAttr reductionMod, ValueRange reductionVars, TypeRange reductionTypes, DenseBoolArrayAttr reductionByref, ArrayAttr reductionSyms)
static void printTaskReductionRegion(OpAsmPrinter &p, Operation *op, Region ®ion, ValueRange taskReductionVars, TypeRange taskReductionTypes, DenseBoolArrayAttr taskReductionByref, ArrayAttr taskReductionSyms)
static LogicalResult verifyOrderedParent(Operation &op)
static void printOrderClause(OpAsmPrinter &p, Operation *op, ClauseOrderKindAttr order, OrderModifierAttr orderMod)
static ParseResult parseBlockArgClause(OpAsmParser &parser, llvm::SmallVectorImpl< OpAsmParser::Argument > &entryBlockArgs, StringRef keyword, std::optional< MapParseArgs > mapArgs)
static ParseResult parseClauseWithRegionArgs(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &operands, SmallVectorImpl< Type > &types, SmallVectorImpl< OpAsmParser::Argument > ®ionPrivateArgs, ArrayAttr *symbols=nullptr, DenseI64ArrayAttr *mapIndices=nullptr, DenseBoolArrayAttr *byref=nullptr, ReductionModifierAttr *modifier=nullptr, UnitAttr *needsBarrier=nullptr)
static LogicalResult verifyPrivateVarsMapping(TargetOp targetOp)
static ParseResult parseScheduleClause(OpAsmParser &parser, ClauseScheduleKindAttr &scheduleAttr, ScheduleModifierAttr &scheduleMod, UnitAttr &scheduleSimd, std::optional< OpAsmParser::UnresolvedOperand > &chunkSize, Type &chunkType)
schedule ::= schedule ( sched-list ) sched-list ::= sched-val | sched-val sched-list | sched-val ,...
static void printClauseAttr(OpAsmPrinter &p, Operation *op, ClauseAttr attr)
static ParseResult parseAllocateAndAllocator(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &allocateVars, SmallVectorImpl< Type > &allocateTypes, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &allocatorVars, SmallVectorImpl< Type > &allocatorTypes)
Parse an allocate clause with allocators and a list of operands with types.
static void printMembersIndex(OpAsmPrinter &p, MapInfoOp op, ArrayAttr membersIdx)
static bool canPromoteToNoLoop(Operation *capturedOp, TeamsOp teamsOp, WsloopOp *wsLoopOp)
Check if we can promote SPMD kernel to No-Loop kernel.
static void printCaptureType(OpAsmPrinter &p, Operation *op, VariableCaptureKindAttr mapCaptureType)
static bool opInGlobalImplicitParallelRegion(Operation *op)
static void printUseDeviceAddrUseDevicePtrRegion(OpAsmPrinter &p, Operation *op, Region ®ion, ValueRange useDeviceAddrVars, TypeRange useDeviceAddrTypes, ValueRange useDevicePtrVars, TypeRange useDevicePtrTypes)
static LogicalResult verifyPrivateVarList(OpType &op)
static ParseResult parseNumTasksClause(OpAsmParser &parser, ClauseNumTasksTypeAttr &numTasksMod, std::optional< OpAsmParser::UnresolvedOperand > &numTasks, Type &numTasksType)
static ParseResult parseAlignedClause(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &alignedVars, SmallVectorImpl< Type > &alignedTypes, ArrayAttr &alignmentsAttr)
aligned ::= aligned ( aligned-list ) aligned-list := aligned-val | aligned-val aligned-list aligned-v...
static ParseResult parsePrivateReductionRegion(OpAsmParser &parser, Region ®ion, llvm::SmallVectorImpl< OpAsmParser::UnresolvedOperand > &privateVars, llvm::SmallVectorImpl< Type > &privateTypes, ArrayAttr &privateSyms, UnitAttr &privateNeedsBarrier, ReductionModifierAttr &reductionMod, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &reductionVars, SmallVectorImpl< Type > &reductionTypes, DenseBoolArrayAttr &reductionByref, ArrayAttr &reductionSyms)
static ParseResult parseInReductionPrivateReductionRegion(OpAsmParser &parser, Region ®ion, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &inReductionVars, SmallVectorImpl< Type > &inReductionTypes, DenseBoolArrayAttr &inReductionByref, ArrayAttr &inReductionSyms, llvm::SmallVectorImpl< OpAsmParser::UnresolvedOperand > &privateVars, llvm::SmallVectorImpl< Type > &privateTypes, ArrayAttr &privateSyms, UnitAttr &privateNeedsBarrier, ReductionModifierAttr &reductionMod, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &reductionVars, SmallVectorImpl< Type > &reductionTypes, DenseBoolArrayAttr &reductionByref, ArrayAttr &reductionSyms)
static ParseResult parseCaptureType(OpAsmParser &parser, VariableCaptureKindAttr &mapCaptureType)
static ParseResult parseTaskReductionRegion(OpAsmParser &parser, Region ®ion, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &taskReductionVars, SmallVectorImpl< Type > &taskReductionTypes, DenseBoolArrayAttr &taskReductionByref, ArrayAttr &taskReductionSyms)
static ParseResult parseGrainsizeClause(OpAsmParser &parser, ClauseGrainsizeTypeAttr &grainsizeMod, std::optional< OpAsmParser::UnresolvedOperand > &grainsize, Type &grainsizeType)
static ParseResult parseCopyprivate(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > ©privateVars, SmallVectorImpl< Type > ©privateTypes, ArrayAttr ©privateSyms)
copyprivate-entry-list ::= copyprivate-entry | copyprivate-entry-list , copyprivate-entry copyprivate...
static LogicalResult verifyDependVarList(Operation *op, std::optional< ArrayAttr > dependKinds, OperandRange dependVars)
Verifies Depend clause.
static ParseResult parseDependVarList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &dependVars, SmallVectorImpl< Type > &dependTypes, ArrayAttr &dependKinds)
depend-entry-list ::= depend-entry | depend-entry-list , depend-entry depend-entry ::= depend-kind ->...
static LogicalResult verifyMapInfoDefinedArgs(Operation *op, StringRef clauseName, OperandRange vars)
static void printGrainsizeClause(OpAsmPrinter &p, Operation *op, ClauseGrainsizeTypeAttr grainsizeMod, Value grainsize, mlir::Type grainsizeType)
static ParseResult verifyScheduleModifiers(OpAsmParser &parser, SmallVectorImpl< SmallString< 12 > > &modifiers)
static bool isUnique(It begin, It end)
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual ParseResult parseMinus()=0
Parse a '-' token.
@ Paren
Parens surrounding zero or more operands.
@ None
Zero or more operands with no delimiters.
virtual ParseResult parseColonTypeList(SmallVectorImpl< Type > &result)=0
Parse a colon followed by a type list, which must have at least one type.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual ParseResult parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
virtual ParseResult parseOptionalEqual()=0
Parse a = token if present.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
MLIRContext * getContext() const
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseOptionalColon()=0
Parse a : token if present.
virtual ParseResult parseLSquare()=0
Parse a [ token.
virtual ParseResult parseRSquare()=0
Parse a ] token.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseOptionalArrow()=0
Parse a '->' token if present.
ParseResult addTypeToList(Type type, SmallVectorImpl< Type > &result)
Add the specified type to the end of the specified type list and return success.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual ParseResult parseEqual()=0
Parse a = token.
virtual ParseResult parseColonType(Type &result)=0
Parse a colon followed by a type.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseOptionalComma()=0
Parse a , token if present.
virtual ParseResult parseColon()=0
Parse a : token.
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseOptionalLess()=0
Parse a '<' token if present.
virtual ParseResult parseArrow()=0
Parse a '->' token.
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseType(Type &result)=0
Parse a type.
virtual ParseResult parseComma()=0
Parse a , token.
virtual ParseResult parseOptionalLParen()=0
Parse a ( token if present.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
ValueTypeRange< BlockArgListType > getArgumentTypes()
Return a range containing the types of the arguments for this block.
BlockArgument getArgument(unsigned i)
unsigned getNumArguments()
SuccessorRange getSuccessors()
BlockArgListType getArguments()
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
IntegerType getIntegerType(unsigned width)
MLIRContext * getContext() const
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
Diagnostic & append(Arg1 &&arg1, Arg2 &&arg2, Args &&...args)
Append arguments to the diagnostic.
Diagnostic & appendOp(Operation &op, const OpPrintingFlags &flags)
Append an operation with the given printing flags.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
A class for computing basic dominance information.
bool dominates(Operation *a, Operation *b) const
Return true if operation A dominates operation B, i.e.
This class represents a diagnostic that is inflight and set to be reported.
Diagnostic & attachNote(std::optional< Location > noteLoc=std::nullopt)
Attaches a note to this diagnostic.
MLIRContext is the top-level object for a collection of MLIR operations.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual ParseResult parseRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region.
virtual ParseResult parseArgument(Argument &result, bool allowType=false, bool allowAttrs=false)=0
Parse a single argument with the following syntax:
virtual ParseResult parseArgumentList(SmallVectorImpl< Argument > &result, Delimiter delimiter=Delimiter::None, bool allowType=false, bool allowAttrs=false)=0
Parse zero or more arguments with a specified surrounding delimiter.
virtual ParseResult resolveOperand(const UnresolvedOperand &operand, Type type, SmallVectorImpl< Value > &result)=0
Resolve an operand to an SSA value, emitting an error on failure.
ParseResult resolveOperands(Operands &&operands, Type type, SmallVectorImpl< Value > &result)
Resolve a list of operands to SSA values, emitting an error on failure, or appending the results to t...
virtual ParseResult parseOperand(UnresolvedOperand &result, bool allowResultNumber=true)=0
Parse a single SSA value operand name along with a result number if allowResultNumber is true.
virtual ParseResult parseOperandList(SmallVectorImpl< UnresolvedOperand > &result, Delimiter delimiter=Delimiter::None, bool allowResultNumber=true, int requiredOperandCount=-1)=0
Parse zero or more SSA comma-separated operand references with a specified surrounding delimiter,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values.
virtual void printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true, bool printEmptyBlock=false)=0
Prints a region.
virtual void printOperand(Value value)=0
Print implementations for various things an operation contains.
This class helps build Operations.
This class represents an operand of an operation.
Set of flags used to control the behavior of the various IR print methods (e.g.
This class provides the API for ops that are known to be isolated from above.
This class provides the API for ops that are known to be terminators.
This class indicates that the regions associated with this op don't have terminators.
This class implements the operand iterators for the Operation class.
Operation is the basic unit of execution within MLIR.
Dialect * getDialect()
Return the dialect this operation is associated with, or nullptr if the associated dialect is not loa...
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Block * getBlock()
Returns the operation block that contains this operation.
unsigned getNumRegions()
Returns the number of regions held by this operation.
Location getLoc()
The source location the operation was defined or derived from.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
user_range getUsers()
Returns a range of all users.
Region * getParentRegion()
Returns the region to which the instruction belongs.
MLIRContext * getContext()
Return the context this operation is associated with.
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
This class contains a list of basic blocks and a link to the parent operation it is attached to.
BlockArgListType getArguments()
OpIterator op_begin()
Return iterators that walk the operations nested directly within this region.
iterator_range< OpIterator > getOps()
unsigned getNumArguments()
Location getLoc()
Return a location for this region.
BlockArgument getArgument(unsigned i)
Operation * getParentOp()
Return the parent operation this region is attached to.
BlockListType & getBlocks()
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
Resource * getResource() const
Return the resource that the effect applies to.
EffectT * getEffect() const
Return the effect being applied.
This class represents a collection of SymbolTables.
virtual Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides an abstraction over the different types of ranges over Values.
type_range getType() const
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Type getType() const
Return the type of this value.
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
static WalkResult interrupt()
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< bool > content)
bool isReachableFromEntry(Block *a) const
Return true if the specified block is reachable from the entry block of its region.
Operation * getOwner() const
Return the owner of this operand.
SideEffects::EffectInstance< Effect > EffectInstance
bool isPerfectlyNested(ArrayRef< AffineForOp > loops)
Returns true if loops is a perfectly nested loop nest, where loops appear in it from outermost to inn...
TargetEnterDataOperands TargetEnterExitUpdateDataOperands
omp.target_enter_data, omp.target_exit_data and omp.target_update take the same clauses,...
std::tuple< NewCliOp, OpOperand *, OpOperand * > decodeCli(mlir::Value cli)
Find the omp.new_cli, generator, and consumer of a canonical loop info.
Include the generated interface declarations.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
function_ref< void(Value, StringRef)> OpAsmSetValueNameFn
A functor used to set the name of the start of a result group of an operation.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::TypeSwitch< T, ResultT > TypeSwitch
SmallVector< Loops, 8 > tile(ArrayRef< scf::ForOp > forOps, ArrayRef< Value > sizes, ArrayRef< scf::ForOp > targets)
Performs tiling fo imperfectly nested loops (with interchange) by strip-mining the forOps by sizes an...
detail::DenseArrayAttrImpl< bool > DenseBoolArrayAttr
function_ref< void(Block *, StringRef)> OpAsmSetBlockNameFn
A functor used to set the name of blocks in regions directly nested under an operation.
This is the representation of an operand reference.
This class provides APIs and verifiers for ops with regions having a single block.
This represents an operation in an abstracted form, suitable for use with the builder APIs.
void addOperands(ValueRange newOperands)
void addAttributes(ArrayRef< NamedAttribute > newAttributes)
Add an array of named attributes.
void addTypes(ArrayRef< Type > newTypes)
Region * addRegion()
Create a region that should be attached to the operation.