123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664 |
- //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- //
- // This file implements the subclesses of Stmt class declared in OpenMPClause.h
- //
- //===----------------------------------------------------------------------===//
- #include "clang/AST/OpenMPClause.h"
- #include "clang/AST/ASTContext.h"
- #include "clang/AST/Attr.h"
- #include "clang/AST/Decl.h"
- #include "clang/AST/DeclOpenMP.h"
- #include "clang/Basic/LLVM.h"
- #include "clang/Basic/OpenMPKinds.h"
- #include "clang/Basic/TargetInfo.h"
- #include "llvm/ADT/SmallPtrSet.h"
- #include "llvm/Support/Casting.h"
- #include "llvm/Support/ErrorHandling.h"
- #include <algorithm>
- #include <cassert>
- #include <optional>
- using namespace clang;
- using namespace llvm;
- using namespace omp;
- OMPClause::child_range OMPClause::children() {
- switch (getClauseKind()) {
- default:
- break;
- #define GEN_CLANG_CLAUSE_CLASS
- #define CLAUSE_CLASS(Enum, Str, Class) \
- case Enum: \
- return static_cast<Class *>(this)->children();
- #include "llvm/Frontend/OpenMP/OMP.inc"
- }
- llvm_unreachable("unknown OMPClause");
- }
- OMPClause::child_range OMPClause::used_children() {
- switch (getClauseKind()) {
- #define GEN_CLANG_CLAUSE_CLASS
- #define CLAUSE_CLASS(Enum, Str, Class) \
- case Enum: \
- return static_cast<Class *>(this)->used_children();
- #define CLAUSE_NO_CLASS(Enum, Str) \
- case Enum: \
- break;
- #include "llvm/Frontend/OpenMP/OMP.inc"
- }
- llvm_unreachable("unknown OMPClause");
- }
- OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
- auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
- return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
- }
- const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
- switch (C->getClauseKind()) {
- case OMPC_schedule:
- return static_cast<const OMPScheduleClause *>(C);
- case OMPC_dist_schedule:
- return static_cast<const OMPDistScheduleClause *>(C);
- case OMPC_firstprivate:
- return static_cast<const OMPFirstprivateClause *>(C);
- case OMPC_lastprivate:
- return static_cast<const OMPLastprivateClause *>(C);
- case OMPC_reduction:
- return static_cast<const OMPReductionClause *>(C);
- case OMPC_task_reduction:
- return static_cast<const OMPTaskReductionClause *>(C);
- case OMPC_in_reduction:
- return static_cast<const OMPInReductionClause *>(C);
- case OMPC_linear:
- return static_cast<const OMPLinearClause *>(C);
- case OMPC_if:
- return static_cast<const OMPIfClause *>(C);
- case OMPC_num_threads:
- return static_cast<const OMPNumThreadsClause *>(C);
- case OMPC_num_teams:
- return static_cast<const OMPNumTeamsClause *>(C);
- case OMPC_thread_limit:
- return static_cast<const OMPThreadLimitClause *>(C);
- case OMPC_device:
- return static_cast<const OMPDeviceClause *>(C);
- case OMPC_grainsize:
- return static_cast<const OMPGrainsizeClause *>(C);
- case OMPC_num_tasks:
- return static_cast<const OMPNumTasksClause *>(C);
- case OMPC_final:
- return static_cast<const OMPFinalClause *>(C);
- case OMPC_priority:
- return static_cast<const OMPPriorityClause *>(C);
- case OMPC_novariants:
- return static_cast<const OMPNovariantsClause *>(C);
- case OMPC_nocontext:
- 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:
- case OMPC_simdlen:
- case OMPC_sizes:
- case OMPC_allocator:
- case OMPC_allocate:
- case OMPC_collapse:
- case OMPC_private:
- case OMPC_shared:
- case OMPC_aligned:
- case OMPC_copyin:
- case OMPC_copyprivate:
- case OMPC_ordered:
- case OMPC_nowait:
- case OMPC_untied:
- case OMPC_mergeable:
- case OMPC_threadprivate:
- case OMPC_flush:
- case OMPC_depobj:
- case OMPC_read:
- case OMPC_write:
- case OMPC_update:
- case OMPC_capture:
- case OMPC_compare:
- case OMPC_seq_cst:
- case OMPC_acq_rel:
- case OMPC_acquire:
- case OMPC_release:
- case OMPC_relaxed:
- case OMPC_depend:
- case OMPC_threads:
- case OMPC_simd:
- case OMPC_map:
- case OMPC_nogroup:
- case OMPC_hint:
- case OMPC_defaultmap:
- case OMPC_unknown:
- case OMPC_uniform:
- case OMPC_to:
- case OMPC_from:
- 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:
- case OMPC_order:
- case OMPC_destroy:
- case OMPC_detach:
- case OMPC_inclusive:
- case OMPC_exclusive:
- case OMPC_uses_allocators:
- case OMPC_affinity:
- case OMPC_when:
- case OMPC_bind:
- break;
- default:
- break;
- }
- return nullptr;
- }
- OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
- auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
- return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
- }
- const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
- switch (C->getClauseKind()) {
- case OMPC_lastprivate:
- return static_cast<const OMPLastprivateClause *>(C);
- case OMPC_reduction:
- return static_cast<const OMPReductionClause *>(C);
- case OMPC_task_reduction:
- return static_cast<const OMPTaskReductionClause *>(C);
- case OMPC_in_reduction:
- return static_cast<const OMPInReductionClause *>(C);
- case OMPC_linear:
- return static_cast<const OMPLinearClause *>(C);
- case OMPC_schedule:
- case OMPC_dist_schedule:
- case OMPC_firstprivate:
- case OMPC_default:
- case OMPC_proc_bind:
- case OMPC_if:
- case OMPC_final:
- case OMPC_num_threads:
- case OMPC_safelen:
- case OMPC_simdlen:
- case OMPC_sizes:
- case OMPC_allocator:
- case OMPC_allocate:
- case OMPC_collapse:
- case OMPC_private:
- case OMPC_shared:
- case OMPC_aligned:
- case OMPC_copyin:
- case OMPC_copyprivate:
- case OMPC_ordered:
- case OMPC_nowait:
- case OMPC_untied:
- case OMPC_mergeable:
- case OMPC_threadprivate:
- case OMPC_flush:
- case OMPC_depobj:
- case OMPC_read:
- case OMPC_write:
- case OMPC_update:
- case OMPC_capture:
- case OMPC_compare:
- case OMPC_seq_cst:
- case OMPC_acq_rel:
- case OMPC_acquire:
- case OMPC_release:
- case OMPC_relaxed:
- case OMPC_depend:
- case OMPC_device:
- case OMPC_threads:
- case OMPC_simd:
- case OMPC_map:
- case OMPC_num_teams:
- case OMPC_thread_limit:
- case OMPC_priority:
- case OMPC_grainsize:
- case OMPC_nogroup:
- case OMPC_num_tasks:
- case OMPC_hint:
- case OMPC_defaultmap:
- case OMPC_unknown:
- case OMPC_uniform:
- case OMPC_to:
- case OMPC_from:
- 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:
- case OMPC_order:
- case OMPC_destroy:
- case OMPC_novariants:
- case OMPC_nocontext:
- case OMPC_detach:
- case OMPC_inclusive:
- case OMPC_exclusive:
- case OMPC_uses_allocators:
- case OMPC_affinity:
- case OMPC_when:
- case OMPC_bind:
- break;
- default:
- break;
- }
- return nullptr;
- }
- /// Gets the address of the original, non-captured, expression used in the
- /// clause as the preinitializer.
- static Stmt **getAddrOfExprAsWritten(Stmt *S) {
- if (!S)
- return nullptr;
- if (auto *DS = dyn_cast<DeclStmt>(S)) {
- assert(DS->isSingleDecl() && "Only single expression must be captured.");
- if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
- return OED->getInitAddress();
- }
- return nullptr;
- }
- OMPClause::child_range OMPIfClause::used_children() {
- if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
- return child_range(C, C + 1);
- return child_range(&Condition, &Condition + 1);
- }
- OMPClause::child_range OMPGrainsizeClause::used_children() {
- if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
- return child_range(C, C + 1);
- return child_range(&Grainsize, &Grainsize + 1);
- }
- OMPClause::child_range OMPNumTasksClause::used_children() {
- if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
- return child_range(C, C + 1);
- return child_range(&NumTasks, &NumTasks + 1);
- }
- OMPClause::child_range OMPFinalClause::used_children() {
- if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
- return child_range(C, C + 1);
- return children();
- }
- OMPClause::child_range OMPPriorityClause::used_children() {
- if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
- return child_range(C, C + 1);
- return child_range(&Priority, &Priority + 1);
- }
- OMPClause::child_range OMPNovariantsClause::used_children() {
- if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
- return child_range(C, C + 1);
- return children();
- }
- OMPClause::child_range OMPNocontextClause::used_children() {
- if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
- return child_range(C, C + 1);
- return children();
- }
- OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
- unsigned NumLoops,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
- auto *Clause =
- new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
- for (unsigned I = 0; I < NumLoops; ++I) {
- Clause->setLoopNumIterations(I, nullptr);
- Clause->setLoopCounter(I, nullptr);
- }
- return Clause;
- }
- OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
- unsigned NumLoops) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
- auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
- for (unsigned I = 0; I < NumLoops; ++I) {
- Clause->setLoopNumIterations(I, nullptr);
- Clause->setLoopCounter(I, nullptr);
- }
- return Clause;
- }
- void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
- Expr *NumIterations) {
- assert(NumLoop < NumberOfLoops && "out of loops number.");
- getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
- }
- ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
- return llvm::ArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
- }
- void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
- assert(NumLoop < NumberOfLoops && "out of loops number.");
- getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
- }
- Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
- assert(NumLoop < NumberOfLoops && "out of loops number.");
- return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
- }
- const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
- assert(NumLoop < NumberOfLoops && "out of loops number.");
- return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
- }
- OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation EndLoc) {
- return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false);
- }
- OMPUpdateClause *
- OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation ArgumentLoc,
- OpenMPDependClauseKind DK, SourceLocation EndLoc) {
- void *Mem =
- C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
- alignof(OMPUpdateClause));
- auto *Clause =
- new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true);
- Clause->setLParenLoc(LParenLoc);
- Clause->setArgumentLoc(ArgumentLoc);
- Clause->setDependencyKind(DK);
- return Clause;
- }
- OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C,
- bool IsExtended) {
- if (!IsExtended)
- return new (C) OMPUpdateClause(/*IsExtended=*/false);
- void *Mem =
- C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
- alignof(OMPUpdateClause));
- auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true);
- Clause->IsExtended = true;
- return Clause;
- }
- void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
- assert(VL.size() == varlist_size() &&
- "Number of private copies is not the same as the preallocated buffer");
- std::copy(VL.begin(), VL.end(), varlist_end());
- }
- OMPPrivateClause *
- OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation EndLoc,
- ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
- // Allocate space for private variables and initializer expressions.
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
- OMPPrivateClause *Clause =
- new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- Clause->setPrivateCopies(PrivateVL);
- return Clause;
- }
- OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
- return new (Mem) OMPPrivateClause(N);
- }
- void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
- assert(VL.size() == varlist_size() &&
- "Number of private copies is not the same as the preallocated buffer");
- std::copy(VL.begin(), VL.end(), varlist_end());
- }
- void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
- assert(VL.size() == varlist_size() &&
- "Number of inits is not the same as the preallocated buffer");
- std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
- }
- OMPFirstprivateClause *
- OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation EndLoc,
- ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
- ArrayRef<Expr *> InitVL, Stmt *PreInit) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
- OMPFirstprivateClause *Clause =
- new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- Clause->setPrivateCopies(PrivateVL);
- Clause->setInits(InitVL);
- Clause->setPreInitStmt(PreInit);
- return Clause;
- }
- OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
- return new (Mem) OMPFirstprivateClause(N);
- }
- void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
- assert(PrivateCopies.size() == varlist_size() &&
- "Number of private copies is not the same as the preallocated buffer");
- std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
- }
- void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
- assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
- "not the same as the "
- "preallocated buffer");
- std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
- }
- void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
- assert(DstExprs.size() == varlist_size() && "Number of destination "
- "expressions is not the same as "
- "the preallocated buffer");
- std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
- }
- void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
- assert(AssignmentOps.size() == varlist_size() &&
- "Number of assignment expressions is not the same as the preallocated "
- "buffer");
- std::copy(AssignmentOps.begin(), AssignmentOps.end(),
- getDestinationExprs().end());
- }
- OMPLastprivateClause *OMPLastprivateClause::Create(
- const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
- ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
- OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
- SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
- OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
- StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
- Clause->setVarRefs(VL);
- Clause->setSourceExprs(SrcExprs);
- Clause->setDestinationExprs(DstExprs);
- Clause->setAssignmentOps(AssignmentOps);
- Clause->setPreInitStmt(PreInit);
- Clause->setPostUpdateExpr(PostUpdate);
- return Clause;
- }
- OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
- return new (Mem) OMPLastprivateClause(N);
- }
- OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc,
- ArrayRef<Expr *> VL) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
- OMPSharedClause *Clause =
- new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- return Clause;
- }
- OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
- return new (Mem) OMPSharedClause(N);
- }
- void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
- assert(PL.size() == varlist_size() &&
- "Number of privates is not the same as the preallocated buffer");
- std::copy(PL.begin(), PL.end(), varlist_end());
- }
- void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
- assert(IL.size() == varlist_size() &&
- "Number of inits is not the same as the preallocated buffer");
- std::copy(IL.begin(), IL.end(), getPrivates().end());
- }
- void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
- assert(UL.size() == varlist_size() &&
- "Number of updates is not the same as the preallocated buffer");
- std::copy(UL.begin(), UL.end(), getInits().end());
- }
- void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
- assert(FL.size() == varlist_size() &&
- "Number of final updates is not the same as the preallocated buffer");
- std::copy(FL.begin(), FL.end(), getUpdates().end());
- }
- void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
- assert(
- UE.size() == varlist_size() + 1 &&
- "Number of used expressions is not the same as the preallocated buffer");
- std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
- }
- 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) {
- // 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());
- Clause->setVarRefs(VL);
- Clause->setPrivates(PL);
- Clause->setInits(IL);
- // Fill update and final expressions with zeroes, they are provided later,
- // after the directive construction.
- std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
- nullptr);
- std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
- nullptr);
- std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
- nullptr);
- Clause->setStep(Step);
- Clause->setCalcStep(CalcStep);
- Clause->setPreInitStmt(PreInit);
- Clause->setPostUpdateExpr(PostUpdate);
- return Clause;
- }
- OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
- unsigned NumVars) {
- // 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 * NumVars + 2 + NumVars +1));
- return new (Mem) OMPLinearClause(NumVars);
- }
- OMPClause::child_range OMPLinearClause::used_children() {
- // Range includes only non-nullptr elements.
- return child_range(
- reinterpret_cast<Stmt **>(getUsedExprs().begin()),
- reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
- }
- OMPAlignedClause *
- OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation ColonLoc,
- SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
- OMPAlignedClause *Clause = new (Mem)
- OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- Clause->setAlignment(A);
- return Clause;
- }
- OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
- unsigned NumVars) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
- 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 "
- "preallocated buffer");
- std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
- }
- void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
- assert(DstExprs.size() == varlist_size() && "Number of destination "
- "expressions is not the same as "
- "the preallocated buffer");
- std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
- }
- void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
- assert(AssignmentOps.size() == varlist_size() &&
- "Number of assignment expressions is not the same as the preallocated "
- "buffer");
- std::copy(AssignmentOps.begin(), AssignmentOps.end(),
- getDestinationExprs().end());
- }
- OMPCopyinClause *OMPCopyinClause::Create(
- const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
- ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
- OMPCopyinClause *Clause =
- new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- Clause->setSourceExprs(SrcExprs);
- Clause->setDestinationExprs(DstExprs);
- Clause->setAssignmentOps(AssignmentOps);
- return Clause;
- }
- OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
- return new (Mem) OMPCopyinClause(N);
- }
- void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
- assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
- "not the same as the "
- "preallocated buffer");
- std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
- }
- void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
- assert(DstExprs.size() == varlist_size() && "Number of destination "
- "expressions is not the same as "
- "the preallocated buffer");
- std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
- }
- void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
- assert(AssignmentOps.size() == varlist_size() &&
- "Number of assignment expressions is not the same as the preallocated "
- "buffer");
- std::copy(AssignmentOps.begin(), AssignmentOps.end(),
- getDestinationExprs().end());
- }
- OMPCopyprivateClause *OMPCopyprivateClause::Create(
- const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
- ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
- OMPCopyprivateClause *Clause =
- new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- Clause->setSourceExprs(SrcExprs);
- Clause->setDestinationExprs(DstExprs);
- Clause->setAssignmentOps(AssignmentOps);
- return Clause;
- }
- OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
- return new (Mem) OMPCopyprivateClause(N);
- }
- void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
- assert(Privates.size() == varlist_size() &&
- "Number of private copies is not the same as the preallocated buffer");
- std::copy(Privates.begin(), Privates.end(), varlist_end());
- }
- void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
- assert(
- LHSExprs.size() == varlist_size() &&
- "Number of LHS expressions is not the same as the preallocated buffer");
- std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
- }
- void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
- assert(
- RHSExprs.size() == varlist_size() &&
- "Number of RHS expressions is not the same as the preallocated buffer");
- std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
- }
- void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
- assert(ReductionOps.size() == varlist_size() && "Number of reduction "
- "expressions is not the same "
- "as the preallocated buffer");
- std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
- }
- void OMPReductionClause::setInscanCopyOps(ArrayRef<Expr *> Ops) {
- assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
- assert(Ops.size() == varlist_size() && "Number of copy "
- "expressions is not the same "
- "as the preallocated buffer");
- llvm::copy(Ops, getReductionOps().end());
- }
- void OMPReductionClause::setInscanCopyArrayTemps(
- ArrayRef<Expr *> CopyArrayTemps) {
- assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
- assert(CopyArrayTemps.size() == varlist_size() &&
- "Number of copy temp expressions is not the same as the preallocated "
- "buffer");
- llvm::copy(CopyArrayTemps, getInscanCopyOps().end());
- }
- void OMPReductionClause::setInscanCopyArrayElems(
- ArrayRef<Expr *> CopyArrayElems) {
- assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
- assert(CopyArrayElems.size() == varlist_size() &&
- "Number of copy temp expressions is not the same as the preallocated "
- "buffer");
- llvm::copy(CopyArrayElems, getInscanCopyArrayTemps().end());
- }
- OMPReductionClause *OMPReductionClause::Create(
- const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc,
- OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL,
- NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
- ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
- ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
- ArrayRef<Expr *> CopyOps, ArrayRef<Expr *> CopyArrayTemps,
- ArrayRef<Expr *> CopyArrayElems, Stmt *PreInit, Expr *PostUpdate) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
- (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size()));
- auto *Clause = new (Mem)
- OMPReductionClause(StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc,
- Modifier, VL.size(), QualifierLoc, NameInfo);
- Clause->setVarRefs(VL);
- Clause->setPrivates(Privates);
- Clause->setLHSExprs(LHSExprs);
- Clause->setRHSExprs(RHSExprs);
- Clause->setReductionOps(ReductionOps);
- Clause->setPreInitStmt(PreInit);
- Clause->setPostUpdateExpr(PostUpdate);
- if (Modifier == OMPC_REDUCTION_inscan) {
- Clause->setInscanCopyOps(CopyOps);
- Clause->setInscanCopyArrayTemps(CopyArrayTemps);
- Clause->setInscanCopyArrayElems(CopyArrayElems);
- } else {
- assert(CopyOps.empty() &&
- "copy operations are expected in inscan reductions only.");
- assert(CopyArrayTemps.empty() &&
- "copy array temps are expected in inscan reductions only.");
- assert(CopyArrayElems.empty() &&
- "copy array temps are expected in inscan reductions only.");
- }
- return Clause;
- }
- OMPReductionClause *
- OMPReductionClause::CreateEmpty(const ASTContext &C, unsigned N,
- OpenMPReductionClauseModifier Modifier) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
- (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N));
- auto *Clause = new (Mem) OMPReductionClause(N);
- Clause->setModifier(Modifier);
- return Clause;
- }
- void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
- assert(Privates.size() == varlist_size() &&
- "Number of private copies is not the same as the preallocated buffer");
- std::copy(Privates.begin(), Privates.end(), varlist_end());
- }
- void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
- assert(
- LHSExprs.size() == varlist_size() &&
- "Number of LHS expressions is not the same as the preallocated buffer");
- std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
- }
- void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
- assert(
- RHSExprs.size() == varlist_size() &&
- "Number of RHS expressions is not the same as the preallocated buffer");
- std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
- }
- void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
- assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
- "expressions is not the same "
- "as the preallocated buffer");
- std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
- }
- OMPTaskReductionClause *OMPTaskReductionClause::Create(
- const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
- NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
- ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
- ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
- Expr *PostUpdate) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
- OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
- StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
- Clause->setVarRefs(VL);
- Clause->setPrivates(Privates);
- Clause->setLHSExprs(LHSExprs);
- Clause->setRHSExprs(RHSExprs);
- Clause->setReductionOps(ReductionOps);
- Clause->setPreInitStmt(PreInit);
- Clause->setPostUpdateExpr(PostUpdate);
- return Clause;
- }
- OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
- return new (Mem) OMPTaskReductionClause(N);
- }
- void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
- assert(Privates.size() == varlist_size() &&
- "Number of private copies is not the same as the preallocated buffer");
- std::copy(Privates.begin(), Privates.end(), varlist_end());
- }
- void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
- assert(
- LHSExprs.size() == varlist_size() &&
- "Number of LHS expressions is not the same as the preallocated buffer");
- std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
- }
- void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
- assert(
- RHSExprs.size() == varlist_size() &&
- "Number of RHS expressions is not the same as the preallocated buffer");
- std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
- }
- void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
- assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
- "expressions is not the same "
- "as the preallocated buffer");
- std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
- }
- void OMPInReductionClause::setTaskgroupDescriptors(
- ArrayRef<Expr *> TaskgroupDescriptors) {
- assert(TaskgroupDescriptors.size() == varlist_size() &&
- "Number of in reduction descriptors is not the same as the "
- "preallocated buffer");
- std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
- getReductionOps().end());
- }
- OMPInReductionClause *OMPInReductionClause::Create(
- const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
- NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
- ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
- ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
- ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
- OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
- StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
- Clause->setVarRefs(VL);
- Clause->setPrivates(Privates);
- Clause->setLHSExprs(LHSExprs);
- Clause->setRHSExprs(RHSExprs);
- Clause->setReductionOps(ReductionOps);
- Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
- Clause->setPreInitStmt(PreInit);
- Clause->setPostUpdateExpr(PostUpdate);
- return Clause;
- }
- OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
- return new (Mem) OMPInReductionClause(N);
- }
- OMPSizesClause *OMPSizesClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc,
- ArrayRef<Expr *> Sizes) {
- OMPSizesClause *Clause = CreateEmpty(C, Sizes.size());
- Clause->setLocStart(StartLoc);
- Clause->setLParenLoc(LParenLoc);
- Clause->setLocEnd(EndLoc);
- Clause->setSizesRefs(Sizes);
- return Clause;
- }
- OMPSizesClause *OMPSizesClause::CreateEmpty(const ASTContext &C,
- unsigned NumSizes) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumSizes));
- return new (Mem) OMPSizesClause(NumSizes);
- }
- OMPFullClause *OMPFullClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation EndLoc) {
- OMPFullClause *Clause = CreateEmpty(C);
- Clause->setLocStart(StartLoc);
- Clause->setLocEnd(EndLoc);
- return Clause;
- }
- OMPFullClause *OMPFullClause::CreateEmpty(const ASTContext &C) {
- return new (C) OMPFullClause();
- }
- OMPPartialClause *OMPPartialClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc,
- Expr *Factor) {
- OMPPartialClause *Clause = CreateEmpty(C);
- Clause->setLocStart(StartLoc);
- Clause->setLParenLoc(LParenLoc);
- Clause->setLocEnd(EndLoc);
- Clause->setFactor(Factor);
- return Clause;
- }
- OMPPartialClause *OMPPartialClause::CreateEmpty(const ASTContext &C) {
- return new (C) OMPPartialClause();
- }
- OMPAllocateClause *
- OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, Expr *Allocator,
- SourceLocation ColonLoc, SourceLocation EndLoc,
- ArrayRef<Expr *> VL) {
- // Allocate space for private variables and initializer expressions.
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
- auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
- ColonLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- return Clause;
- }
- OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
- return new (Mem) OMPAllocateClause(N);
- }
- OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc,
- ArrayRef<Expr *> VL) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
- OMPFlushClause *Clause =
- new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- return Clause;
- }
- OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
- return new (Mem) OMPFlushClause(N);
- }
- OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation RParenLoc,
- Expr *Depobj) {
- auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
- Clause->setDepobj(Depobj);
- return Clause;
- }
- OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
- return new (C) OMPDepobjClause();
- }
- OMPDependClause *
- OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation EndLoc,
- 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->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;
- }
- OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
- unsigned NumLoops) {
- void *Mem =
- C.Allocate(totalSizeToAlloc<Expr *>(N + /*depend-modifier*/ 1 + NumLoops),
- alignof(OMPDependClause));
- return new (Mem) OMPDependClause(N, NumLoops);
- }
- void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
- assert((getDependencyKind() == OMPC_DEPEND_sink ||
- getDependencyKind() == OMPC_DEPEND_source) &&
- NumLoop < NumLoops &&
- "Expected sink or source depend + loop index must be less number of "
- "loops.");
- auto *It = std::next(getVarRefs().end(), NumLoop + 1);
- *It = Cnt;
- }
- Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
- assert((getDependencyKind() == OMPC_DEPEND_sink ||
- getDependencyKind() == OMPC_DEPEND_source) &&
- NumLoop < NumLoops &&
- "Expected sink or source depend + loop index must be less number of "
- "loops.");
- auto *It = std::next(getVarRefs().end(), NumLoop + 1);
- return *It;
- }
- const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
- assert((getDependencyKind() == OMPC_DEPEND_sink ||
- getDependencyKind() == OMPC_DEPEND_source) &&
- NumLoop < NumLoops &&
- "Expected sink or source depend + loop index must be less number of "
- "loops.");
- const auto *It = std::next(getVarRefs().end(), NumLoop + 1);
- return *It;
- }
- void OMPDependClause::setModifier(Expr *DepModifier) {
- *getVarRefs().end() = DepModifier;
- }
- Expr *OMPDependClause::getModifier() { return *getVarRefs().end(); }
- unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
- MappableExprComponentListsRef ComponentLists) {
- unsigned TotalNum = 0u;
- for (auto &C : ComponentLists)
- TotalNum += C.size();
- return TotalNum;
- }
- unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
- ArrayRef<const ValueDecl *> Declarations) {
- unsigned TotalNum = 0u;
- llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
- for (const ValueDecl *D : Declarations) {
- const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
- if (Cache.count(VD))
- continue;
- ++TotalNum;
- Cache.insert(VD);
- }
- return TotalNum;
- }
- OMPMapClause *OMPMapClause::Create(
- const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
- ArrayRef<ValueDecl *> Declarations,
- MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
- Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapModifiers,
- ArrayRef<SourceLocation> MapModifiersLoc,
- NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
- OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
- OMPMappableExprListSizeTy Sizes;
- Sizes.NumVars = Vars.size();
- Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
- Sizes.NumComponentLists = ComponentLists.size();
- Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
- // We need to allocate:
- // 2 x NumVars x Expr* - we have an original list expression and an associated
- // user-defined mapper 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>(
- 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- OMPMapClause *Clause = new (Mem)
- OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
- Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
- Clause->setVarRefs(Vars);
- Clause->setUDMapperRefs(UDMapperRefs);
- Clause->setIteratorModifier(IteratorModifier);
- Clause->setClauseInfo(Declarations, ComponentLists);
- Clause->setMapType(Type);
- Clause->setMapLoc(TypeLoc);
- return Clause;
- }
- OMPMapClause *
- OMPMapClause::CreateEmpty(const ASTContext &C,
- const OMPMappableExprListSizeTy &Sizes) {
- void *Mem = C.Allocate(
- totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
- OMPClauseMappableExprCommon::MappableComponent>(
- 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- OMPMapClause *Clause = new (Mem) OMPMapClause(Sizes);
- Clause->setIteratorModifier(nullptr);
- return Clause;
- }
- OMPToClause *OMPToClause::Create(
- const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
- ArrayRef<ValueDecl *> Declarations,
- MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
- ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
- ArrayRef<SourceLocation> MotionModifiersLoc,
- NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
- OMPMappableExprListSizeTy Sizes;
- Sizes.NumVars = Vars.size();
- Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
- Sizes.NumComponentLists = ComponentLists.size();
- Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
- // We need to allocate:
- // 2 x NumVars x Expr* - we have an original list expression and an associated
- // user-defined mapper 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>(
- 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- auto *Clause = new (Mem) OMPToClause(MotionModifiers, MotionModifiersLoc,
- UDMQualifierLoc, MapperId, Locs, Sizes);
- Clause->setVarRefs(Vars);
- Clause->setUDMapperRefs(UDMapperRefs);
- Clause->setClauseInfo(Declarations, ComponentLists);
- return Clause;
- }
- OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
- const OMPMappableExprListSizeTy &Sizes) {
- void *Mem = C.Allocate(
- totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
- OMPClauseMappableExprCommon::MappableComponent>(
- 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- return new (Mem) OMPToClause(Sizes);
- }
- OMPFromClause *OMPFromClause::Create(
- const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
- ArrayRef<ValueDecl *> Declarations,
- MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
- ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
- ArrayRef<SourceLocation> MotionModifiersLoc,
- NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
- OMPMappableExprListSizeTy Sizes;
- Sizes.NumVars = Vars.size();
- Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
- Sizes.NumComponentLists = ComponentLists.size();
- Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
- // We need to allocate:
- // 2 x NumVars x Expr* - we have an original list expression and an associated
- // user-defined mapper 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>(
- 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- auto *Clause =
- new (Mem) OMPFromClause(MotionModifiers, MotionModifiersLoc,
- UDMQualifierLoc, MapperId, Locs, Sizes);
- Clause->setVarRefs(Vars);
- Clause->setUDMapperRefs(UDMapperRefs);
- Clause->setClauseInfo(Declarations, ComponentLists);
- return Clause;
- }
- OMPFromClause *
- OMPFromClause::CreateEmpty(const ASTContext &C,
- const OMPMappableExprListSizeTy &Sizes) {
- void *Mem = C.Allocate(
- totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
- OMPClauseMappableExprCommon::MappableComponent>(
- 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- return new (Mem) OMPFromClause(Sizes);
- }
- void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
- assert(VL.size() == varlist_size() &&
- "Number of private copies is not the same as the preallocated buffer");
- std::copy(VL.begin(), VL.end(), varlist_end());
- }
- void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
- assert(VL.size() == varlist_size() &&
- "Number of inits is not the same as the preallocated buffer");
- std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
- }
- OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
- const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
- ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
- 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>(
- 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
- Clause->setVarRefs(Vars);
- Clause->setPrivateCopies(PrivateVars);
- Clause->setInits(Inits);
- Clause->setClauseInfo(Declarations, ComponentLists);
- return Clause;
- }
- OMPUseDevicePtrClause *
- OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
- const OMPMappableExprListSizeTy &Sizes) {
- void *Mem = C.Allocate(
- totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
- OMPClauseMappableExprCommon::MappableComponent>(
- 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
- Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
- Sizes.NumComponents));
- return new (Mem) OMPUseDevicePtrClause(Sizes);
- }
- OMPUseDeviceAddrClause *
- OMPUseDeviceAddrClause::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:
- // 3 x NumVars x Expr* - we have an original list expression for each clause
- // list entry and an equal number of private copies and inits.
- // 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) OMPUseDeviceAddrClause(Locs, Sizes);
- Clause->setVarRefs(Vars);
- Clause->setClauseInfo(Declarations, ComponentLists);
- return Clause;
- }
- OMPUseDeviceAddrClause *
- OMPUseDeviceAddrClause::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) OMPUseDeviceAddrClause(Sizes);
- }
- OMPIsDevicePtrClause *
- OMPIsDevicePtrClause::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));
- OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
- Clause->setVarRefs(Vars);
- Clause->setClauseInfo(Declarations, ComponentLists);
- return Clause;
- }
- OMPIsDevicePtrClause *
- OMPIsDevicePtrClause::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) 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,
- SourceLocation EndLoc,
- ArrayRef<Expr *> VL) {
- // Allocate space for nontemporal variables + private references.
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
- auto *Clause =
- new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- return Clause;
- }
- OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
- return new (Mem) OMPNontemporalClause(N);
- }
- void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
- assert(VL.size() == varlist_size() && "Number of private references is not "
- "the same as the preallocated buffer");
- std::copy(VL.begin(), VL.end(), varlist_end());
- }
- OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc,
- ArrayRef<Expr *> VL) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
- auto *Clause =
- new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- return Clause;
- }
- OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
- return new (Mem) OMPInclusiveClause(N);
- }
- OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc,
- ArrayRef<Expr *> VL) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
- auto *Clause =
- new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
- Clause->setVarRefs(VL);
- return Clause;
- }
- OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
- return new (Mem) OMPExclusiveClause(N);
- }
- void OMPUsesAllocatorsClause::setAllocatorsData(
- ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
- assert(Data.size() == NumOfAllocators &&
- "Size of allocators data is not the same as the preallocated buffer.");
- for (unsigned I = 0, E = Data.size(); I < E; ++I) {
- const OMPUsesAllocatorsClause::Data &D = Data[I];
- getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
- static_cast<int>(ExprOffsets::Allocator)] =
- D.Allocator;
- getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
- static_cast<int>(
- ExprOffsets::AllocatorTraits)] =
- D.AllocatorTraits;
- getTrailingObjects<
- SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
- static_cast<int>(ParenLocsOffsets::LParen)] =
- D.LParenLoc;
- getTrailingObjects<
- SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
- static_cast<int>(ParenLocsOffsets::RParen)] =
- D.RParenLoc;
- }
- }
- OMPUsesAllocatorsClause::Data
- OMPUsesAllocatorsClause::getAllocatorData(unsigned I) const {
- OMPUsesAllocatorsClause::Data Data;
- Data.Allocator =
- getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
- static_cast<int>(ExprOffsets::Allocator)];
- Data.AllocatorTraits =
- getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
- static_cast<int>(
- ExprOffsets::AllocatorTraits)];
- Data.LParenLoc = getTrailingObjects<
- SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
- static_cast<int>(ParenLocsOffsets::LParen)];
- Data.RParenLoc = getTrailingObjects<
- SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
- static_cast<int>(ParenLocsOffsets::RParen)];
- return Data;
- }
- OMPUsesAllocatorsClause *
- OMPUsesAllocatorsClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation EndLoc,
- ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
- static_cast<int>(ExprOffsets::Total) * Data.size(),
- static_cast<int>(ParenLocsOffsets::Total) * Data.size()));
- auto *Clause = new (Mem)
- OMPUsesAllocatorsClause(StartLoc, LParenLoc, EndLoc, Data.size());
- Clause->setAllocatorsData(Data);
- return Clause;
- }
- OMPUsesAllocatorsClause *
- OMPUsesAllocatorsClause::CreateEmpty(const ASTContext &C, unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
- static_cast<int>(ExprOffsets::Total) * N,
- static_cast<int>(ParenLocsOffsets::Total) * N));
- return new (Mem) OMPUsesAllocatorsClause(N);
- }
- OMPAffinityClause *
- OMPAffinityClause::Create(const ASTContext &C, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation ColonLoc,
- SourceLocation EndLoc, Expr *Modifier,
- ArrayRef<Expr *> Locators) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Locators.size() + 1));
- auto *Clause = new (Mem)
- OMPAffinityClause(StartLoc, LParenLoc, ColonLoc, EndLoc, Locators.size());
- Clause->setModifier(Modifier);
- Clause->setVarRefs(Locators);
- return Clause;
- }
- OMPAffinityClause *OMPAffinityClause::CreateEmpty(const ASTContext &C,
- unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
- return new (Mem) OMPAffinityClause(N);
- }
- OMPInitClause *OMPInitClause::Create(const ASTContext &C, Expr *InteropVar,
- OMPInteropInfo &InteropInfo,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation VarLoc,
- SourceLocation EndLoc) {
- 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(InteropInfo.PreferTypes, Clause->getTrailingObjects<Expr *>() + 1);
- return Clause;
- }
- OMPInitClause *OMPInitClause::CreateEmpty(const ASTContext &C, unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(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();
- }
- //===----------------------------------------------------------------------===//
- // OpenMP clauses printing methods
- //===----------------------------------------------------------------------===//
- void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
- OS << "if(";
- if (Node->getNameModifier() != OMPD_unknown)
- OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
- Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
- OS << "final(";
- Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
- OS << "num_threads(";
- Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
- 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);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
- OS << "simdlen(";
- Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPSizesClause(OMPSizesClause *Node) {
- OS << "sizes(";
- bool First = true;
- for (auto *Size : Node->getSizesRefs()) {
- if (!First)
- OS << ", ";
- Size->printPretty(OS, nullptr, Policy, 0);
- First = false;
- }
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPFullClause(OMPFullClause *Node) { OS << "full"; }
- void OMPClausePrinter::VisitOMPPartialClause(OMPPartialClause *Node) {
- OS << "partial";
- if (Expr *Factor = Node->getFactor()) {
- OS << '(';
- Factor->printPretty(OS, nullptr, Policy, 0);
- OS << ')';
- }
- }
- void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
- OS << "allocator(";
- Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
- OS << "collapse(";
- Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
- OS << "detach(";
- Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
- OS << "default("
- << getOpenMPSimpleClauseTypeName(OMPC_default,
- unsigned(Node->getDefaultKind()))
- << ")";
- }
- void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
- OS << "proc_bind("
- << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
- unsigned(Node->getProcBindKind()))
- << ")";
- }
- void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
- OS << "unified_address";
- }
- void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
- OMPUnifiedSharedMemoryClause *) {
- OS << "unified_shared_memory";
- }
- void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
- OS << "reverse_offload";
- }
- void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
- OMPDynamicAllocatorsClause *) {
- OS << "dynamic_allocators";
- }
- void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
- OMPAtomicDefaultMemOrderClause *Node) {
- OS << "atomic_default_mem_order("
- << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
- Node->getAtomicDefaultMemOrderKind())
- << ")";
- }
- 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) {
- OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
- Node->getFirstScheduleModifier());
- if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
- OS << ", ";
- OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
- Node->getSecondScheduleModifier());
- }
- OS << ": ";
- }
- OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
- if (auto *E = Node->getChunkSize()) {
- OS << ", ";
- E->printPretty(OS, nullptr, Policy);
- }
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
- OS << "ordered";
- if (auto *Num = Node->getNumForLoops()) {
- OS << "(";
- Num->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
- OS << "nowait";
- }
- void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
- OS << "untied";
- }
- void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
- OS << "nogroup";
- }
- void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
- OS << "mergeable";
- }
- void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
- void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
- void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) {
- OS << "update";
- if (Node->isExtended()) {
- OS << "(";
- OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
- Node->getDependencyKind());
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
- OS << "capture";
- }
- void OMPClausePrinter::VisitOMPCompareClause(OMPCompareClause *) {
- OS << "compare";
- }
- void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
- OS << "seq_cst";
- }
- void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
- OS << "acq_rel";
- }
- void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
- OS << "acquire";
- }
- void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
- OS << "release";
- }
- void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
- OS << "relaxed";
- }
- void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
- OS << "threads";
- }
- void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
- void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
- OS << "device(";
- OpenMPDeviceClauseModifier Modifier = Node->getModifier();
- if (Modifier != OMPC_DEVICE_unknown) {
- OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
- << ": ";
- }
- Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
- OS << "num_teams(";
- Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
- OS << "thread_limit(";
- Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
- OS << "priority(";
- Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- 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 << ")";
- }
- void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
- OS << "hint(";
- Node->getHint()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPInitClause(OMPInitClause *Node) {
- OS << "init(";
- bool First = true;
- for (const Expr *E : Node->prefs()) {
- if (First)
- OS << "prefer_type(";
- else
- OS << ",";
- E->printPretty(OS, nullptr, Policy);
- First = false;
- }
- if (!First)
- OS << "), ";
- if (Node->getIsTarget())
- OS << "target";
- if (Node->getIsTargetSync()) {
- if (Node->getIsTarget())
- OS << ", ";
- OS << "targetsync";
- }
- OS << " : ";
- Node->getInteropVar()->printPretty(OS, nullptr, Policy);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPUseClause(OMPUseClause *Node) {
- OS << "use(";
- Node->getInteropVar()->printPretty(OS, nullptr, Policy);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *Node) {
- OS << "destroy";
- if (Expr *E = Node->getInteropVar()) {
- OS << "(";
- E->printPretty(OS, nullptr, Policy);
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPNovariantsClause(OMPNovariantsClause *Node) {
- OS << "novariants";
- if (Expr *E = Node->getCondition()) {
- OS << "(";
- E->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPNocontextClause(OMPNocontextClause *Node) {
- OS << "nocontext";
- if (Expr *E = Node->getCondition()) {
- OS << "(";
- E->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- }
- template<typename T>
- void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
- for (typename T::varlist_iterator I = Node->varlist_begin(),
- E = Node->varlist_end();
- I != E; ++I) {
- assert(*I && "Expected non-null Stmt");
- OS << (I == Node->varlist_begin() ? StartSym : ',');
- if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
- if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
- DRE->printPretty(OS, nullptr, Policy, 0);
- else
- DRE->getDecl()->printQualifiedName(OS);
- } else
- (*I)->printPretty(OS, nullptr, Policy, 0);
- }
- }
- void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
- if (Node->varlist_empty())
- return;
- OS << "allocate";
- if (Expr *Allocator = Node->getAllocator()) {
- OS << "(";
- Allocator->printPretty(OS, nullptr, Policy, 0);
- OS << ":";
- VisitOMPClauseList(Node, ' ');
- } else {
- VisitOMPClauseList(Node, '(');
- }
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "private";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "firstprivate";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "lastprivate";
- OpenMPLastprivateModifier LPKind = Node->getKind();
- if (LPKind != OMPC_LASTPRIVATE_unknown) {
- OS << "("
- << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
- << ":";
- }
- VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "shared";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "reduction(";
- if (Node->getModifierLoc().isValid())
- OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier())
- << ", ";
- NestedNameSpecifier *QualifierLoc =
- Node->getQualifierLoc().getNestedNameSpecifier();
- OverloadedOperatorKind OOK =
- Node->getNameInfo().getName().getCXXOverloadedOperator();
- if (QualifierLoc == nullptr && OOK != OO_None) {
- // Print reduction identifier in C format
- OS << getOperatorSpelling(OOK);
- } else {
- // Use C++ format
- if (QualifierLoc != nullptr)
- QualifierLoc->print(OS, Policy);
- OS << Node->getNameInfo();
- }
- OS << ":";
- VisitOMPClauseList(Node, ' ');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPTaskReductionClause(
- OMPTaskReductionClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "task_reduction(";
- NestedNameSpecifier *QualifierLoc =
- Node->getQualifierLoc().getNestedNameSpecifier();
- OverloadedOperatorKind OOK =
- Node->getNameInfo().getName().getCXXOverloadedOperator();
- if (QualifierLoc == nullptr && OOK != OO_None) {
- // Print reduction identifier in C format
- OS << getOperatorSpelling(OOK);
- } else {
- // Use C++ format
- if (QualifierLoc != nullptr)
- QualifierLoc->print(OS, Policy);
- OS << Node->getNameInfo();
- }
- OS << ":";
- VisitOMPClauseList(Node, ' ');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "in_reduction(";
- NestedNameSpecifier *QualifierLoc =
- Node->getQualifierLoc().getNestedNameSpecifier();
- OverloadedOperatorKind OOK =
- Node->getNameInfo().getName().getCXXOverloadedOperator();
- if (QualifierLoc == nullptr && OOK != OO_None) {
- // Print reduction identifier in C format
- OS << getOperatorSpelling(OOK);
- } else {
- // Use C++ format
- if (QualifierLoc != nullptr)
- QualifierLoc->print(OS, Policy);
- OS << Node->getNameInfo();
- }
- OS << ":";
- VisitOMPClauseList(Node, ' ');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "linear";
- if (Node->getModifierLoc().isValid()) {
- OS << '('
- << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
- }
- VisitOMPClauseList(Node, '(');
- if (Node->getModifierLoc().isValid())
- OS << ')';
- if (Node->getStep() != nullptr) {
- OS << ": ";
- Node->getStep()->printPretty(OS, nullptr, Policy, 0);
- }
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "aligned";
- VisitOMPClauseList(Node, '(');
- if (Node->getAlignment() != nullptr) {
- OS << ": ";
- Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
- }
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "copyin";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "copyprivate";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
- if (!Node->varlist_empty()) {
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
- OS << "(";
- Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
- OS << "depend(";
- if (Expr *DepModifier = Node->getModifier()) {
- DepModifier->printPretty(OS, nullptr, Policy);
- OS << ", ";
- }
- 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, ' ');
- if (IsOmpAllMemory) {
- OS << (Node->varlist_empty() ? " " : ",");
- OS << "omp_all_memory";
- }
- OS << ")";
- }
- template <typename T>
- static void PrintMapper(raw_ostream &OS, T *Node,
- const PrintingPolicy &Policy) {
- OS << '(';
- NestedNameSpecifier *MapperNNS =
- Node->getMapperQualifierLoc().getNestedNameSpecifier();
- if (MapperNNS)
- MapperNNS->print(OS, Policy);
- 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) {
- 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 << ',';
- }
- }
- OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
- OS << ':';
- }
- VisitOMPClauseList(Node, ' ');
- OS << ")";
- }
- }
- template <typename T> void OMPClausePrinter::VisitOMPMotionClause(T *Node) {
- if (Node->varlist_empty())
- return;
- OS << getOpenMPClauseName(Node->getClauseKind());
- unsigned ModifierCount = 0;
- for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
- if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown)
- ++ModifierCount;
- }
- if (ModifierCount) {
- OS << '(';
- for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
- if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) {
- OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
- Node->getMotionModifier(I));
- if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
- PrintMapper(OS, Node, Policy);
- if (I < ModifierCount - 1)
- OS << ", ";
- }
- }
- OS << ':';
- VisitOMPClauseList(Node, ' ');
- } else {
- VisitOMPClauseList(Node, '(');
- }
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
- VisitOMPMotionClause(Node);
- }
- void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
- VisitOMPMotionClause(Node);
- }
- void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
- OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
- OMPC_dist_schedule, Node->getDistScheduleKind());
- if (auto *E = Node->getChunkSize()) {
- OS << ", ";
- E->printPretty(OS, nullptr, Policy);
- }
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
- OS << "defaultmap(";
- OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
- Node->getDefaultmapModifier());
- if (Node->getDefaultmapKind() != OMPC_DEFAULTMAP_unknown) {
- OS << ": ";
- OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
- Node->getDefaultmapKind());
- }
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "use_device_ptr";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPUseDeviceAddrClause(
- OMPUseDeviceAddrClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "use_device_addr";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "is_device_ptr";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- 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";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
- 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) {
- if (!Node->varlist_empty()) {
- OS << "inclusive";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
- if (!Node->varlist_empty()) {
- OS << "exclusive";
- VisitOMPClauseList(Node, '(');
- OS << ")";
- }
- }
- void OMPClausePrinter::VisitOMPUsesAllocatorsClause(
- OMPUsesAllocatorsClause *Node) {
- if (Node->getNumberOfAllocators() == 0)
- return;
- OS << "uses_allocators(";
- for (unsigned I = 0, E = Node->getNumberOfAllocators(); I < E; ++I) {
- OMPUsesAllocatorsClause::Data Data = Node->getAllocatorData(I);
- Data.Allocator->printPretty(OS, nullptr, Policy);
- if (Data.AllocatorTraits) {
- OS << "(";
- Data.AllocatorTraits->printPretty(OS, nullptr, Policy);
- OS << ")";
- }
- if (I < E - 1)
- OS << ",";
- }
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPAffinityClause(OMPAffinityClause *Node) {
- if (Node->varlist_empty())
- return;
- OS << "affinity";
- char StartSym = '(';
- if (Expr *Modifier = Node->getModifier()) {
- OS << "(";
- Modifier->printPretty(OS, nullptr, Policy);
- OS << " :";
- StartSym = ' ';
- }
- VisitOMPClauseList(Node, StartSym);
- OS << ")";
- }
- void OMPClausePrinter::VisitOMPFilterClause(OMPFilterClause *Node) {
- OS << "filter(";
- Node->getThreadID()->printPretty(OS, nullptr, Policy, 0);
- 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 OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
- VariantMatchInfo &VMI) const {
- for (const OMPTraitSet &Set : Sets) {
- for (const OMPTraitSelector &Selector : Set.Selectors) {
- // User conditions are special as we evaluate the condition here.
- if (Selector.Kind == TraitSelector::user_condition) {
- assert(Selector.ScoreOrCondition &&
- "Ill-formed user condition, expected condition expression!");
- assert(Selector.Properties.size() == 1 &&
- Selector.Properties.front().Kind ==
- TraitProperty::user_condition_unknown &&
- "Ill-formed user condition, expected unknown trait property!");
- if (std::optional<APSInt> CondVal =
- Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))
- VMI.addTrait(CondVal->isZero() ? TraitProperty::user_condition_false
- : TraitProperty::user_condition_true,
- "<condition>");
- else
- VMI.addTrait(TraitProperty::user_condition_false, "<condition>");
- continue;
- }
- std::optional<llvm::APSInt> Score;
- llvm::APInt *ScorePtr = nullptr;
- if (Selector.ScoreOrCondition) {
- if ((Score = Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)))
- ScorePtr = &*Score;
- else
- VMI.addTrait(TraitProperty::user_condition_false,
- "<non-constant-score>");
- }
- for (const OMPTraitProperty &Property : Selector.Properties)
- VMI.addTrait(Set.Kind, Property.Kind, Property.RawString, ScorePtr);
- if (Set.Kind != TraitSet::construct)
- continue;
- // TODO: This might not hold once we implement SIMD properly.
- assert(Selector.Properties.size() == 1 &&
- Selector.Properties.front().Kind ==
- getOpenMPContextTraitPropertyForSelector(
- Selector.Kind) &&
- "Ill-formed construct selector!");
- }
- }
- }
- void OMPTraitInfo::print(llvm::raw_ostream &OS,
- const PrintingPolicy &Policy) const {
- bool FirstSet = true;
- for (const OMPTraitSet &Set : Sets) {
- if (!FirstSet)
- OS << ", ";
- FirstSet = false;
- OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
- bool FirstSelector = true;
- for (const OMPTraitSelector &Selector : Set.Selectors) {
- if (!FirstSelector)
- OS << ", ";
- FirstSelector = false;
- OS << getOpenMPContextTraitSelectorName(Selector.Kind);
- bool AllowsTraitScore = false;
- bool RequiresProperty = false;
- isValidTraitSelectorForTraitSet(
- Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
- if (!RequiresProperty)
- continue;
- OS << "(";
- if (Selector.Kind == TraitSelector::user_condition) {
- if (Selector.ScoreOrCondition)
- Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
- else
- OS << "...";
- } else {
- if (Selector.ScoreOrCondition) {
- OS << "score(";
- Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
- OS << "): ";
- }
- bool FirstProperty = true;
- for (const OMPTraitProperty &Property : Selector.Properties) {
- if (!FirstProperty)
- OS << ", ";
- FirstProperty = false;
- OS << getOpenMPContextTraitPropertyName(Property.Kind,
- Property.RawString);
- }
- }
- OS << ")";
- }
- OS << "}";
- }
- }
- std::string OMPTraitInfo::getMangledName() const {
- std::string MangledName;
- llvm::raw_string_ostream OS(MangledName);
- for (const OMPTraitSet &Set : Sets) {
- OS << '$' << 'S' << unsigned(Set.Kind);
- for (const OMPTraitSelector &Selector : Set.Selectors) {
- bool AllowsTraitScore = false;
- bool RequiresProperty = false;
- isValidTraitSelectorForTraitSet(
- Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
- OS << '$' << 's' << unsigned(Selector.Kind);
- if (!RequiresProperty ||
- Selector.Kind == TraitSelector::user_condition)
- continue;
- for (const OMPTraitProperty &Property : Selector.Properties)
- OS << '$' << 'P'
- << getOpenMPContextTraitPropertyName(Property.Kind,
- Property.RawString);
- }
- }
- return MangledName;
- }
- OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
- unsigned long U;
- do {
- if (!MangledName.consume_front("$S"))
- break;
- if (MangledName.consumeInteger(10, U))
- break;
- Sets.push_back(OMPTraitSet());
- OMPTraitSet &Set = Sets.back();
- Set.Kind = TraitSet(U);
- do {
- if (!MangledName.consume_front("$s"))
- break;
- if (MangledName.consumeInteger(10, U))
- break;
- Set.Selectors.push_back(OMPTraitSelector());
- OMPTraitSelector &Selector = Set.Selectors.back();
- Selector.Kind = TraitSelector(U);
- do {
- if (!MangledName.consume_front("$P"))
- break;
- Selector.Properties.push_back(OMPTraitProperty());
- OMPTraitProperty &Property = Selector.Properties.back();
- std::pair<StringRef, StringRef> PropRestPair = MangledName.split('$');
- Property.RawString = PropRestPair.first;
- Property.Kind = getOpenMPContextTraitPropertyKind(
- Set.Kind, Selector.Kind, PropRestPair.first);
- MangledName = MangledName.drop_front(PropRestPair.first.size());
- } while (true);
- } while (true);
- } while (true);
- }
- llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
- const OMPTraitInfo &TI) {
- LangOptions LO;
- PrintingPolicy Policy(LO);
- TI.print(OS, Policy);
- return OS;
- }
- llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
- const OMPTraitInfo *TI) {
- return TI ? OS << *TI : OS;
- }
- TargetOMPContext::TargetOMPContext(
- ASTContext &ASTCtx, std::function<void(StringRef)> &&DiagUnknownTrait,
- const FunctionDecl *CurrentFunctionDecl,
- ArrayRef<llvm::omp::TraitProperty> ConstructTraits)
- : OMPContext(ASTCtx.getLangOpts().OpenMPIsDevice,
- 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 {
- auto It = FeatureMap.find(RawString);
- if (It != FeatureMap.end())
- return It->second;
- if (!FeatureValidityCheck(RawString))
- DiagUnknownTrait(RawString);
- return false;
- }
|