diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/OpenMPClause.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/AST/OpenMPClause.cpp | 381 |
1 files changed, 328 insertions, 53 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/OpenMPClause.cpp b/contrib/llvm-project/clang/lib/AST/OpenMPClause.cpp index 50f40395a197..04f680a8f5c9 100644 --- a/contrib/llvm-project/clang/lib/AST/OpenMPClause.cpp +++ b/contrib/llvm-project/clang/lib/AST/OpenMPClause.cpp @@ -23,6 +23,7 @@ #include "llvm/Support/ErrorHandling.h" #include <algorithm> #include <cassert> +#include <optional> using namespace clang; using namespace llvm; @@ -102,6 +103,8 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { return static_cast<const OMPNocontextClause *>(C); case OMPC_filter: return static_cast<const OMPFilterClause *>(C); + case OMPC_ompx_dyn_cgroup_mem: + return static_cast<const OMPXDynCGroupMemClause *>(C); case OMPC_default: case OMPC_proc_bind: case OMPC_safelen: @@ -126,6 +129,8 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_compare: + case OMPC_fail: case OMPC_seq_cst: case OMPC_acq_rel: case OMPC_acquire: @@ -145,11 +150,15 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { case OMPC_use_device_ptr: case OMPC_use_device_addr: case OMPC_is_device_ptr: + case OMPC_has_device_addr: case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: case OMPC_dynamic_allocators: case OMPC_atomic_default_mem_order: + case OMPC_at: + case OMPC_severity: + case OMPC_message: case OMPC_device_type: case OMPC_match: case OMPC_nontemporal: @@ -160,6 +169,9 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { case OMPC_exclusive: case OMPC_uses_allocators: case OMPC_affinity: + case OMPC_when: + case OMPC_bind: + case OMPC_ompx_bare: break; default: break; @@ -215,6 +227,8 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_compare: + case OMPC_fail: case OMPC_seq_cst: case OMPC_acq_rel: case OMPC_acquire: @@ -240,11 +254,15 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) case OMPC_use_device_ptr: case OMPC_use_device_addr: case OMPC_is_device_ptr: + case OMPC_has_device_addr: case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: case OMPC_dynamic_allocators: case OMPC_atomic_default_mem_order: + case OMPC_at: + case OMPC_severity: + case OMPC_message: case OMPC_device_type: case OMPC_match: case OMPC_nontemporal: @@ -257,6 +275,8 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) case OMPC_exclusive: case OMPC_uses_allocators: case OMPC_affinity: + case OMPC_when: + case OMPC_bind: break; default: break; @@ -299,7 +319,7 @@ OMPClause::child_range OMPNumTasksClause::used_children() { OMPClause::child_range OMPFinalClause::used_children() { if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) return child_range(C, C + 1); - return child_range(&Condition, &Condition + 1); + return children(); } OMPClause::child_range OMPPriorityClause::used_children() { @@ -311,13 +331,13 @@ OMPClause::child_range OMPPriorityClause::used_children() { OMPClause::child_range OMPNovariantsClause::used_children() { if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) return child_range(C, C + 1); - return child_range(&Condition, &Condition + 1); + return children(); } OMPClause::child_range OMPNocontextClause::used_children() { if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) return child_range(C, C + 1); - return child_range(&Condition, &Condition + 1); + return children(); } OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num, @@ -353,7 +373,7 @@ void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop, } ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const { - return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops); + return llvm::ArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops); } void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) { @@ -565,15 +585,17 @@ void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) { OMPLinearClause *OMPLinearClause::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, - SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, - ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, - Stmt *PreInit, Expr *PostUpdate) { + SourceLocation ColonLoc, SourceLocation StepModifierLoc, + SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PL, + ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, + Expr *PostUpdate) { // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions // (Step and CalcStep), list of used expression + step. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1)); - OMPLinearClause *Clause = new (Mem) OMPLinearClause( - StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); + OMPLinearClause *Clause = + new (Mem) OMPLinearClause(StartLoc, LParenLoc, Modifier, ModifierLoc, + ColonLoc, StepModifierLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setPrivates(PL); Clause->setInits(IL); @@ -625,6 +647,13 @@ OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, return new (Mem) OMPAlignedClause(NumVars); } +OMPAlignClause *OMPAlignClause::Create(const ASTContext &C, Expr *A, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + return new (C) OMPAlignClause(A, StartLoc, LParenLoc, EndLoc); +} + void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " "not the same as the " @@ -1025,19 +1054,19 @@ OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) { OMPDependClause * OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, - Expr *DepModifier, OpenMPDependClauseKind DepKind, - SourceLocation DepLoc, SourceLocation ColonLoc, + DependDataTy Data, Expr *DepModifier, ArrayRef<Expr *> VL, unsigned NumLoops) { void *Mem = C.Allocate( totalSizeToAlloc<Expr *>(VL.size() + /*depend-modifier*/ 1 + NumLoops), alignof(OMPDependClause)); OMPDependClause *Clause = new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); - Clause->setVarRefs(VL); - Clause->setDependencyKind(DepKind); - Clause->setDependencyLoc(DepLoc); - Clause->setColonLoc(ColonLoc); + Clause->setDependencyKind(Data.DepKind); + Clause->setDependencyLoc(Data.DepLoc); + Clause->setColonLoc(Data.ColonLoc); + Clause->setOmpAllMemoryLoc(Data.OmpAllMemoryLoc); Clause->setModifier(DepModifier); + Clause->setVarRefs(VL); for (unsigned I = 0 ; I < NumLoops; ++I) Clause->setLoopData(I, nullptr); return Clause; @@ -1112,7 +1141,7 @@ OMPMapClause *OMPMapClause::Create( const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, - ArrayRef<OpenMPMapModifierKind> MapModifiers, + Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapModifiers, ArrayRef<SourceLocation> MapModifiersLoc, NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) { @@ -1135,7 +1164,7 @@ OMPMapClause *OMPMapClause::Create( void *Mem = C.Allocate( totalSizeToAlloc<Expr *, ValueDecl *, unsigned, OMPClauseMappableExprCommon::MappableComponent>( - 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, + 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations, Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, Sizes.NumComponents)); OMPMapClause *Clause = new (Mem) @@ -1144,6 +1173,7 @@ OMPMapClause *OMPMapClause::Create( Clause->setVarRefs(Vars); Clause->setUDMapperRefs(UDMapperRefs); + Clause->setIteratorModifier(IteratorModifier); Clause->setClauseInfo(Declarations, ComponentLists); Clause->setMapType(Type); Clause->setMapLoc(TypeLoc); @@ -1156,10 +1186,12 @@ OMPMapClause::CreateEmpty(const ASTContext &C, void *Mem = C.Allocate( totalSizeToAlloc<Expr *, ValueDecl *, unsigned, OMPClauseMappableExprCommon::MappableComponent>( - 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, + 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations, Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, Sizes.NumComponents)); - return new (Mem) OMPMapClause(Sizes); + OMPMapClause *Clause = new (Mem) OMPMapClause(Sizes); + Clause->setIteratorModifier(nullptr); + return Clause; } OMPToClause *OMPToClause::Create( @@ -1419,6 +1451,53 @@ OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C, return new (Mem) OMPIsDevicePtrClause(Sizes); } +OMPHasDeviceAddrClause * +OMPHasDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, + ArrayRef<Expr *> Vars, + ArrayRef<ValueDecl *> Declarations, + MappableExprComponentListsRef ComponentLists) { + OMPMappableExprListSizeTy Sizes; + Sizes.NumVars = Vars.size(); + Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); + Sizes.NumComponentLists = ComponentLists.size(); + Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); + + // We need to allocate: + // NumVars x Expr* - we have an original list expression for each clause list + // entry. + // NumUniqueDeclarations x ValueDecl* - unique base declarations associated + // with each component list. + // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the + // number of lists for each unique declaration and the size of each component + // list. + // NumComponents x MappableComponent - the total of all the components in all + // the lists. + void *Mem = C.Allocate( + totalSizeToAlloc<Expr *, ValueDecl *, unsigned, + OMPClauseMappableExprCommon::MappableComponent>( + Sizes.NumVars, Sizes.NumUniqueDeclarations, + Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, + Sizes.NumComponents)); + + auto *Clause = new (Mem) OMPHasDeviceAddrClause(Locs, Sizes); + + Clause->setVarRefs(Vars); + Clause->setClauseInfo(Declarations, ComponentLists); + return Clause; +} + +OMPHasDeviceAddrClause * +OMPHasDeviceAddrClause::CreateEmpty(const ASTContext &C, + const OMPMappableExprListSizeTy &Sizes) { + void *Mem = C.Allocate( + totalSizeToAlloc<Expr *, ValueDecl *, unsigned, + OMPClauseMappableExprCommon::MappableComponent>( + Sizes.NumVars, Sizes.NumUniqueDeclarations, + Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, + Sizes.NumComponents)); + return new (Mem) OMPHasDeviceAddrClause(Sizes); +} + OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, @@ -1564,18 +1643,19 @@ OMPAffinityClause *OMPAffinityClause::CreateEmpty(const ASTContext &C, } OMPInitClause *OMPInitClause::Create(const ASTContext &C, Expr *InteropVar, - ArrayRef<Expr *> PrefExprs, bool IsTarget, - bool IsTargetSync, SourceLocation StartLoc, + OMPInteropInfo &InteropInfo, + SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc) { - void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(PrefExprs.size() + 1)); - auto *Clause = - new (Mem) OMPInitClause(IsTarget, IsTargetSync, StartLoc, LParenLoc, - VarLoc, EndLoc, PrefExprs.size() + 1); + void *Mem = + C.Allocate(totalSizeToAlloc<Expr *>(InteropInfo.PreferTypes.size() + 1)); + auto *Clause = new (Mem) OMPInitClause( + InteropInfo.IsTarget, InteropInfo.IsTargetSync, StartLoc, LParenLoc, + VarLoc, EndLoc, InteropInfo.PreferTypes.size() + 1); Clause->setInteropVar(InteropVar); - llvm::copy(PrefExprs, Clause->getTrailingObjects<Expr *>() + 1); + llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects<Expr *>() + 1); return Clause; } @@ -1584,6 +1664,62 @@ OMPInitClause *OMPInitClause::CreateEmpty(const ASTContext &C, unsigned N) { return new (Mem) OMPInitClause(N); } +OMPBindClause * +OMPBindClause::Create(const ASTContext &C, OpenMPBindClauseKind K, + SourceLocation KLoc, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation EndLoc) { + return new (C) OMPBindClause(K, KLoc, StartLoc, LParenLoc, EndLoc); +} + +OMPBindClause *OMPBindClause::CreateEmpty(const ASTContext &C) { + return new (C) OMPBindClause(); +} + +OMPDoacrossClause * +OMPDoacrossClause::Create(const ASTContext &C, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation EndLoc, + OpenMPDoacrossClauseModifier DepType, + SourceLocation DepLoc, SourceLocation ColonLoc, + ArrayRef<Expr *> VL, unsigned NumLoops) { + void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops), + alignof(OMPDoacrossClause)); + OMPDoacrossClause *Clause = new (Mem) + OMPDoacrossClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); + Clause->setDependenceType(DepType); + Clause->setDependenceLoc(DepLoc); + Clause->setColonLoc(ColonLoc); + Clause->setVarRefs(VL); + for (unsigned I = 0; I < NumLoops; ++I) + Clause->setLoopData(I, nullptr); + return Clause; +} + +OMPDoacrossClause *OMPDoacrossClause::CreateEmpty(const ASTContext &C, + unsigned N, + unsigned NumLoops) { + void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops), + alignof(OMPDoacrossClause)); + return new (Mem) OMPDoacrossClause(N, NumLoops); +} + +void OMPDoacrossClause::setLoopData(unsigned NumLoop, Expr *Cnt) { + assert(NumLoop < NumLoops && "Loop index must be less number of loops."); + auto *It = std::next(getVarRefs().end(), NumLoop); + *It = Cnt; +} + +Expr *OMPDoacrossClause::getLoopData(unsigned NumLoop) { + assert(NumLoop < NumLoops && "Loop index must be less number of loops."); + auto *It = std::next(getVarRefs().end(), NumLoop); + return *It; +} + +const Expr *OMPDoacrossClause::getLoopData(unsigned NumLoop) const { + assert(NumLoop < NumLoops && "Loop index must be less number of loops."); + const auto *It = std::next(getVarRefs().end(), NumLoop); + return *It; +} + //===----------------------------------------------------------------------===// // OpenMP clauses printing methods //===----------------------------------------------------------------------===// @@ -1608,6 +1744,12 @@ void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) { OS << ")"; } +void OMPClausePrinter::VisitOMPAlignClause(OMPAlignClause *Node) { + OS << "align("; + Node->getAlignment()->printPretty(OS, nullptr, Policy, 0); + OS << ")"; +} + void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) { OS << "safelen("; Node->getSafelen()->printPretty(OS, nullptr, Policy, 0); @@ -1623,7 +1765,7 @@ void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) { void OMPClausePrinter::VisitOMPSizesClause(OMPSizesClause *Node) { OS << "sizes("; bool First = true; - for (auto Size : Node->getSizesRefs()) { + for (auto *Size : Node->getSizesRefs()) { if (!First) OS << ", "; Size->printPretty(OS, nullptr, Policy, 0); @@ -1702,6 +1844,22 @@ void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause( << ")"; } +void OMPClausePrinter::VisitOMPAtClause(OMPAtClause *Node) { + OS << "at(" << getOpenMPSimpleClauseTypeName(OMPC_at, Node->getAtKind()) + << ")"; +} + +void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) { + OS << "severity(" + << getOpenMPSimpleClauseTypeName(OMPC_severity, Node->getSeverityKind()) + << ")"; +} + +void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause *Node) { + OS << "message(\"" + << cast<StringLiteral>(Node->getMessageString())->getString() << "\")"; +} + void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) { OS << "schedule("; if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { @@ -1765,6 +1923,20 @@ void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) { OS << "capture"; } +void OMPClausePrinter::VisitOMPCompareClause(OMPCompareClause *) { + OS << "compare"; +} + +void OMPClausePrinter::VisitOMPFailClause(OMPFailClause *Node) { + OS << "fail"; + if (Node) { + OS << "("; + OS << getOpenMPSimpleClauseTypeName( + Node->getClauseKind(), static_cast<int>(Node->getFailParameter())); + OS << ")"; + } +} + void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { OS << "seq_cst"; } @@ -1822,12 +1994,22 @@ void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) { void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) { OS << "grainsize("; + OpenMPGrainsizeClauseModifier Modifier = Node->getModifier(); + if (Modifier != OMPC_GRAINSIZE_unknown) { + OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier) + << ": "; + } Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0); OS << ")"; } void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) { OS << "num_tasks("; + OpenMPNumTasksClauseModifier Modifier = Node->getModifier(); + if (Modifier != OMPC_NUMTASKS_unknown) { + OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier) + << ": "; + } Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0); OS << ")"; } @@ -2039,16 +2221,20 @@ void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) { void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) { if (!Node->varlist_empty()) { OS << "linear"; + VisitOMPClauseList(Node, '('); + if (Node->getModifierLoc().isValid() || Node->getStep() != nullptr) { + OS << ": "; + } if (Node->getModifierLoc().isValid()) { - OS << '(' - << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier()); + OS << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier()); } - VisitOMPClauseList(Node, '('); - if (Node->getModifierLoc().isValid()) - OS << ')'; if (Node->getStep() != nullptr) { - OS << ": "; + if (Node->getModifierLoc().isValid()) { + OS << ", "; + } + OS << "step("; Node->getStep()->printPretty(OS, nullptr, Policy, 0); + OS << ")"; } OS << ")"; } @@ -2101,11 +2287,23 @@ void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) { DepModifier->printPretty(OS, nullptr, Policy); OS << ", "; } - OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), - Node->getDependencyKind()); - if (!Node->varlist_empty()) { + OpenMPDependClauseKind DepKind = Node->getDependencyKind(); + OpenMPDependClauseKind PrintKind = DepKind; + bool IsOmpAllMemory = false; + if (PrintKind == OMPC_DEPEND_outallmemory) { + PrintKind = OMPC_DEPEND_out; + IsOmpAllMemory = true; + } else if (PrintKind == OMPC_DEPEND_inoutallmemory) { + PrintKind = OMPC_DEPEND_inout; + IsOmpAllMemory = true; + } + OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), PrintKind); + if (!Node->varlist_empty() || IsOmpAllMemory) OS << " :"; - VisitOMPClauseList(Node, ' '); + VisitOMPClauseList(Node, ' '); + if (IsOmpAllMemory) { + OS << (Node->varlist_empty() ? " " : ","); + OS << "omp_all_memory"; } OS << ")"; } @@ -2121,16 +2319,27 @@ static void PrintMapper(raw_ostream &OS, T *Node, OS << Node->getMapperIdInfo() << ')'; } +template <typename T> +static void PrintIterator(raw_ostream &OS, T *Node, + const PrintingPolicy &Policy) { + if (Expr *IteratorModifier = Node->getIteratorModifier()) + IteratorModifier->printPretty(OS, nullptr, Policy); +} + void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) { if (!Node->varlist_empty()) { OS << "map("; if (Node->getMapType() != OMPC_MAP_unknown) { for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) { if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) { - OS << getOpenMPSimpleClauseTypeName(OMPC_map, - Node->getMapTypeModifier(I)); - if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) - PrintMapper(OS, Node, Policy); + if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_iterator) { + PrintIterator(OS, Node, Policy); + } else { + OS << getOpenMPSimpleClauseTypeName(OMPC_map, + Node->getMapTypeModifier(I)); + if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) + PrintMapper(OS, Node, Policy); + } OS << ','; } } @@ -2226,6 +2435,14 @@ void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) { } } +void OMPClausePrinter::VisitOMPHasDeviceAddrClause(OMPHasDeviceAddrClause *Node) { + if (!Node->varlist_empty()) { + OS << "has_device_addr"; + VisitOMPClauseList(Node, '('); + OS << ")"; + } +} + void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) { if (!Node->varlist_empty()) { OS << "nontemporal"; @@ -2235,8 +2452,12 @@ void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) { } void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) { - OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind()) - << ")"; + OS << "order("; + if (Node->getModifier() != OMPC_ORDER_MODIFIER_unknown) { + OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getModifier()); + OS << ": "; + } + OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind()) << ")"; } void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) { @@ -2295,6 +2516,59 @@ void OMPClausePrinter::VisitOMPFilterClause(OMPFilterClause *Node) { OS << ")"; } +void OMPClausePrinter::VisitOMPBindClause(OMPBindClause *Node) { + OS << "bind(" + << getOpenMPSimpleClauseTypeName(OMPC_bind, unsigned(Node->getBindKind())) + << ")"; +} + +void OMPClausePrinter::VisitOMPXDynCGroupMemClause( + OMPXDynCGroupMemClause *Node) { + OS << "ompx_dyn_cgroup_mem("; + Node->getSize()->printPretty(OS, nullptr, Policy, 0); + OS << ")"; +} + +void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause *Node) { + OS << "doacross("; + OpenMPDoacrossClauseModifier DepType = Node->getDependenceType(); + + switch (DepType) { + case OMPC_DOACROSS_source: + OS << "source:"; + break; + case OMPC_DOACROSS_sink: + OS << "sink:"; + break; + case OMPC_DOACROSS_source_omp_cur_iteration: + OS << "source: omp_cur_iteration"; + break; + case OMPC_DOACROSS_sink_omp_cur_iteration: + OS << "sink: omp_cur_iteration - 1"; + break; + default: + llvm_unreachable("unknown docaross modifier"); + } + VisitOMPClauseList(Node, ' '); + OS << ")"; +} + +void OMPClausePrinter::VisitOMPXAttributeClause(OMPXAttributeClause *Node) { + OS << "ompx_attribute("; + bool IsFirst = true; + for (auto &Attr : Node->getAttrs()) { + if (!IsFirst) + OS << ", "; + Attr->printPretty(OS, Policy); + IsFirst = false; + } + OS << ")"; +} + +void OMPClausePrinter::VisitOMPXBareClause(OMPXBareClause *Node) { + OS << "ompx_bare"; +} + void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx, VariantMatchInfo &VMI) const { for (const OMPTraitSet &Set : Sets) { @@ -2309,18 +2583,17 @@ void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx, TraitProperty::user_condition_unknown && "Ill-formed user condition, expected unknown trait property!"); - if (Optional<APSInt> CondVal = + if (std::optional<APSInt> CondVal = Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)) - VMI.addTrait(CondVal->isNullValue() - ? TraitProperty::user_condition_false - : TraitProperty::user_condition_true, + VMI.addTrait(CondVal->isZero() ? TraitProperty::user_condition_false + : TraitProperty::user_condition_true, "<condition>"); else VMI.addTrait(TraitProperty::user_condition_false, "<condition>"); continue; } - Optional<llvm::APSInt> Score; + std::optional<llvm::APSInt> Score; llvm::APInt *ScorePtr = nullptr; if (Selector.ScoreOrCondition) { if ((Score = Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))) @@ -2342,8 +2615,6 @@ void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx, getOpenMPContextTraitPropertyForSelector( Selector.Kind) && "Ill-formed construct selector!"); - - VMI.ConstructTraits.push_back(Selector.Properties.front().Kind); } } } @@ -2424,7 +2695,7 @@ std::string OMPTraitInfo::getMangledName() const { Property.RawString); } } - return OS.str(); + return MangledName; } OMPTraitInfo::OMPTraitInfo(StringRef MangledName) { @@ -2474,14 +2745,18 @@ llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, TargetOMPContext::TargetOMPContext( ASTContext &ASTCtx, std::function<void(StringRef)> &&DiagUnknownTrait, - const FunctionDecl *CurrentFunctionDecl) - : OMPContext(ASTCtx.getLangOpts().OpenMPIsDevice, + const FunctionDecl *CurrentFunctionDecl, + ArrayRef<llvm::omp::TraitProperty> ConstructTraits) + : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice, ASTCtx.getTargetInfo().getTriple()), FeatureValidityCheck([&](StringRef FeatureName) { return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName); }), DiagUnknownTrait(std::move(DiagUnknownTrait)) { ASTCtx.getFunctionFeatureMap(FeatureMap, CurrentFunctionDecl); + + for (llvm::omp::TraitProperty Property : ConstructTraits) + addTrait(Property); } bool TargetOMPContext::matchesISATrait(StringRef RawString) const { |