StmtOpenMP.h 210 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- StmtOpenMP.h - Classes for OpenMP directives ------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. /// This file defines OpenMP AST classes for executable directives and
  15. /// clauses.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_AST_STMTOPENMP_H
  19. #define LLVM_CLANG_AST_STMTOPENMP_H
  20. #include "clang/AST/ASTContext.h"
  21. #include "clang/AST/Expr.h"
  22. #include "clang/AST/OpenMPClause.h"
  23. #include "clang/AST/Stmt.h"
  24. #include "clang/AST/StmtCXX.h"
  25. #include "clang/Basic/OpenMPKinds.h"
  26. #include "clang/Basic/SourceLocation.h"
  27. namespace clang {
  28. //===----------------------------------------------------------------------===//
  29. // AST classes for directives.
  30. //===----------------------------------------------------------------------===//
  31. /// Representation of an OpenMP canonical loop.
  32. ///
  33. /// OpenMP 1.0 C/C++, section 2.4.1 for Construct; canonical-shape
  34. /// OpenMP 2.0 C/C++, section 2.4.1 for Construct; canonical-shape
  35. /// OpenMP 2.5, section 2.5.1 Loop Construct; canonical form
  36. /// OpenMP 3.1, section 2.5.1 Loop Construct; canonical form
  37. /// OpenMP 4.0, section 2.6 Canonical Loop Form
  38. /// OpenMP 4.5, section 2.6 Canonical Loop Form
  39. /// OpenMP 5.0, section 2.9.1 Canonical Loop Form
  40. /// OpenMP 5.1, section 2.11.1 Canonical Loop Nest Form
  41. ///
  42. /// An OpenMP canonical loop is a for-statement or range-based for-statement
  43. /// with additional requirements that ensure that the number of iterations is
  44. /// known before entering the loop and allow skipping to an arbitrary iteration.
  45. /// The OMPCanonicalLoop AST node wraps a ForStmt or CXXForRangeStmt that is
  46. /// known to fulfill OpenMP's canonical loop requirements because of being
  47. /// associated to an OMPLoopBasedDirective. That is, the general structure is:
  48. ///
  49. /// OMPLoopBasedDirective
  50. /// [`- CapturedStmt ]
  51. /// [ `- CapturedDecl]
  52. /// ` OMPCanonicalLoop
  53. /// `- ForStmt/CXXForRangeStmt
  54. /// `- Stmt
  55. ///
  56. /// One or multiple CapturedStmt/CapturedDecl pairs may be inserted by some
  57. /// directives such as OMPParallelForDirective, but others do not need them
  58. /// (such as OMPTileDirective). In The OMPCanonicalLoop and
  59. /// ForStmt/CXXForRangeStmt pair is repeated for loop associated with the
  60. /// directive. A OMPCanonicalLoop must not appear in the AST unless associated
  61. /// with a OMPLoopBasedDirective. In an imperfectly nested loop nest, the
  62. /// OMPCanonicalLoop may also be wrapped in a CompoundStmt:
  63. ///
  64. /// [...]
  65. /// ` OMPCanonicalLoop
  66. /// `- ForStmt/CXXForRangeStmt
  67. /// `- CompoundStmt
  68. /// |- Leading in-between code (if any)
  69. /// |- OMPCanonicalLoop
  70. /// | `- ForStmt/CXXForRangeStmt
  71. /// | `- ...
  72. /// `- Trailing in-between code (if any)
  73. ///
  74. /// The leading/trailing in-between code must not itself be a OMPCanonicalLoop
  75. /// to avoid confusion which loop belongs to the nesting.
  76. ///
  77. /// There are three different kinds of iteration variables for different
  78. /// purposes:
  79. /// * Loop user variable: The user-accessible variable with different value for
  80. /// each iteration.
  81. /// * Loop iteration variable: The variable used to identify a loop iteration;
  82. /// for range-based for-statement, this is the hidden iterator '__begin'. For
  83. /// other loops, it is identical to the loop user variable. Must be a
  84. /// random-access iterator, pointer or integer type.
  85. /// * Logical iteration counter: Normalized loop counter starting at 0 and
  86. /// incrementing by one at each iteration. Allows abstracting over the type
  87. /// of the loop iteration variable and is always an unsigned integer type
  88. /// appropriate to represent the range of the loop iteration variable. Its
  89. /// value corresponds to the logical iteration number in the OpenMP
  90. /// specification.
  91. ///
  92. /// This AST node provides two captured statements:
  93. /// * The distance function which computes the number of iterations.
  94. /// * The loop user variable function that computes the loop user variable when
  95. /// given a logical iteration number.
  96. ///
  97. /// These captured statements provide the link between C/C++ semantics and the
  98. /// logical iteration counters used by the OpenMPIRBuilder which is
  99. /// language-agnostic and therefore does not know e.g. how to advance a
  100. /// random-access iterator. The OpenMPIRBuilder will use this information to
  101. /// apply simd, workshare-loop, distribute, taskloop and loop directives to the
  102. /// loop. For compatibility with the non-OpenMPIRBuilder codegen path, an
  103. /// OMPCanonicalLoop can itself also be wrapped into the CapturedStmts of an
  104. /// OMPLoopDirective and skipped when searching for the associated syntactical
  105. /// loop.
  106. ///
  107. /// Example:
  108. /// <code>
  109. /// std::vector<std::string> Container{1,2,3};
  110. /// for (std::string Str : Container)
  111. /// Body(Str);
  112. /// </code>
  113. /// which is syntactic sugar for approximately:
  114. /// <code>
  115. /// auto &&__range = Container;
  116. /// auto __begin = std::begin(__range);
  117. /// auto __end = std::end(__range);
  118. /// for (; __begin != __end; ++__begin) {
  119. /// std::String Str = *__begin;
  120. /// Body(Str);
  121. /// }
  122. /// </code>
  123. /// In this example, the loop user variable is `Str`, the loop iteration
  124. /// variable is `__begin` of type `std::vector<std::string>::iterator` and the
  125. /// logical iteration number type is `size_t` (unsigned version of
  126. /// `std::vector<std::string>::iterator::difference_type` aka `ptrdiff_t`).
  127. /// Therefore, the distance function will be
  128. /// <code>
  129. /// [&](size_t &Result) { Result = __end - __begin; }
  130. /// </code>
  131. /// and the loop variable function is
  132. /// <code>
  133. /// [&,__begin](std::vector<std::string>::iterator &Result, size_t Logical) {
  134. /// Result = __begin + Logical;
  135. /// }
  136. /// </code>
  137. /// The variable `__begin`, aka the loop iteration variable, is captured by
  138. /// value because it is modified in the loop body, but both functions require
  139. /// the initial value. The OpenMP specification explicitly leaves unspecified
  140. /// when the loop expressions are evaluated such that a capture by reference is
  141. /// sufficient.
  142. class OMPCanonicalLoop : public Stmt {
  143. friend class ASTStmtReader;
  144. friend class ASTStmtWriter;
  145. /// Children of this AST node.
  146. enum {
  147. LOOP_STMT,
  148. DISTANCE_FUNC,
  149. LOOPVAR_FUNC,
  150. LOOPVAR_REF,
  151. LastSubStmt = LOOPVAR_REF
  152. };
  153. private:
  154. /// This AST node's children.
  155. Stmt *SubStmts[LastSubStmt + 1] = {};
  156. OMPCanonicalLoop() : Stmt(StmtClass::OMPCanonicalLoopClass) {}
  157. public:
  158. /// Create a new OMPCanonicalLoop.
  159. static OMPCanonicalLoop *create(const ASTContext &Ctx, Stmt *LoopStmt,
  160. CapturedStmt *DistanceFunc,
  161. CapturedStmt *LoopVarFunc,
  162. DeclRefExpr *LoopVarRef) {
  163. OMPCanonicalLoop *S = new (Ctx) OMPCanonicalLoop();
  164. S->setLoopStmt(LoopStmt);
  165. S->setDistanceFunc(DistanceFunc);
  166. S->setLoopVarFunc(LoopVarFunc);
  167. S->setLoopVarRef(LoopVarRef);
  168. return S;
  169. }
  170. /// Create an empty OMPCanonicalLoop for deserialization.
  171. static OMPCanonicalLoop *createEmpty(const ASTContext &Ctx) {
  172. return new (Ctx) OMPCanonicalLoop();
  173. }
  174. static bool classof(const Stmt *S) {
  175. return S->getStmtClass() == StmtClass::OMPCanonicalLoopClass;
  176. }
  177. SourceLocation getBeginLoc() const { return getLoopStmt()->getBeginLoc(); }
  178. SourceLocation getEndLoc() const { return getLoopStmt()->getEndLoc(); }
  179. /// Return this AST node's children.
  180. /// @{
  181. child_range children() {
  182. return child_range(&SubStmts[0], &SubStmts[0] + LastSubStmt + 1);
  183. }
  184. const_child_range children() const {
  185. return const_child_range(&SubStmts[0], &SubStmts[0] + LastSubStmt + 1);
  186. }
  187. /// @}
  188. /// The wrapped syntactic loop statement (ForStmt or CXXForRangeStmt).
  189. /// @{
  190. Stmt *getLoopStmt() { return SubStmts[LOOP_STMT]; }
  191. const Stmt *getLoopStmt() const { return SubStmts[LOOP_STMT]; }
  192. void setLoopStmt(Stmt *S) {
  193. assert((isa<ForStmt>(S) || isa<CXXForRangeStmt>(S)) &&
  194. "Canonical loop must be a for loop (range-based or otherwise)");
  195. SubStmts[LOOP_STMT] = S;
  196. }
  197. /// @}
  198. /// The function that computes the number of loop iterations. Can be evaluated
  199. /// before entering the loop but after the syntactical loop's init
  200. /// statement(s).
  201. ///
  202. /// Function signature: void(LogicalTy &Result)
  203. /// Any values necessary to compute the distance are captures of the closure.
  204. /// @{
  205. CapturedStmt *getDistanceFunc() {
  206. return cast<CapturedStmt>(SubStmts[DISTANCE_FUNC]);
  207. }
  208. const CapturedStmt *getDistanceFunc() const {
  209. return cast<CapturedStmt>(SubStmts[DISTANCE_FUNC]);
  210. }
  211. void setDistanceFunc(CapturedStmt *S) {
  212. assert(S && "Expected non-null captured statement");
  213. SubStmts[DISTANCE_FUNC] = S;
  214. }
  215. /// @}
  216. /// The function that computes the loop user variable from a logical iteration
  217. /// counter. Can be evaluated as first statement in the loop.
  218. ///
  219. /// Function signature: void(LoopVarTy &Result, LogicalTy Number)
  220. /// Any other values required to compute the loop user variable (such as start
  221. /// value, step size) are captured by the closure. In particular, the initial
  222. /// value of loop iteration variable is captured by value to be unaffected by
  223. /// previous iterations.
  224. /// @{
  225. CapturedStmt *getLoopVarFunc() {
  226. return cast<CapturedStmt>(SubStmts[LOOPVAR_FUNC]);
  227. }
  228. const CapturedStmt *getLoopVarFunc() const {
  229. return cast<CapturedStmt>(SubStmts[LOOPVAR_FUNC]);
  230. }
  231. void setLoopVarFunc(CapturedStmt *S) {
  232. assert(S && "Expected non-null captured statement");
  233. SubStmts[LOOPVAR_FUNC] = S;
  234. }
  235. /// @}
  236. /// Reference to the loop user variable as accessed in the loop body.
  237. /// @{
  238. DeclRefExpr *getLoopVarRef() {
  239. return cast<DeclRefExpr>(SubStmts[LOOPVAR_REF]);
  240. }
  241. const DeclRefExpr *getLoopVarRef() const {
  242. return cast<DeclRefExpr>(SubStmts[LOOPVAR_REF]);
  243. }
  244. void setLoopVarRef(DeclRefExpr *E) {
  245. assert(E && "Expected non-null loop variable");
  246. SubStmts[LOOPVAR_REF] = E;
  247. }
  248. /// @}
  249. };
  250. /// This is a basic class for representing single OpenMP executable
  251. /// directive.
  252. ///
  253. class OMPExecutableDirective : public Stmt {
  254. friend class ASTStmtReader;
  255. friend class ASTStmtWriter;
  256. /// Kind of the directive.
  257. OpenMPDirectiveKind Kind = llvm::omp::OMPD_unknown;
  258. /// Starting location of the directive (directive keyword).
  259. SourceLocation StartLoc;
  260. /// Ending location of the directive.
  261. SourceLocation EndLoc;
  262. /// Get the clauses storage.
  263. MutableArrayRef<OMPClause *> getClauses() {
  264. if (!Data)
  265. return llvm::None;
  266. return Data->getClauses();
  267. }
  268. protected:
  269. /// Data, associated with the directive.
  270. OMPChildren *Data = nullptr;
  271. /// Build instance of directive of class \a K.
  272. ///
  273. /// \param SC Statement class.
  274. /// \param K Kind of OpenMP directive.
  275. /// \param StartLoc Starting location of the directive (directive keyword).
  276. /// \param EndLoc Ending location of the directive.
  277. ///
  278. OMPExecutableDirective(StmtClass SC, OpenMPDirectiveKind K,
  279. SourceLocation StartLoc, SourceLocation EndLoc)
  280. : Stmt(SC), Kind(K), StartLoc(std::move(StartLoc)),
  281. EndLoc(std::move(EndLoc)) {}
  282. template <typename T, typename... Params>
  283. static T *createDirective(const ASTContext &C, ArrayRef<OMPClause *> Clauses,
  284. Stmt *AssociatedStmt, unsigned NumChildren,
  285. Params &&... P) {
  286. void *Mem =
  287. C.Allocate(sizeof(T) + OMPChildren::size(Clauses.size(), AssociatedStmt,
  288. NumChildren),
  289. alignof(T));
  290. auto *Data = OMPChildren::Create(reinterpret_cast<T *>(Mem) + 1, Clauses,
  291. AssociatedStmt, NumChildren);
  292. auto *Inst = new (Mem) T(std::forward<Params>(P)...);
  293. Inst->Data = Data;
  294. return Inst;
  295. }
  296. template <typename T, typename... Params>
  297. static T *createEmptyDirective(const ASTContext &C, unsigned NumClauses,
  298. bool HasAssociatedStmt, unsigned NumChildren,
  299. Params &&... P) {
  300. void *Mem =
  301. C.Allocate(sizeof(T) + OMPChildren::size(NumClauses, HasAssociatedStmt,
  302. NumChildren),
  303. alignof(T));
  304. auto *Data =
  305. OMPChildren::CreateEmpty(reinterpret_cast<T *>(Mem) + 1, NumClauses,
  306. HasAssociatedStmt, NumChildren);
  307. auto *Inst = new (Mem) T(std::forward<Params>(P)...);
  308. Inst->Data = Data;
  309. return Inst;
  310. }
  311. template <typename T>
  312. static T *createEmptyDirective(const ASTContext &C, unsigned NumClauses,
  313. bool HasAssociatedStmt = false,
  314. unsigned NumChildren = 0) {
  315. void *Mem =
  316. C.Allocate(sizeof(T) + OMPChildren::size(NumClauses, HasAssociatedStmt,
  317. NumChildren),
  318. alignof(T));
  319. auto *Data =
  320. OMPChildren::CreateEmpty(reinterpret_cast<T *>(Mem) + 1, NumClauses,
  321. HasAssociatedStmt, NumChildren);
  322. auto *Inst = new (Mem) T;
  323. Inst->Data = Data;
  324. return Inst;
  325. }
  326. public:
  327. /// Iterates over expressions/statements used in the construct.
  328. class used_clauses_child_iterator
  329. : public llvm::iterator_adaptor_base<
  330. used_clauses_child_iterator, ArrayRef<OMPClause *>::iterator,
  331. std::forward_iterator_tag, Stmt *, ptrdiff_t, Stmt *, Stmt *> {
  332. ArrayRef<OMPClause *>::iterator End;
  333. OMPClause::child_iterator ChildI, ChildEnd;
  334. void MoveToNext() {
  335. if (ChildI != ChildEnd)
  336. return;
  337. while (this->I != End) {
  338. ++this->I;
  339. if (this->I != End) {
  340. ChildI = (*this->I)->used_children().begin();
  341. ChildEnd = (*this->I)->used_children().end();
  342. if (ChildI != ChildEnd)
  343. return;
  344. }
  345. }
  346. }
  347. public:
  348. explicit used_clauses_child_iterator(ArrayRef<OMPClause *> Clauses)
  349. : used_clauses_child_iterator::iterator_adaptor_base(Clauses.begin()),
  350. End(Clauses.end()) {
  351. if (this->I != End) {
  352. ChildI = (*this->I)->used_children().begin();
  353. ChildEnd = (*this->I)->used_children().end();
  354. MoveToNext();
  355. }
  356. }
  357. Stmt *operator*() const { return *ChildI; }
  358. Stmt *operator->() const { return **this; }
  359. used_clauses_child_iterator &operator++() {
  360. ++ChildI;
  361. if (ChildI != ChildEnd)
  362. return *this;
  363. if (this->I != End) {
  364. ++this->I;
  365. if (this->I != End) {
  366. ChildI = (*this->I)->used_children().begin();
  367. ChildEnd = (*this->I)->used_children().end();
  368. }
  369. }
  370. MoveToNext();
  371. return *this;
  372. }
  373. };
  374. static llvm::iterator_range<used_clauses_child_iterator>
  375. used_clauses_children(ArrayRef<OMPClause *> Clauses) {
  376. return {used_clauses_child_iterator(Clauses),
  377. used_clauses_child_iterator(llvm::makeArrayRef(Clauses.end(), 0))};
  378. }
  379. /// Iterates over a filtered subrange of clauses applied to a
  380. /// directive.
  381. ///
  382. /// This iterator visits only clauses of type SpecificClause.
  383. template <typename SpecificClause>
  384. class specific_clause_iterator
  385. : public llvm::iterator_adaptor_base<
  386. specific_clause_iterator<SpecificClause>,
  387. ArrayRef<OMPClause *>::const_iterator, std::forward_iterator_tag,
  388. const SpecificClause *, ptrdiff_t, const SpecificClause *,
  389. const SpecificClause *> {
  390. ArrayRef<OMPClause *>::const_iterator End;
  391. void SkipToNextClause() {
  392. while (this->I != End && !isa<SpecificClause>(*this->I))
  393. ++this->I;
  394. }
  395. public:
  396. explicit specific_clause_iterator(ArrayRef<OMPClause *> Clauses)
  397. : specific_clause_iterator::iterator_adaptor_base(Clauses.begin()),
  398. End(Clauses.end()) {
  399. SkipToNextClause();
  400. }
  401. const SpecificClause *operator*() const {
  402. return cast<SpecificClause>(*this->I);
  403. }
  404. const SpecificClause *operator->() const { return **this; }
  405. specific_clause_iterator &operator++() {
  406. ++this->I;
  407. SkipToNextClause();
  408. return *this;
  409. }
  410. };
  411. template <typename SpecificClause>
  412. static llvm::iterator_range<specific_clause_iterator<SpecificClause>>
  413. getClausesOfKind(ArrayRef<OMPClause *> Clauses) {
  414. return {specific_clause_iterator<SpecificClause>(Clauses),
  415. specific_clause_iterator<SpecificClause>(
  416. llvm::makeArrayRef(Clauses.end(), 0))};
  417. }
  418. template <typename SpecificClause>
  419. llvm::iterator_range<specific_clause_iterator<SpecificClause>>
  420. getClausesOfKind() const {
  421. return getClausesOfKind<SpecificClause>(clauses());
  422. }
  423. /// Gets a single clause of the specified kind associated with the
  424. /// current directive iff there is only one clause of this kind (and assertion
  425. /// is fired if there is more than one clause is associated with the
  426. /// directive). Returns nullptr if no clause of this kind is associated with
  427. /// the directive.
  428. template <typename SpecificClause>
  429. static const SpecificClause *getSingleClause(ArrayRef<OMPClause *> Clauses) {
  430. auto ClausesOfKind = getClausesOfKind<SpecificClause>(Clauses);
  431. if (ClausesOfKind.begin() != ClausesOfKind.end()) {
  432. assert(std::next(ClausesOfKind.begin()) == ClausesOfKind.end() &&
  433. "There are at least 2 clauses of the specified kind");
  434. return *ClausesOfKind.begin();
  435. }
  436. return nullptr;
  437. }
  438. template <typename SpecificClause>
  439. const SpecificClause *getSingleClause() const {
  440. return getSingleClause<SpecificClause>(clauses());
  441. }
  442. /// Returns true if the current directive has one or more clauses of a
  443. /// specific kind.
  444. template <typename SpecificClause>
  445. bool hasClausesOfKind() const {
  446. auto Clauses = getClausesOfKind<SpecificClause>();
  447. return Clauses.begin() != Clauses.end();
  448. }
  449. /// Returns starting location of directive kind.
  450. SourceLocation getBeginLoc() const { return StartLoc; }
  451. /// Returns ending location of directive.
  452. SourceLocation getEndLoc() const { return EndLoc; }
  453. /// Set starting location of directive kind.
  454. ///
  455. /// \param Loc New starting location of directive.
  456. ///
  457. void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
  458. /// Set ending location of directive.
  459. ///
  460. /// \param Loc New ending location of directive.
  461. ///
  462. void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
  463. /// Get number of clauses.
  464. unsigned getNumClauses() const {
  465. if (!Data)
  466. return 0;
  467. return Data->getNumClauses();
  468. }
  469. /// Returns specified clause.
  470. ///
  471. /// \param I Number of clause.
  472. ///
  473. OMPClause *getClause(unsigned I) const { return clauses()[I]; }
  474. /// Returns true if directive has associated statement.
  475. bool hasAssociatedStmt() const { return Data && Data->hasAssociatedStmt(); }
  476. /// Returns statement associated with the directive.
  477. const Stmt *getAssociatedStmt() const {
  478. return const_cast<OMPExecutableDirective *>(this)->getAssociatedStmt();
  479. }
  480. Stmt *getAssociatedStmt() {
  481. assert(hasAssociatedStmt() &&
  482. "Expected directive with the associated statement.");
  483. return Data->getAssociatedStmt();
  484. }
  485. /// Returns the captured statement associated with the
  486. /// component region within the (combined) directive.
  487. ///
  488. /// \param RegionKind Component region kind.
  489. const CapturedStmt *getCapturedStmt(OpenMPDirectiveKind RegionKind) const {
  490. assert(hasAssociatedStmt() &&
  491. "Expected directive with the associated statement.");
  492. SmallVector<OpenMPDirectiveKind, 4> CaptureRegions;
  493. getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind());
  494. return Data->getCapturedStmt(RegionKind, CaptureRegions);
  495. }
  496. /// Get innermost captured statement for the construct.
  497. CapturedStmt *getInnermostCapturedStmt() {
  498. assert(hasAssociatedStmt() &&
  499. "Expected directive with the associated statement.");
  500. SmallVector<OpenMPDirectiveKind, 4> CaptureRegions;
  501. getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind());
  502. return Data->getInnermostCapturedStmt(CaptureRegions);
  503. }
  504. const CapturedStmt *getInnermostCapturedStmt() const {
  505. return const_cast<OMPExecutableDirective *>(this)
  506. ->getInnermostCapturedStmt();
  507. }
  508. OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
  509. static bool classof(const Stmt *S) {
  510. return S->getStmtClass() >= firstOMPExecutableDirectiveConstant &&
  511. S->getStmtClass() <= lastOMPExecutableDirectiveConstant;
  512. }
  513. child_range children() {
  514. if (!Data)
  515. return child_range(child_iterator(), child_iterator());
  516. return Data->getAssociatedStmtAsRange();
  517. }
  518. const_child_range children() const {
  519. return const_cast<OMPExecutableDirective *>(this)->children();
  520. }
  521. ArrayRef<OMPClause *> clauses() const {
  522. if (!Data)
  523. return llvm::None;
  524. return Data->getClauses();
  525. }
  526. /// Returns whether or not this is a Standalone directive.
  527. ///
  528. /// Stand-alone directives are executable directives
  529. /// that have no associated user code.
  530. bool isStandaloneDirective() const;
  531. /// Returns the AST node representing OpenMP structured-block of this
  532. /// OpenMP executable directive,
  533. /// Prerequisite: Executable Directive must not be Standalone directive.
  534. const Stmt *getStructuredBlock() const {
  535. return const_cast<OMPExecutableDirective *>(this)->getStructuredBlock();
  536. }
  537. Stmt *getStructuredBlock();
  538. const Stmt *getRawStmt() const {
  539. return const_cast<OMPExecutableDirective *>(this)->getRawStmt();
  540. }
  541. Stmt *getRawStmt() {
  542. assert(hasAssociatedStmt() &&
  543. "Expected directive with the associated statement.");
  544. return Data->getRawStmt();
  545. }
  546. };
  547. /// This represents '#pragma omp parallel' directive.
  548. ///
  549. /// \code
  550. /// #pragma omp parallel private(a,b) reduction(+: c,d)
  551. /// \endcode
  552. /// In this example directive '#pragma omp parallel' has clauses 'private'
  553. /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
  554. /// variables 'c' and 'd'.
  555. ///
  556. class OMPParallelDirective : public OMPExecutableDirective {
  557. friend class ASTStmtReader;
  558. friend class OMPExecutableDirective;
  559. /// true if the construct has inner cancel directive.
  560. bool HasCancel = false;
  561. /// Build directive with the given start and end location.
  562. ///
  563. /// \param StartLoc Starting location of the directive (directive keyword).
  564. /// \param EndLoc Ending Location of the directive.
  565. ///
  566. OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  567. : OMPExecutableDirective(OMPParallelDirectiveClass,
  568. llvm::omp::OMPD_parallel, StartLoc, EndLoc) {}
  569. /// Build an empty directive.
  570. ///
  571. explicit OMPParallelDirective()
  572. : OMPExecutableDirective(OMPParallelDirectiveClass,
  573. llvm::omp::OMPD_parallel, SourceLocation(),
  574. SourceLocation()) {}
  575. /// Sets special task reduction descriptor.
  576. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; }
  577. /// Set cancel state.
  578. void setHasCancel(bool Has) { HasCancel = Has; }
  579. public:
  580. /// Creates directive with a list of \a Clauses.
  581. ///
  582. /// \param C AST context.
  583. /// \param StartLoc Starting location of the directive kind.
  584. /// \param EndLoc Ending Location of the directive.
  585. /// \param Clauses List of clauses.
  586. /// \param AssociatedStmt Statement associated with the directive.
  587. /// \param TaskRedRef Task reduction special reference expression to handle
  588. /// taskgroup descriptor.
  589. /// \param HasCancel true if this directive has inner cancel directive.
  590. ///
  591. static OMPParallelDirective *
  592. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  593. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef,
  594. bool HasCancel);
  595. /// Creates an empty directive with the place for \a N clauses.
  596. ///
  597. /// \param C AST context.
  598. /// \param NumClauses Number of clauses.
  599. ///
  600. static OMPParallelDirective *CreateEmpty(const ASTContext &C,
  601. unsigned NumClauses, EmptyShell);
  602. /// Returns special task reduction reference expression.
  603. Expr *getTaskReductionRefExpr() {
  604. return cast_or_null<Expr>(Data->getChildren()[0]);
  605. }
  606. const Expr *getTaskReductionRefExpr() const {
  607. return const_cast<OMPParallelDirective *>(this)->getTaskReductionRefExpr();
  608. }
  609. /// Return true if current directive has inner cancel directive.
  610. bool hasCancel() const { return HasCancel; }
  611. static bool classof(const Stmt *T) {
  612. return T->getStmtClass() == OMPParallelDirectiveClass;
  613. }
  614. };
  615. /// The base class for all loop-based directives, including loop transformation
  616. /// directives.
  617. class OMPLoopBasedDirective : public OMPExecutableDirective {
  618. friend class ASTStmtReader;
  619. protected:
  620. /// Number of collapsed loops as specified by 'collapse' clause.
  621. unsigned NumAssociatedLoops = 0;
  622. /// Build instance of loop directive of class \a Kind.
  623. ///
  624. /// \param SC Statement class.
  625. /// \param Kind Kind of OpenMP directive.
  626. /// \param StartLoc Starting location of the directive (directive keyword).
  627. /// \param EndLoc Ending location of the directive.
  628. /// \param NumAssociatedLoops Number of loops associated with the construct.
  629. ///
  630. OMPLoopBasedDirective(StmtClass SC, OpenMPDirectiveKind Kind,
  631. SourceLocation StartLoc, SourceLocation EndLoc,
  632. unsigned NumAssociatedLoops)
  633. : OMPExecutableDirective(SC, Kind, StartLoc, EndLoc),
  634. NumAssociatedLoops(NumAssociatedLoops) {}
  635. public:
  636. /// The expressions built to support OpenMP loops in combined/composite
  637. /// pragmas (e.g. pragma omp distribute parallel for)
  638. struct DistCombinedHelperExprs {
  639. /// DistributeLowerBound - used when composing 'omp distribute' with
  640. /// 'omp for' in a same construct.
  641. Expr *LB;
  642. /// DistributeUpperBound - used when composing 'omp distribute' with
  643. /// 'omp for' in a same construct.
  644. Expr *UB;
  645. /// DistributeEnsureUpperBound - used when composing 'omp distribute'
  646. /// with 'omp for' in a same construct, EUB depends on DistUB
  647. Expr *EUB;
  648. /// Distribute loop iteration variable init used when composing 'omp
  649. /// distribute'
  650. /// with 'omp for' in a same construct
  651. Expr *Init;
  652. /// Distribute Loop condition used when composing 'omp distribute'
  653. /// with 'omp for' in a same construct
  654. Expr *Cond;
  655. /// Update of LowerBound for statically scheduled omp loops for
  656. /// outer loop in combined constructs (e.g. 'distribute parallel for')
  657. Expr *NLB;
  658. /// Update of UpperBound for statically scheduled omp loops for
  659. /// outer loop in combined constructs (e.g. 'distribute parallel for')
  660. Expr *NUB;
  661. /// Distribute Loop condition used when composing 'omp distribute'
  662. /// with 'omp for' in a same construct when schedule is chunked.
  663. Expr *DistCond;
  664. /// 'omp parallel for' loop condition used when composed with
  665. /// 'omp distribute' in the same construct and when schedule is
  666. /// chunked and the chunk size is 1.
  667. Expr *ParForInDistCond;
  668. };
  669. /// The expressions built for the OpenMP loop CodeGen for the
  670. /// whole collapsed loop nest.
  671. struct HelperExprs {
  672. /// Loop iteration variable.
  673. Expr *IterationVarRef;
  674. /// Loop last iteration number.
  675. Expr *LastIteration;
  676. /// Loop number of iterations.
  677. Expr *NumIterations;
  678. /// Calculation of last iteration.
  679. Expr *CalcLastIteration;
  680. /// Loop pre-condition.
  681. Expr *PreCond;
  682. /// Loop condition.
  683. Expr *Cond;
  684. /// Loop iteration variable init.
  685. Expr *Init;
  686. /// Loop increment.
  687. Expr *Inc;
  688. /// IsLastIteration - local flag variable passed to runtime.
  689. Expr *IL;
  690. /// LowerBound - local variable passed to runtime.
  691. Expr *LB;
  692. /// UpperBound - local variable passed to runtime.
  693. Expr *UB;
  694. /// Stride - local variable passed to runtime.
  695. Expr *ST;
  696. /// EnsureUpperBound -- expression UB = min(UB, NumIterations).
  697. Expr *EUB;
  698. /// Update of LowerBound for statically scheduled 'omp for' loops.
  699. Expr *NLB;
  700. /// Update of UpperBound for statically scheduled 'omp for' loops.
  701. Expr *NUB;
  702. /// PreviousLowerBound - local variable passed to runtime in the
  703. /// enclosing schedule or null if that does not apply.
  704. Expr *PrevLB;
  705. /// PreviousUpperBound - local variable passed to runtime in the
  706. /// enclosing schedule or null if that does not apply.
  707. Expr *PrevUB;
  708. /// DistInc - increment expression for distribute loop when found
  709. /// combined with a further loop level (e.g. in 'distribute parallel for')
  710. /// expression IV = IV + ST
  711. Expr *DistInc;
  712. /// PrevEUB - expression similar to EUB but to be used when loop
  713. /// scheduling uses PrevLB and PrevUB (e.g. in 'distribute parallel for'
  714. /// when ensuring that the UB is either the calculated UB by the runtime or
  715. /// the end of the assigned distribute chunk)
  716. /// expression UB = min (UB, PrevUB)
  717. Expr *PrevEUB;
  718. /// Counters Loop counters.
  719. SmallVector<Expr *, 4> Counters;
  720. /// PrivateCounters Loop counters.
  721. SmallVector<Expr *, 4> PrivateCounters;
  722. /// Expressions for loop counters inits for CodeGen.
  723. SmallVector<Expr *, 4> Inits;
  724. /// Expressions for loop counters update for CodeGen.
  725. SmallVector<Expr *, 4> Updates;
  726. /// Final loop counter values for GodeGen.
  727. SmallVector<Expr *, 4> Finals;
  728. /// List of counters required for the generation of the non-rectangular
  729. /// loops.
  730. SmallVector<Expr *, 4> DependentCounters;
  731. /// List of initializers required for the generation of the non-rectangular
  732. /// loops.
  733. SmallVector<Expr *, 4> DependentInits;
  734. /// List of final conditions required for the generation of the
  735. /// non-rectangular loops.
  736. SmallVector<Expr *, 4> FinalsConditions;
  737. /// Init statement for all captured expressions.
  738. Stmt *PreInits;
  739. /// Expressions used when combining OpenMP loop pragmas
  740. DistCombinedHelperExprs DistCombinedFields;
  741. /// Check if all the expressions are built (does not check the
  742. /// worksharing ones).
  743. bool builtAll() {
  744. return IterationVarRef != nullptr && LastIteration != nullptr &&
  745. NumIterations != nullptr && PreCond != nullptr &&
  746. Cond != nullptr && Init != nullptr && Inc != nullptr;
  747. }
  748. /// Initialize all the fields to null.
  749. /// \param Size Number of elements in the
  750. /// counters/finals/updates/dependent_counters/dependent_inits/finals_conditions
  751. /// arrays.
  752. void clear(unsigned Size) {
  753. IterationVarRef = nullptr;
  754. LastIteration = nullptr;
  755. CalcLastIteration = nullptr;
  756. PreCond = nullptr;
  757. Cond = nullptr;
  758. Init = nullptr;
  759. Inc = nullptr;
  760. IL = nullptr;
  761. LB = nullptr;
  762. UB = nullptr;
  763. ST = nullptr;
  764. EUB = nullptr;
  765. NLB = nullptr;
  766. NUB = nullptr;
  767. NumIterations = nullptr;
  768. PrevLB = nullptr;
  769. PrevUB = nullptr;
  770. DistInc = nullptr;
  771. PrevEUB = nullptr;
  772. Counters.resize(Size);
  773. PrivateCounters.resize(Size);
  774. Inits.resize(Size);
  775. Updates.resize(Size);
  776. Finals.resize(Size);
  777. DependentCounters.resize(Size);
  778. DependentInits.resize(Size);
  779. FinalsConditions.resize(Size);
  780. for (unsigned I = 0; I < Size; ++I) {
  781. Counters[I] = nullptr;
  782. PrivateCounters[I] = nullptr;
  783. Inits[I] = nullptr;
  784. Updates[I] = nullptr;
  785. Finals[I] = nullptr;
  786. DependentCounters[I] = nullptr;
  787. DependentInits[I] = nullptr;
  788. FinalsConditions[I] = nullptr;
  789. }
  790. PreInits = nullptr;
  791. DistCombinedFields.LB = nullptr;
  792. DistCombinedFields.UB = nullptr;
  793. DistCombinedFields.EUB = nullptr;
  794. DistCombinedFields.Init = nullptr;
  795. DistCombinedFields.Cond = nullptr;
  796. DistCombinedFields.NLB = nullptr;
  797. DistCombinedFields.NUB = nullptr;
  798. DistCombinedFields.DistCond = nullptr;
  799. DistCombinedFields.ParForInDistCond = nullptr;
  800. }
  801. };
  802. /// Get number of collapsed loops.
  803. unsigned getLoopsNumber() const { return NumAssociatedLoops; }
  804. /// Try to find the next loop sub-statement in the specified statement \p
  805. /// CurStmt.
  806. /// \param TryImperfectlyNestedLoops true, if we need to try to look for the
  807. /// imperfectly nested loop.
  808. static Stmt *tryToFindNextInnerLoop(Stmt *CurStmt,
  809. bool TryImperfectlyNestedLoops);
  810. static const Stmt *tryToFindNextInnerLoop(const Stmt *CurStmt,
  811. bool TryImperfectlyNestedLoops) {
  812. return tryToFindNextInnerLoop(const_cast<Stmt *>(CurStmt),
  813. TryImperfectlyNestedLoops);
  814. }
  815. /// Calls the specified callback function for all the loops in \p CurStmt,
  816. /// from the outermost to the innermost.
  817. static bool
  818. doForAllLoops(Stmt *CurStmt, bool TryImperfectlyNestedLoops,
  819. unsigned NumLoops,
  820. llvm::function_ref<bool(unsigned, Stmt *)> Callback,
  821. llvm::function_ref<void(OMPLoopTransformationDirective *)>
  822. OnTransformationCallback);
  823. static bool
  824. doForAllLoops(const Stmt *CurStmt, bool TryImperfectlyNestedLoops,
  825. unsigned NumLoops,
  826. llvm::function_ref<bool(unsigned, const Stmt *)> Callback,
  827. llvm::function_ref<void(const OMPLoopTransformationDirective *)>
  828. OnTransformationCallback) {
  829. auto &&NewCallback = [Callback](unsigned Cnt, Stmt *CurStmt) {
  830. return Callback(Cnt, CurStmt);
  831. };
  832. auto &&NewTransformCb =
  833. [OnTransformationCallback](OMPLoopTransformationDirective *A) {
  834. OnTransformationCallback(A);
  835. };
  836. return doForAllLoops(const_cast<Stmt *>(CurStmt), TryImperfectlyNestedLoops,
  837. NumLoops, NewCallback, NewTransformCb);
  838. }
  839. /// Calls the specified callback function for all the loops in \p CurStmt,
  840. /// from the outermost to the innermost.
  841. static bool
  842. doForAllLoops(Stmt *CurStmt, bool TryImperfectlyNestedLoops,
  843. unsigned NumLoops,
  844. llvm::function_ref<bool(unsigned, Stmt *)> Callback) {
  845. auto &&TransformCb = [](OMPLoopTransformationDirective *) {};
  846. return doForAllLoops(CurStmt, TryImperfectlyNestedLoops, NumLoops, Callback,
  847. TransformCb);
  848. }
  849. static bool
  850. doForAllLoops(const Stmt *CurStmt, bool TryImperfectlyNestedLoops,
  851. unsigned NumLoops,
  852. llvm::function_ref<bool(unsigned, const Stmt *)> Callback) {
  853. auto &&NewCallback = [Callback](unsigned Cnt, const Stmt *CurStmt) {
  854. return Callback(Cnt, CurStmt);
  855. };
  856. return doForAllLoops(const_cast<Stmt *>(CurStmt), TryImperfectlyNestedLoops,
  857. NumLoops, NewCallback);
  858. }
  859. /// Calls the specified callback function for all the loop bodies in \p
  860. /// CurStmt, from the outermost loop to the innermost.
  861. static void doForAllLoopsBodies(
  862. Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops,
  863. llvm::function_ref<void(unsigned, Stmt *, Stmt *)> Callback);
  864. static void doForAllLoopsBodies(
  865. const Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops,
  866. llvm::function_ref<void(unsigned, const Stmt *, const Stmt *)> Callback) {
  867. auto &&NewCallback = [Callback](unsigned Cnt, Stmt *Loop, Stmt *Body) {
  868. Callback(Cnt, Loop, Body);
  869. };
  870. doForAllLoopsBodies(const_cast<Stmt *>(CurStmt), TryImperfectlyNestedLoops,
  871. NumLoops, NewCallback);
  872. }
  873. static bool classof(const Stmt *T) {
  874. if (auto *D = dyn_cast<OMPExecutableDirective>(T))
  875. return isOpenMPLoopDirective(D->getDirectiveKind());
  876. return false;
  877. }
  878. };
  879. /// The base class for all loop transformation directives.
  880. class OMPLoopTransformationDirective : public OMPLoopBasedDirective {
  881. friend class ASTStmtReader;
  882. /// Number of loops generated by this loop transformation.
  883. unsigned NumGeneratedLoops = 0;
  884. protected:
  885. explicit OMPLoopTransformationDirective(StmtClass SC,
  886. OpenMPDirectiveKind Kind,
  887. SourceLocation StartLoc,
  888. SourceLocation EndLoc,
  889. unsigned NumAssociatedLoops)
  890. : OMPLoopBasedDirective(SC, Kind, StartLoc, EndLoc, NumAssociatedLoops) {}
  891. /// Set the number of loops generated by this loop transformation.
  892. void setNumGeneratedLoops(unsigned Num) { NumGeneratedLoops = Num; }
  893. public:
  894. /// Return the number of associated (consumed) loops.
  895. unsigned getNumAssociatedLoops() const { return getLoopsNumber(); }
  896. /// Return the number of loops generated by this loop transformation.
  897. unsigned getNumGeneratedLoops() { return NumGeneratedLoops; }
  898. /// Get the de-sugared statements after after the loop transformation.
  899. ///
  900. /// Might be nullptr if either the directive generates no loops and is handled
  901. /// directly in CodeGen, or resolving a template-dependence context is
  902. /// required.
  903. Stmt *getTransformedStmt() const;
  904. /// Return preinits statement.
  905. Stmt *getPreInits() const;
  906. static bool classof(const Stmt *T) {
  907. return T->getStmtClass() == OMPTileDirectiveClass ||
  908. T->getStmtClass() == OMPUnrollDirectiveClass;
  909. }
  910. };
  911. /// This is a common base class for loop directives ('omp simd', 'omp
  912. /// for', 'omp for simd' etc.). It is responsible for the loop code generation.
  913. ///
  914. class OMPLoopDirective : public OMPLoopBasedDirective {
  915. friend class ASTStmtReader;
  916. /// Offsets to the stored exprs.
  917. /// This enumeration contains offsets to all the pointers to children
  918. /// expressions stored in OMPLoopDirective.
  919. /// The first 9 children are necessary for all the loop directives,
  920. /// the next 8 are specific to the worksharing ones, and the next 11 are
  921. /// used for combined constructs containing two pragmas associated to loops.
  922. /// After the fixed children, three arrays of length NumAssociatedLoops are
  923. /// allocated: loop counters, their updates and final values.
  924. /// PrevLowerBound and PrevUpperBound are used to communicate blocking
  925. /// information in composite constructs which require loop blocking
  926. /// DistInc is used to generate the increment expression for the distribute
  927. /// loop when combined with a further nested loop
  928. /// PrevEnsureUpperBound is used as the EnsureUpperBound expression for the
  929. /// for loop when combined with a previous distribute loop in the same pragma
  930. /// (e.g. 'distribute parallel for')
  931. ///
  932. enum {
  933. IterationVariableOffset = 0,
  934. LastIterationOffset = 1,
  935. CalcLastIterationOffset = 2,
  936. PreConditionOffset = 3,
  937. CondOffset = 4,
  938. InitOffset = 5,
  939. IncOffset = 6,
  940. PreInitsOffset = 7,
  941. // The '...End' enumerators do not correspond to child expressions - they
  942. // specify the offset to the end (and start of the following counters/
  943. // updates/finals/dependent_counters/dependent_inits/finals_conditions
  944. // arrays).
  945. DefaultEnd = 8,
  946. // The following 8 exprs are used by worksharing and distribute loops only.
  947. IsLastIterVariableOffset = 8,
  948. LowerBoundVariableOffset = 9,
  949. UpperBoundVariableOffset = 10,
  950. StrideVariableOffset = 11,
  951. EnsureUpperBoundOffset = 12,
  952. NextLowerBoundOffset = 13,
  953. NextUpperBoundOffset = 14,
  954. NumIterationsOffset = 15,
  955. // Offset to the end for worksharing loop directives.
  956. WorksharingEnd = 16,
  957. PrevLowerBoundVariableOffset = 16,
  958. PrevUpperBoundVariableOffset = 17,
  959. DistIncOffset = 18,
  960. PrevEnsureUpperBoundOffset = 19,
  961. CombinedLowerBoundVariableOffset = 20,
  962. CombinedUpperBoundVariableOffset = 21,
  963. CombinedEnsureUpperBoundOffset = 22,
  964. CombinedInitOffset = 23,
  965. CombinedConditionOffset = 24,
  966. CombinedNextLowerBoundOffset = 25,
  967. CombinedNextUpperBoundOffset = 26,
  968. CombinedDistConditionOffset = 27,
  969. CombinedParForInDistConditionOffset = 28,
  970. // Offset to the end (and start of the following
  971. // counters/updates/finals/dependent_counters/dependent_inits/finals_conditions
  972. // arrays) for combined distribute loop directives.
  973. CombinedDistributeEnd = 29,
  974. };
  975. /// Get the counters storage.
  976. MutableArrayRef<Expr *> getCounters() {
  977. auto **Storage = reinterpret_cast<Expr **>(
  978. &Data->getChildren()[getArraysOffset(getDirectiveKind())]);
  979. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  980. }
  981. /// Get the private counters storage.
  982. MutableArrayRef<Expr *> getPrivateCounters() {
  983. auto **Storage = reinterpret_cast<Expr **>(
  984. &Data->getChildren()[getArraysOffset(getDirectiveKind()) +
  985. getLoopsNumber()]);
  986. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  987. }
  988. /// Get the updates storage.
  989. MutableArrayRef<Expr *> getInits() {
  990. auto **Storage = reinterpret_cast<Expr **>(
  991. &Data->getChildren()[getArraysOffset(getDirectiveKind()) +
  992. 2 * getLoopsNumber()]);
  993. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  994. }
  995. /// Get the updates storage.
  996. MutableArrayRef<Expr *> getUpdates() {
  997. auto **Storage = reinterpret_cast<Expr **>(
  998. &Data->getChildren()[getArraysOffset(getDirectiveKind()) +
  999. 3 * getLoopsNumber()]);
  1000. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  1001. }
  1002. /// Get the final counter updates storage.
  1003. MutableArrayRef<Expr *> getFinals() {
  1004. auto **Storage = reinterpret_cast<Expr **>(
  1005. &Data->getChildren()[getArraysOffset(getDirectiveKind()) +
  1006. 4 * getLoopsNumber()]);
  1007. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  1008. }
  1009. /// Get the dependent counters storage.
  1010. MutableArrayRef<Expr *> getDependentCounters() {
  1011. auto **Storage = reinterpret_cast<Expr **>(
  1012. &Data->getChildren()[getArraysOffset(getDirectiveKind()) +
  1013. 5 * getLoopsNumber()]);
  1014. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  1015. }
  1016. /// Get the dependent inits storage.
  1017. MutableArrayRef<Expr *> getDependentInits() {
  1018. auto **Storage = reinterpret_cast<Expr **>(
  1019. &Data->getChildren()[getArraysOffset(getDirectiveKind()) +
  1020. 6 * getLoopsNumber()]);
  1021. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  1022. }
  1023. /// Get the finals conditions storage.
  1024. MutableArrayRef<Expr *> getFinalsConditions() {
  1025. auto **Storage = reinterpret_cast<Expr **>(
  1026. &Data->getChildren()[getArraysOffset(getDirectiveKind()) +
  1027. 7 * getLoopsNumber()]);
  1028. return llvm::makeMutableArrayRef(Storage, getLoopsNumber());
  1029. }
  1030. protected:
  1031. /// Build instance of loop directive of class \a Kind.
  1032. ///
  1033. /// \param SC Statement class.
  1034. /// \param Kind Kind of OpenMP directive.
  1035. /// \param StartLoc Starting location of the directive (directive keyword).
  1036. /// \param EndLoc Ending location of the directive.
  1037. /// \param CollapsedNum Number of collapsed loops from 'collapse' clause.
  1038. ///
  1039. OMPLoopDirective(StmtClass SC, OpenMPDirectiveKind Kind,
  1040. SourceLocation StartLoc, SourceLocation EndLoc,
  1041. unsigned CollapsedNum)
  1042. : OMPLoopBasedDirective(SC, Kind, StartLoc, EndLoc, CollapsedNum) {}
  1043. /// Offset to the start of children expression arrays.
  1044. static unsigned getArraysOffset(OpenMPDirectiveKind Kind) {
  1045. if (isOpenMPLoopBoundSharingDirective(Kind))
  1046. return CombinedDistributeEnd;
  1047. if (isOpenMPWorksharingDirective(Kind) || isOpenMPTaskLoopDirective(Kind) ||
  1048. isOpenMPGenericLoopDirective(Kind) || isOpenMPDistributeDirective(Kind))
  1049. return WorksharingEnd;
  1050. return DefaultEnd;
  1051. }
  1052. /// Children number.
  1053. static unsigned numLoopChildren(unsigned CollapsedNum,
  1054. OpenMPDirectiveKind Kind) {
  1055. return getArraysOffset(Kind) +
  1056. 8 * CollapsedNum; // Counters, PrivateCounters, Inits,
  1057. // Updates, Finals, DependentCounters,
  1058. // DependentInits, FinalsConditions.
  1059. }
  1060. void setIterationVariable(Expr *IV) {
  1061. Data->getChildren()[IterationVariableOffset] = IV;
  1062. }
  1063. void setLastIteration(Expr *LI) {
  1064. Data->getChildren()[LastIterationOffset] = LI;
  1065. }
  1066. void setCalcLastIteration(Expr *CLI) {
  1067. Data->getChildren()[CalcLastIterationOffset] = CLI;
  1068. }
  1069. void setPreCond(Expr *PC) { Data->getChildren()[PreConditionOffset] = PC; }
  1070. void setCond(Expr *Cond) { Data->getChildren()[CondOffset] = Cond; }
  1071. void setInit(Expr *Init) { Data->getChildren()[InitOffset] = Init; }
  1072. void setInc(Expr *Inc) { Data->getChildren()[IncOffset] = Inc; }
  1073. void setPreInits(Stmt *PreInits) {
  1074. Data->getChildren()[PreInitsOffset] = PreInits;
  1075. }
  1076. void setIsLastIterVariable(Expr *IL) {
  1077. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1078. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1079. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1080. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1081. "expected worksharing loop directive");
  1082. Data->getChildren()[IsLastIterVariableOffset] = IL;
  1083. }
  1084. void setLowerBoundVariable(Expr *LB) {
  1085. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1086. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1087. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1088. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1089. "expected worksharing loop directive");
  1090. Data->getChildren()[LowerBoundVariableOffset] = LB;
  1091. }
  1092. void setUpperBoundVariable(Expr *UB) {
  1093. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1094. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1095. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1096. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1097. "expected worksharing loop directive");
  1098. Data->getChildren()[UpperBoundVariableOffset] = UB;
  1099. }
  1100. void setStrideVariable(Expr *ST) {
  1101. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1102. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1103. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1104. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1105. "expected worksharing loop directive");
  1106. Data->getChildren()[StrideVariableOffset] = ST;
  1107. }
  1108. void setEnsureUpperBound(Expr *EUB) {
  1109. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1110. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1111. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1112. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1113. "expected worksharing loop directive");
  1114. Data->getChildren()[EnsureUpperBoundOffset] = EUB;
  1115. }
  1116. void setNextLowerBound(Expr *NLB) {
  1117. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1118. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1119. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1120. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1121. "expected worksharing loop directive");
  1122. Data->getChildren()[NextLowerBoundOffset] = NLB;
  1123. }
  1124. void setNextUpperBound(Expr *NUB) {
  1125. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1126. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1127. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1128. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1129. "expected worksharing loop directive");
  1130. Data->getChildren()[NextUpperBoundOffset] = NUB;
  1131. }
  1132. void setNumIterations(Expr *NI) {
  1133. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1134. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1135. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1136. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1137. "expected worksharing loop directive");
  1138. Data->getChildren()[NumIterationsOffset] = NI;
  1139. }
  1140. void setPrevLowerBoundVariable(Expr *PrevLB) {
  1141. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1142. "expected loop bound sharing directive");
  1143. Data->getChildren()[PrevLowerBoundVariableOffset] = PrevLB;
  1144. }
  1145. void setPrevUpperBoundVariable(Expr *PrevUB) {
  1146. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1147. "expected loop bound sharing directive");
  1148. Data->getChildren()[PrevUpperBoundVariableOffset] = PrevUB;
  1149. }
  1150. void setDistInc(Expr *DistInc) {
  1151. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1152. "expected loop bound sharing directive");
  1153. Data->getChildren()[DistIncOffset] = DistInc;
  1154. }
  1155. void setPrevEnsureUpperBound(Expr *PrevEUB) {
  1156. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1157. "expected loop bound sharing directive");
  1158. Data->getChildren()[PrevEnsureUpperBoundOffset] = PrevEUB;
  1159. }
  1160. void setCombinedLowerBoundVariable(Expr *CombLB) {
  1161. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1162. "expected loop bound sharing directive");
  1163. Data->getChildren()[CombinedLowerBoundVariableOffset] = CombLB;
  1164. }
  1165. void setCombinedUpperBoundVariable(Expr *CombUB) {
  1166. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1167. "expected loop bound sharing directive");
  1168. Data->getChildren()[CombinedUpperBoundVariableOffset] = CombUB;
  1169. }
  1170. void setCombinedEnsureUpperBound(Expr *CombEUB) {
  1171. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1172. "expected loop bound sharing directive");
  1173. Data->getChildren()[CombinedEnsureUpperBoundOffset] = CombEUB;
  1174. }
  1175. void setCombinedInit(Expr *CombInit) {
  1176. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1177. "expected loop bound sharing directive");
  1178. Data->getChildren()[CombinedInitOffset] = CombInit;
  1179. }
  1180. void setCombinedCond(Expr *CombCond) {
  1181. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1182. "expected loop bound sharing directive");
  1183. Data->getChildren()[CombinedConditionOffset] = CombCond;
  1184. }
  1185. void setCombinedNextLowerBound(Expr *CombNLB) {
  1186. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1187. "expected loop bound sharing directive");
  1188. Data->getChildren()[CombinedNextLowerBoundOffset] = CombNLB;
  1189. }
  1190. void setCombinedNextUpperBound(Expr *CombNUB) {
  1191. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1192. "expected loop bound sharing directive");
  1193. Data->getChildren()[CombinedNextUpperBoundOffset] = CombNUB;
  1194. }
  1195. void setCombinedDistCond(Expr *CombDistCond) {
  1196. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1197. "expected loop bound distribute sharing directive");
  1198. Data->getChildren()[CombinedDistConditionOffset] = CombDistCond;
  1199. }
  1200. void setCombinedParForInDistCond(Expr *CombParForInDistCond) {
  1201. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1202. "expected loop bound distribute sharing directive");
  1203. Data->getChildren()[CombinedParForInDistConditionOffset] =
  1204. CombParForInDistCond;
  1205. }
  1206. void setCounters(ArrayRef<Expr *> A);
  1207. void setPrivateCounters(ArrayRef<Expr *> A);
  1208. void setInits(ArrayRef<Expr *> A);
  1209. void setUpdates(ArrayRef<Expr *> A);
  1210. void setFinals(ArrayRef<Expr *> A);
  1211. void setDependentCounters(ArrayRef<Expr *> A);
  1212. void setDependentInits(ArrayRef<Expr *> A);
  1213. void setFinalsConditions(ArrayRef<Expr *> A);
  1214. public:
  1215. Expr *getIterationVariable() const {
  1216. return cast<Expr>(Data->getChildren()[IterationVariableOffset]);
  1217. }
  1218. Expr *getLastIteration() const {
  1219. return cast<Expr>(Data->getChildren()[LastIterationOffset]);
  1220. }
  1221. Expr *getCalcLastIteration() const {
  1222. return cast<Expr>(Data->getChildren()[CalcLastIterationOffset]);
  1223. }
  1224. Expr *getPreCond() const {
  1225. return cast<Expr>(Data->getChildren()[PreConditionOffset]);
  1226. }
  1227. Expr *getCond() const { return cast<Expr>(Data->getChildren()[CondOffset]); }
  1228. Expr *getInit() const { return cast<Expr>(Data->getChildren()[InitOffset]); }
  1229. Expr *getInc() const { return cast<Expr>(Data->getChildren()[IncOffset]); }
  1230. const Stmt *getPreInits() const {
  1231. return Data->getChildren()[PreInitsOffset];
  1232. }
  1233. Stmt *getPreInits() { return Data->getChildren()[PreInitsOffset]; }
  1234. Expr *getIsLastIterVariable() const {
  1235. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1236. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1237. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1238. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1239. "expected worksharing loop directive");
  1240. return cast<Expr>(Data->getChildren()[IsLastIterVariableOffset]);
  1241. }
  1242. Expr *getLowerBoundVariable() const {
  1243. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1244. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1245. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1246. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1247. "expected worksharing loop directive");
  1248. return cast<Expr>(Data->getChildren()[LowerBoundVariableOffset]);
  1249. }
  1250. Expr *getUpperBoundVariable() const {
  1251. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1252. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1253. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1254. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1255. "expected worksharing loop directive");
  1256. return cast<Expr>(Data->getChildren()[UpperBoundVariableOffset]);
  1257. }
  1258. Expr *getStrideVariable() const {
  1259. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1260. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1261. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1262. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1263. "expected worksharing loop directive");
  1264. return cast<Expr>(Data->getChildren()[StrideVariableOffset]);
  1265. }
  1266. Expr *getEnsureUpperBound() const {
  1267. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1268. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1269. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1270. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1271. "expected worksharing loop directive");
  1272. return cast<Expr>(Data->getChildren()[EnsureUpperBoundOffset]);
  1273. }
  1274. Expr *getNextLowerBound() const {
  1275. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1276. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1277. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1278. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1279. "expected worksharing loop directive");
  1280. return cast<Expr>(Data->getChildren()[NextLowerBoundOffset]);
  1281. }
  1282. Expr *getNextUpperBound() const {
  1283. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1284. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1285. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1286. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1287. "expected worksharing loop directive");
  1288. return cast<Expr>(Data->getChildren()[NextUpperBoundOffset]);
  1289. }
  1290. Expr *getNumIterations() const {
  1291. assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
  1292. isOpenMPGenericLoopDirective(getDirectiveKind()) ||
  1293. isOpenMPTaskLoopDirective(getDirectiveKind()) ||
  1294. isOpenMPDistributeDirective(getDirectiveKind())) &&
  1295. "expected worksharing loop directive");
  1296. return cast<Expr>(Data->getChildren()[NumIterationsOffset]);
  1297. }
  1298. Expr *getPrevLowerBoundVariable() const {
  1299. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1300. "expected loop bound sharing directive");
  1301. return cast<Expr>(Data->getChildren()[PrevLowerBoundVariableOffset]);
  1302. }
  1303. Expr *getPrevUpperBoundVariable() const {
  1304. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1305. "expected loop bound sharing directive");
  1306. return cast<Expr>(Data->getChildren()[PrevUpperBoundVariableOffset]);
  1307. }
  1308. Expr *getDistInc() const {
  1309. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1310. "expected loop bound sharing directive");
  1311. return cast<Expr>(Data->getChildren()[DistIncOffset]);
  1312. }
  1313. Expr *getPrevEnsureUpperBound() const {
  1314. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1315. "expected loop bound sharing directive");
  1316. return cast<Expr>(Data->getChildren()[PrevEnsureUpperBoundOffset]);
  1317. }
  1318. Expr *getCombinedLowerBoundVariable() const {
  1319. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1320. "expected loop bound sharing directive");
  1321. return cast<Expr>(Data->getChildren()[CombinedLowerBoundVariableOffset]);
  1322. }
  1323. Expr *getCombinedUpperBoundVariable() const {
  1324. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1325. "expected loop bound sharing directive");
  1326. return cast<Expr>(Data->getChildren()[CombinedUpperBoundVariableOffset]);
  1327. }
  1328. Expr *getCombinedEnsureUpperBound() const {
  1329. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1330. "expected loop bound sharing directive");
  1331. return cast<Expr>(Data->getChildren()[CombinedEnsureUpperBoundOffset]);
  1332. }
  1333. Expr *getCombinedInit() const {
  1334. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1335. "expected loop bound sharing directive");
  1336. return cast<Expr>(Data->getChildren()[CombinedInitOffset]);
  1337. }
  1338. Expr *getCombinedCond() const {
  1339. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1340. "expected loop bound sharing directive");
  1341. return cast<Expr>(Data->getChildren()[CombinedConditionOffset]);
  1342. }
  1343. Expr *getCombinedNextLowerBound() const {
  1344. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1345. "expected loop bound sharing directive");
  1346. return cast<Expr>(Data->getChildren()[CombinedNextLowerBoundOffset]);
  1347. }
  1348. Expr *getCombinedNextUpperBound() const {
  1349. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1350. "expected loop bound sharing directive");
  1351. return cast<Expr>(Data->getChildren()[CombinedNextUpperBoundOffset]);
  1352. }
  1353. Expr *getCombinedDistCond() const {
  1354. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1355. "expected loop bound distribute sharing directive");
  1356. return cast<Expr>(Data->getChildren()[CombinedDistConditionOffset]);
  1357. }
  1358. Expr *getCombinedParForInDistCond() const {
  1359. assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) &&
  1360. "expected loop bound distribute sharing directive");
  1361. return cast<Expr>(Data->getChildren()[CombinedParForInDistConditionOffset]);
  1362. }
  1363. Stmt *getBody();
  1364. const Stmt *getBody() const {
  1365. return const_cast<OMPLoopDirective *>(this)->getBody();
  1366. }
  1367. ArrayRef<Expr *> counters() { return getCounters(); }
  1368. ArrayRef<Expr *> counters() const {
  1369. return const_cast<OMPLoopDirective *>(this)->getCounters();
  1370. }
  1371. ArrayRef<Expr *> private_counters() { return getPrivateCounters(); }
  1372. ArrayRef<Expr *> private_counters() const {
  1373. return const_cast<OMPLoopDirective *>(this)->getPrivateCounters();
  1374. }
  1375. ArrayRef<Expr *> inits() { return getInits(); }
  1376. ArrayRef<Expr *> inits() const {
  1377. return const_cast<OMPLoopDirective *>(this)->getInits();
  1378. }
  1379. ArrayRef<Expr *> updates() { return getUpdates(); }
  1380. ArrayRef<Expr *> updates() const {
  1381. return const_cast<OMPLoopDirective *>(this)->getUpdates();
  1382. }
  1383. ArrayRef<Expr *> finals() { return getFinals(); }
  1384. ArrayRef<Expr *> finals() const {
  1385. return const_cast<OMPLoopDirective *>(this)->getFinals();
  1386. }
  1387. ArrayRef<Expr *> dependent_counters() { return getDependentCounters(); }
  1388. ArrayRef<Expr *> dependent_counters() const {
  1389. return const_cast<OMPLoopDirective *>(this)->getDependentCounters();
  1390. }
  1391. ArrayRef<Expr *> dependent_inits() { return getDependentInits(); }
  1392. ArrayRef<Expr *> dependent_inits() const {
  1393. return const_cast<OMPLoopDirective *>(this)->getDependentInits();
  1394. }
  1395. ArrayRef<Expr *> finals_conditions() { return getFinalsConditions(); }
  1396. ArrayRef<Expr *> finals_conditions() const {
  1397. return const_cast<OMPLoopDirective *>(this)->getFinalsConditions();
  1398. }
  1399. static bool classof(const Stmt *T) {
  1400. return T->getStmtClass() == OMPSimdDirectiveClass ||
  1401. T->getStmtClass() == OMPForDirectiveClass ||
  1402. T->getStmtClass() == OMPForSimdDirectiveClass ||
  1403. T->getStmtClass() == OMPParallelForDirectiveClass ||
  1404. T->getStmtClass() == OMPParallelForSimdDirectiveClass ||
  1405. T->getStmtClass() == OMPTaskLoopDirectiveClass ||
  1406. T->getStmtClass() == OMPTaskLoopSimdDirectiveClass ||
  1407. T->getStmtClass() == OMPMasterTaskLoopDirectiveClass ||
  1408. T->getStmtClass() == OMPMasterTaskLoopSimdDirectiveClass ||
  1409. T->getStmtClass() == OMPGenericLoopDirectiveClass ||
  1410. T->getStmtClass() == OMPParallelMasterTaskLoopDirectiveClass ||
  1411. T->getStmtClass() == OMPParallelMasterTaskLoopSimdDirectiveClass ||
  1412. T->getStmtClass() == OMPDistributeDirectiveClass ||
  1413. T->getStmtClass() == OMPTargetParallelForDirectiveClass ||
  1414. T->getStmtClass() == OMPDistributeParallelForDirectiveClass ||
  1415. T->getStmtClass() == OMPDistributeParallelForSimdDirectiveClass ||
  1416. T->getStmtClass() == OMPDistributeSimdDirectiveClass ||
  1417. T->getStmtClass() == OMPTargetParallelForSimdDirectiveClass ||
  1418. T->getStmtClass() == OMPTargetSimdDirectiveClass ||
  1419. T->getStmtClass() == OMPTeamsDistributeDirectiveClass ||
  1420. T->getStmtClass() == OMPTeamsDistributeSimdDirectiveClass ||
  1421. T->getStmtClass() ==
  1422. OMPTeamsDistributeParallelForSimdDirectiveClass ||
  1423. T->getStmtClass() == OMPTeamsDistributeParallelForDirectiveClass ||
  1424. T->getStmtClass() ==
  1425. OMPTargetTeamsDistributeParallelForDirectiveClass ||
  1426. T->getStmtClass() ==
  1427. OMPTargetTeamsDistributeParallelForSimdDirectiveClass ||
  1428. T->getStmtClass() == OMPTargetTeamsDistributeDirectiveClass ||
  1429. T->getStmtClass() == OMPTargetTeamsDistributeSimdDirectiveClass;
  1430. }
  1431. };
  1432. /// This represents '#pragma omp simd' directive.
  1433. ///
  1434. /// \code
  1435. /// #pragma omp simd private(a,b) linear(i,j:s) reduction(+:c,d)
  1436. /// \endcode
  1437. /// In this example directive '#pragma omp simd' has clauses 'private'
  1438. /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and
  1439. /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'.
  1440. ///
  1441. class OMPSimdDirective : public OMPLoopDirective {
  1442. friend class ASTStmtReader;
  1443. friend class OMPExecutableDirective;
  1444. /// Build directive with the given start and end location.
  1445. ///
  1446. /// \param StartLoc Starting location of the directive kind.
  1447. /// \param EndLoc Ending location of the directive.
  1448. /// \param CollapsedNum Number of collapsed nested loops.
  1449. ///
  1450. OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  1451. unsigned CollapsedNum)
  1452. : OMPLoopDirective(OMPSimdDirectiveClass, llvm::omp::OMPD_simd, StartLoc,
  1453. EndLoc, CollapsedNum) {}
  1454. /// Build an empty directive.
  1455. ///
  1456. /// \param CollapsedNum Number of collapsed nested loops.
  1457. ///
  1458. explicit OMPSimdDirective(unsigned CollapsedNum)
  1459. : OMPLoopDirective(OMPSimdDirectiveClass, llvm::omp::OMPD_simd,
  1460. SourceLocation(), SourceLocation(), CollapsedNum) {}
  1461. public:
  1462. /// Creates directive with a list of \a Clauses.
  1463. ///
  1464. /// \param C AST context.
  1465. /// \param StartLoc Starting location of the directive kind.
  1466. /// \param EndLoc Ending Location of the directive.
  1467. /// \param CollapsedNum Number of collapsed loops.
  1468. /// \param Clauses List of clauses.
  1469. /// \param AssociatedStmt Statement, associated with the directive.
  1470. /// \param Exprs Helper expressions for CodeGen.
  1471. ///
  1472. static OMPSimdDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  1473. SourceLocation EndLoc, unsigned CollapsedNum,
  1474. ArrayRef<OMPClause *> Clauses,
  1475. Stmt *AssociatedStmt,
  1476. const HelperExprs &Exprs);
  1477. /// Creates an empty directive with the place
  1478. /// for \a NumClauses clauses.
  1479. ///
  1480. /// \param C AST context.
  1481. /// \param CollapsedNum Number of collapsed nested loops.
  1482. /// \param NumClauses Number of clauses.
  1483. ///
  1484. static OMPSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
  1485. unsigned CollapsedNum, EmptyShell);
  1486. static bool classof(const Stmt *T) {
  1487. return T->getStmtClass() == OMPSimdDirectiveClass;
  1488. }
  1489. };
  1490. /// This represents '#pragma omp for' directive.
  1491. ///
  1492. /// \code
  1493. /// #pragma omp for private(a,b) reduction(+:c,d)
  1494. /// \endcode
  1495. /// In this example directive '#pragma omp for' has clauses 'private' with the
  1496. /// variables 'a' and 'b' and 'reduction' with operator '+' and variables 'c'
  1497. /// and 'd'.
  1498. ///
  1499. class OMPForDirective : public OMPLoopDirective {
  1500. friend class ASTStmtReader;
  1501. friend class OMPExecutableDirective;
  1502. /// true if current directive has inner cancel directive.
  1503. bool HasCancel = false;
  1504. /// Build directive with the given start and end location.
  1505. ///
  1506. /// \param StartLoc Starting location of the directive kind.
  1507. /// \param EndLoc Ending location of the directive.
  1508. /// \param CollapsedNum Number of collapsed nested loops.
  1509. ///
  1510. OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  1511. unsigned CollapsedNum)
  1512. : OMPLoopDirective(OMPForDirectiveClass, llvm::omp::OMPD_for, StartLoc,
  1513. EndLoc, CollapsedNum) {}
  1514. /// Build an empty directive.
  1515. ///
  1516. /// \param CollapsedNum Number of collapsed nested loops.
  1517. ///
  1518. explicit OMPForDirective(unsigned CollapsedNum)
  1519. : OMPLoopDirective(OMPForDirectiveClass, llvm::omp::OMPD_for,
  1520. SourceLocation(), SourceLocation(), CollapsedNum) {}
  1521. /// Sets special task reduction descriptor.
  1522. void setTaskReductionRefExpr(Expr *E) {
  1523. Data->getChildren()[numLoopChildren(getLoopsNumber(),
  1524. llvm::omp::OMPD_for)] = E;
  1525. }
  1526. /// Set cancel state.
  1527. void setHasCancel(bool Has) { HasCancel = Has; }
  1528. public:
  1529. /// Creates directive with a list of \a Clauses.
  1530. ///
  1531. /// \param C AST context.
  1532. /// \param StartLoc Starting location of the directive kind.
  1533. /// \param EndLoc Ending Location of the directive.
  1534. /// \param CollapsedNum Number of collapsed loops.
  1535. /// \param Clauses List of clauses.
  1536. /// \param AssociatedStmt Statement, associated with the directive.
  1537. /// \param Exprs Helper expressions for CodeGen.
  1538. /// \param TaskRedRef Task reduction special reference expression to handle
  1539. /// taskgroup descriptor.
  1540. /// \param HasCancel true if current directive has inner cancel directive.
  1541. ///
  1542. static OMPForDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  1543. SourceLocation EndLoc, unsigned CollapsedNum,
  1544. ArrayRef<OMPClause *> Clauses,
  1545. Stmt *AssociatedStmt, const HelperExprs &Exprs,
  1546. Expr *TaskRedRef, bool HasCancel);
  1547. /// Creates an empty directive with the place
  1548. /// for \a NumClauses clauses.
  1549. ///
  1550. /// \param C AST context.
  1551. /// \param CollapsedNum Number of collapsed nested loops.
  1552. /// \param NumClauses Number of clauses.
  1553. ///
  1554. static OMPForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
  1555. unsigned CollapsedNum, EmptyShell);
  1556. /// Returns special task reduction reference expression.
  1557. Expr *getTaskReductionRefExpr() {
  1558. return cast_or_null<Expr>(Data->getChildren()[numLoopChildren(
  1559. getLoopsNumber(), llvm::omp::OMPD_for)]);
  1560. }
  1561. const Expr *getTaskReductionRefExpr() const {
  1562. return const_cast<OMPForDirective *>(this)->getTaskReductionRefExpr();
  1563. }
  1564. /// Return true if current directive has inner cancel directive.
  1565. bool hasCancel() const { return HasCancel; }
  1566. static bool classof(const Stmt *T) {
  1567. return T->getStmtClass() == OMPForDirectiveClass;
  1568. }
  1569. };
  1570. /// This represents '#pragma omp for simd' directive.
  1571. ///
  1572. /// \code
  1573. /// #pragma omp for simd private(a,b) linear(i,j:s) reduction(+:c,d)
  1574. /// \endcode
  1575. /// In this example directive '#pragma omp for simd' has clauses 'private'
  1576. /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and
  1577. /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'.
  1578. ///
  1579. class OMPForSimdDirective : public OMPLoopDirective {
  1580. friend class ASTStmtReader;
  1581. friend class OMPExecutableDirective;
  1582. /// Build directive with the given start and end location.
  1583. ///
  1584. /// \param StartLoc Starting location of the directive kind.
  1585. /// \param EndLoc Ending location of the directive.
  1586. /// \param CollapsedNum Number of collapsed nested loops.
  1587. ///
  1588. OMPForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  1589. unsigned CollapsedNum)
  1590. : OMPLoopDirective(OMPForSimdDirectiveClass, llvm::omp::OMPD_for_simd,
  1591. StartLoc, EndLoc, CollapsedNum) {}
  1592. /// Build an empty directive.
  1593. ///
  1594. /// \param CollapsedNum Number of collapsed nested loops.
  1595. ///
  1596. explicit OMPForSimdDirective(unsigned CollapsedNum)
  1597. : OMPLoopDirective(OMPForSimdDirectiveClass, llvm::omp::OMPD_for_simd,
  1598. SourceLocation(), SourceLocation(), CollapsedNum) {}
  1599. public:
  1600. /// Creates directive with a list of \a Clauses.
  1601. ///
  1602. /// \param C AST context.
  1603. /// \param StartLoc Starting location of the directive kind.
  1604. /// \param EndLoc Ending Location of the directive.
  1605. /// \param CollapsedNum Number of collapsed loops.
  1606. /// \param Clauses List of clauses.
  1607. /// \param AssociatedStmt Statement, associated with the directive.
  1608. /// \param Exprs Helper expressions for CodeGen.
  1609. ///
  1610. static OMPForSimdDirective *
  1611. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  1612. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  1613. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  1614. /// Creates an empty directive with the place
  1615. /// for \a NumClauses clauses.
  1616. ///
  1617. /// \param C AST context.
  1618. /// \param CollapsedNum Number of collapsed nested loops.
  1619. /// \param NumClauses Number of clauses.
  1620. ///
  1621. static OMPForSimdDirective *CreateEmpty(const ASTContext &C,
  1622. unsigned NumClauses,
  1623. unsigned CollapsedNum, EmptyShell);
  1624. static bool classof(const Stmt *T) {
  1625. return T->getStmtClass() == OMPForSimdDirectiveClass;
  1626. }
  1627. };
  1628. /// This represents '#pragma omp sections' directive.
  1629. ///
  1630. /// \code
  1631. /// #pragma omp sections private(a,b) reduction(+:c,d)
  1632. /// \endcode
  1633. /// In this example directive '#pragma omp sections' has clauses 'private' with
  1634. /// the variables 'a' and 'b' and 'reduction' with operator '+' and variables
  1635. /// 'c' and 'd'.
  1636. ///
  1637. class OMPSectionsDirective : public OMPExecutableDirective {
  1638. friend class ASTStmtReader;
  1639. friend class OMPExecutableDirective;
  1640. /// true if current directive has inner cancel directive.
  1641. bool HasCancel = false;
  1642. /// Build directive with the given start and end location.
  1643. ///
  1644. /// \param StartLoc Starting location of the directive kind.
  1645. /// \param EndLoc Ending location of the directive.
  1646. ///
  1647. OMPSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  1648. : OMPExecutableDirective(OMPSectionsDirectiveClass,
  1649. llvm::omp::OMPD_sections, StartLoc, EndLoc) {}
  1650. /// Build an empty directive.
  1651. ///
  1652. explicit OMPSectionsDirective()
  1653. : OMPExecutableDirective(OMPSectionsDirectiveClass,
  1654. llvm::omp::OMPD_sections, SourceLocation(),
  1655. SourceLocation()) {}
  1656. /// Sets special task reduction descriptor.
  1657. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; }
  1658. /// Set cancel state.
  1659. void setHasCancel(bool Has) { HasCancel = Has; }
  1660. public:
  1661. /// Creates directive with a list of \a Clauses.
  1662. ///
  1663. /// \param C AST context.
  1664. /// \param StartLoc Starting location of the directive kind.
  1665. /// \param EndLoc Ending Location of the directive.
  1666. /// \param Clauses List of clauses.
  1667. /// \param AssociatedStmt Statement, associated with the directive.
  1668. /// \param TaskRedRef Task reduction special reference expression to handle
  1669. /// taskgroup descriptor.
  1670. /// \param HasCancel true if current directive has inner directive.
  1671. ///
  1672. static OMPSectionsDirective *
  1673. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  1674. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef,
  1675. bool HasCancel);
  1676. /// Creates an empty directive with the place for \a NumClauses
  1677. /// clauses.
  1678. ///
  1679. /// \param C AST context.
  1680. /// \param NumClauses Number of clauses.
  1681. ///
  1682. static OMPSectionsDirective *CreateEmpty(const ASTContext &C,
  1683. unsigned NumClauses, EmptyShell);
  1684. /// Returns special task reduction reference expression.
  1685. Expr *getTaskReductionRefExpr() {
  1686. return cast_or_null<Expr>(Data->getChildren()[0]);
  1687. }
  1688. const Expr *getTaskReductionRefExpr() const {
  1689. return const_cast<OMPSectionsDirective *>(this)->getTaskReductionRefExpr();
  1690. }
  1691. /// Return true if current directive has inner cancel directive.
  1692. bool hasCancel() const { return HasCancel; }
  1693. static bool classof(const Stmt *T) {
  1694. return T->getStmtClass() == OMPSectionsDirectiveClass;
  1695. }
  1696. };
  1697. /// This represents '#pragma omp section' directive.
  1698. ///
  1699. /// \code
  1700. /// #pragma omp section
  1701. /// \endcode
  1702. ///
  1703. class OMPSectionDirective : public OMPExecutableDirective {
  1704. friend class ASTStmtReader;
  1705. friend class OMPExecutableDirective;
  1706. /// true if current directive has inner cancel directive.
  1707. bool HasCancel = false;
  1708. /// Build directive with the given start and end location.
  1709. ///
  1710. /// \param StartLoc Starting location of the directive kind.
  1711. /// \param EndLoc Ending location of the directive.
  1712. ///
  1713. OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  1714. : OMPExecutableDirective(OMPSectionDirectiveClass,
  1715. llvm::omp::OMPD_section, StartLoc, EndLoc) {}
  1716. /// Build an empty directive.
  1717. ///
  1718. explicit OMPSectionDirective()
  1719. : OMPExecutableDirective(OMPSectionDirectiveClass,
  1720. llvm::omp::OMPD_section, SourceLocation(),
  1721. SourceLocation()) {}
  1722. public:
  1723. /// Creates directive.
  1724. ///
  1725. /// \param C AST context.
  1726. /// \param StartLoc Starting location of the directive kind.
  1727. /// \param EndLoc Ending Location of the directive.
  1728. /// \param AssociatedStmt Statement, associated with the directive.
  1729. /// \param HasCancel true if current directive has inner directive.
  1730. ///
  1731. static OMPSectionDirective *Create(const ASTContext &C,
  1732. SourceLocation StartLoc,
  1733. SourceLocation EndLoc,
  1734. Stmt *AssociatedStmt, bool HasCancel);
  1735. /// Creates an empty directive.
  1736. ///
  1737. /// \param C AST context.
  1738. ///
  1739. static OMPSectionDirective *CreateEmpty(const ASTContext &C, EmptyShell);
  1740. /// Set cancel state.
  1741. void setHasCancel(bool Has) { HasCancel = Has; }
  1742. /// Return true if current directive has inner cancel directive.
  1743. bool hasCancel() const { return HasCancel; }
  1744. static bool classof(const Stmt *T) {
  1745. return T->getStmtClass() == OMPSectionDirectiveClass;
  1746. }
  1747. };
  1748. /// This represents '#pragma omp single' directive.
  1749. ///
  1750. /// \code
  1751. /// #pragma omp single private(a,b) copyprivate(c,d)
  1752. /// \endcode
  1753. /// In this example directive '#pragma omp single' has clauses 'private' with
  1754. /// the variables 'a' and 'b' and 'copyprivate' with variables 'c' and 'd'.
  1755. ///
  1756. class OMPSingleDirective : public OMPExecutableDirective {
  1757. friend class ASTStmtReader;
  1758. friend class OMPExecutableDirective;
  1759. /// Build directive with the given start and end location.
  1760. ///
  1761. /// \param StartLoc Starting location of the directive kind.
  1762. /// \param EndLoc Ending location of the directive.
  1763. ///
  1764. OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  1765. : OMPExecutableDirective(OMPSingleDirectiveClass, llvm::omp::OMPD_single,
  1766. StartLoc, EndLoc) {}
  1767. /// Build an empty directive.
  1768. ///
  1769. explicit OMPSingleDirective()
  1770. : OMPExecutableDirective(OMPSingleDirectiveClass, llvm::omp::OMPD_single,
  1771. SourceLocation(), SourceLocation()) {}
  1772. public:
  1773. /// Creates directive with a list of \a Clauses.
  1774. ///
  1775. /// \param C AST context.
  1776. /// \param StartLoc Starting location of the directive kind.
  1777. /// \param EndLoc Ending Location of the directive.
  1778. /// \param Clauses List of clauses.
  1779. /// \param AssociatedStmt Statement, associated with the directive.
  1780. ///
  1781. static OMPSingleDirective *
  1782. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  1783. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  1784. /// Creates an empty directive with the place for \a NumClauses
  1785. /// clauses.
  1786. ///
  1787. /// \param C AST context.
  1788. /// \param NumClauses Number of clauses.
  1789. ///
  1790. static OMPSingleDirective *CreateEmpty(const ASTContext &C,
  1791. unsigned NumClauses, EmptyShell);
  1792. static bool classof(const Stmt *T) {
  1793. return T->getStmtClass() == OMPSingleDirectiveClass;
  1794. }
  1795. };
  1796. /// This represents '#pragma omp master' directive.
  1797. ///
  1798. /// \code
  1799. /// #pragma omp master
  1800. /// \endcode
  1801. ///
  1802. class OMPMasterDirective : public OMPExecutableDirective {
  1803. friend class ASTStmtReader;
  1804. friend class OMPExecutableDirective;
  1805. /// Build directive with the given start and end location.
  1806. ///
  1807. /// \param StartLoc Starting location of the directive kind.
  1808. /// \param EndLoc Ending location of the directive.
  1809. ///
  1810. OMPMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  1811. : OMPExecutableDirective(OMPMasterDirectiveClass, llvm::omp::OMPD_master,
  1812. StartLoc, EndLoc) {}
  1813. /// Build an empty directive.
  1814. ///
  1815. explicit OMPMasterDirective()
  1816. : OMPExecutableDirective(OMPMasterDirectiveClass, llvm::omp::OMPD_master,
  1817. SourceLocation(), SourceLocation()) {}
  1818. public:
  1819. /// Creates directive.
  1820. ///
  1821. /// \param C AST context.
  1822. /// \param StartLoc Starting location of the directive kind.
  1823. /// \param EndLoc Ending Location of the directive.
  1824. /// \param AssociatedStmt Statement, associated with the directive.
  1825. ///
  1826. static OMPMasterDirective *Create(const ASTContext &C,
  1827. SourceLocation StartLoc,
  1828. SourceLocation EndLoc,
  1829. Stmt *AssociatedStmt);
  1830. /// Creates an empty directive.
  1831. ///
  1832. /// \param C AST context.
  1833. ///
  1834. static OMPMasterDirective *CreateEmpty(const ASTContext &C, EmptyShell);
  1835. static bool classof(const Stmt *T) {
  1836. return T->getStmtClass() == OMPMasterDirectiveClass;
  1837. }
  1838. };
  1839. /// This represents '#pragma omp critical' directive.
  1840. ///
  1841. /// \code
  1842. /// #pragma omp critical
  1843. /// \endcode
  1844. ///
  1845. class OMPCriticalDirective : public OMPExecutableDirective {
  1846. friend class ASTStmtReader;
  1847. friend class OMPExecutableDirective;
  1848. /// Name of the directive.
  1849. DeclarationNameInfo DirName;
  1850. /// Build directive with the given start and end location.
  1851. ///
  1852. /// \param Name Name of the directive.
  1853. /// \param StartLoc Starting location of the directive kind.
  1854. /// \param EndLoc Ending location of the directive.
  1855. ///
  1856. OMPCriticalDirective(const DeclarationNameInfo &Name, SourceLocation StartLoc,
  1857. SourceLocation EndLoc)
  1858. : OMPExecutableDirective(OMPCriticalDirectiveClass,
  1859. llvm::omp::OMPD_critical, StartLoc, EndLoc),
  1860. DirName(Name) {}
  1861. /// Build an empty directive.
  1862. ///
  1863. explicit OMPCriticalDirective()
  1864. : OMPExecutableDirective(OMPCriticalDirectiveClass,
  1865. llvm::omp::OMPD_critical, SourceLocation(),
  1866. SourceLocation()) {}
  1867. /// Set name of the directive.
  1868. ///
  1869. /// \param Name Name of the directive.
  1870. ///
  1871. void setDirectiveName(const DeclarationNameInfo &Name) { DirName = Name; }
  1872. public:
  1873. /// Creates directive.
  1874. ///
  1875. /// \param C AST context.
  1876. /// \param Name Name of the directive.
  1877. /// \param StartLoc Starting location of the directive kind.
  1878. /// \param EndLoc Ending Location of the directive.
  1879. /// \param Clauses List of clauses.
  1880. /// \param AssociatedStmt Statement, associated with the directive.
  1881. ///
  1882. static OMPCriticalDirective *
  1883. Create(const ASTContext &C, const DeclarationNameInfo &Name,
  1884. SourceLocation StartLoc, SourceLocation EndLoc,
  1885. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  1886. /// Creates an empty directive.
  1887. ///
  1888. /// \param C AST context.
  1889. /// \param NumClauses Number of clauses.
  1890. ///
  1891. static OMPCriticalDirective *CreateEmpty(const ASTContext &C,
  1892. unsigned NumClauses, EmptyShell);
  1893. /// Return name of the directive.
  1894. ///
  1895. DeclarationNameInfo getDirectiveName() const { return DirName; }
  1896. static bool classof(const Stmt *T) {
  1897. return T->getStmtClass() == OMPCriticalDirectiveClass;
  1898. }
  1899. };
  1900. /// This represents '#pragma omp parallel for' directive.
  1901. ///
  1902. /// \code
  1903. /// #pragma omp parallel for private(a,b) reduction(+:c,d)
  1904. /// \endcode
  1905. /// In this example directive '#pragma omp parallel for' has clauses 'private'
  1906. /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
  1907. /// variables 'c' and 'd'.
  1908. ///
  1909. class OMPParallelForDirective : public OMPLoopDirective {
  1910. friend class ASTStmtReader;
  1911. friend class OMPExecutableDirective;
  1912. /// true if current region has inner cancel directive.
  1913. bool HasCancel = false;
  1914. /// Build directive with the given start and end location.
  1915. ///
  1916. /// \param StartLoc Starting location of the directive kind.
  1917. /// \param EndLoc Ending location of the directive.
  1918. /// \param CollapsedNum Number of collapsed nested loops.
  1919. ///
  1920. OMPParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  1921. unsigned CollapsedNum)
  1922. : OMPLoopDirective(OMPParallelForDirectiveClass,
  1923. llvm::omp::OMPD_parallel_for, StartLoc, EndLoc,
  1924. CollapsedNum) {}
  1925. /// Build an empty directive.
  1926. ///
  1927. /// \param CollapsedNum Number of collapsed nested loops.
  1928. ///
  1929. explicit OMPParallelForDirective(unsigned CollapsedNum)
  1930. : OMPLoopDirective(OMPParallelForDirectiveClass,
  1931. llvm::omp::OMPD_parallel_for, SourceLocation(),
  1932. SourceLocation(), CollapsedNum) {}
  1933. /// Sets special task reduction descriptor.
  1934. void setTaskReductionRefExpr(Expr *E) {
  1935. Data->getChildren()[numLoopChildren(getLoopsNumber(),
  1936. llvm::omp::OMPD_parallel_for)] = E;
  1937. }
  1938. /// Set cancel state.
  1939. void setHasCancel(bool Has) { HasCancel = Has; }
  1940. public:
  1941. /// Creates directive with a list of \a Clauses.
  1942. ///
  1943. /// \param C AST context.
  1944. /// \param StartLoc Starting location of the directive kind.
  1945. /// \param EndLoc Ending Location of the directive.
  1946. /// \param CollapsedNum Number of collapsed loops.
  1947. /// \param Clauses List of clauses.
  1948. /// \param AssociatedStmt Statement, associated with the directive.
  1949. /// \param Exprs Helper expressions for CodeGen.
  1950. /// \param TaskRedRef Task reduction special reference expression to handle
  1951. /// taskgroup descriptor.
  1952. /// \param HasCancel true if current directive has inner cancel directive.
  1953. ///
  1954. static OMPParallelForDirective *
  1955. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  1956. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  1957. Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef,
  1958. bool HasCancel);
  1959. /// Creates an empty directive with the place
  1960. /// for \a NumClauses clauses.
  1961. ///
  1962. /// \param C AST context.
  1963. /// \param CollapsedNum Number of collapsed nested loops.
  1964. /// \param NumClauses Number of clauses.
  1965. ///
  1966. static OMPParallelForDirective *CreateEmpty(const ASTContext &C,
  1967. unsigned NumClauses,
  1968. unsigned CollapsedNum,
  1969. EmptyShell);
  1970. /// Returns special task reduction reference expression.
  1971. Expr *getTaskReductionRefExpr() {
  1972. return cast_or_null<Expr>(Data->getChildren()[numLoopChildren(
  1973. getLoopsNumber(), llvm::omp::OMPD_parallel_for)]);
  1974. }
  1975. const Expr *getTaskReductionRefExpr() const {
  1976. return const_cast<OMPParallelForDirective *>(this)
  1977. ->getTaskReductionRefExpr();
  1978. }
  1979. /// Return true if current directive has inner cancel directive.
  1980. bool hasCancel() const { return HasCancel; }
  1981. static bool classof(const Stmt *T) {
  1982. return T->getStmtClass() == OMPParallelForDirectiveClass;
  1983. }
  1984. };
  1985. /// This represents '#pragma omp parallel for simd' directive.
  1986. ///
  1987. /// \code
  1988. /// #pragma omp parallel for simd private(a,b) linear(i,j:s) reduction(+:c,d)
  1989. /// \endcode
  1990. /// In this example directive '#pragma omp parallel for simd' has clauses
  1991. /// 'private' with the variables 'a' and 'b', 'linear' with variables 'i', 'j'
  1992. /// and linear step 's', 'reduction' with operator '+' and variables 'c' and
  1993. /// 'd'.
  1994. ///
  1995. class OMPParallelForSimdDirective : public OMPLoopDirective {
  1996. friend class ASTStmtReader;
  1997. friend class OMPExecutableDirective;
  1998. /// Build directive with the given start and end location.
  1999. ///
  2000. /// \param StartLoc Starting location of the directive kind.
  2001. /// \param EndLoc Ending location of the directive.
  2002. /// \param CollapsedNum Number of collapsed nested loops.
  2003. ///
  2004. OMPParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  2005. unsigned CollapsedNum)
  2006. : OMPLoopDirective(OMPParallelForSimdDirectiveClass,
  2007. llvm::omp::OMPD_parallel_for_simd, StartLoc, EndLoc,
  2008. CollapsedNum) {}
  2009. /// Build an empty directive.
  2010. ///
  2011. /// \param CollapsedNum Number of collapsed nested loops.
  2012. ///
  2013. explicit OMPParallelForSimdDirective(unsigned CollapsedNum)
  2014. : OMPLoopDirective(OMPParallelForSimdDirectiveClass,
  2015. llvm::omp::OMPD_parallel_for_simd, SourceLocation(),
  2016. SourceLocation(), CollapsedNum) {}
  2017. public:
  2018. /// Creates directive with a list of \a Clauses.
  2019. ///
  2020. /// \param C AST context.
  2021. /// \param StartLoc Starting location of the directive kind.
  2022. /// \param EndLoc Ending Location of the directive.
  2023. /// \param CollapsedNum Number of collapsed loops.
  2024. /// \param Clauses List of clauses.
  2025. /// \param AssociatedStmt Statement, associated with the directive.
  2026. /// \param Exprs Helper expressions for CodeGen.
  2027. ///
  2028. static OMPParallelForSimdDirective *
  2029. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2030. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  2031. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  2032. /// Creates an empty directive with the place
  2033. /// for \a NumClauses clauses.
  2034. ///
  2035. /// \param C AST context.
  2036. /// \param CollapsedNum Number of collapsed nested loops.
  2037. /// \param NumClauses Number of clauses.
  2038. ///
  2039. static OMPParallelForSimdDirective *CreateEmpty(const ASTContext &C,
  2040. unsigned NumClauses,
  2041. unsigned CollapsedNum,
  2042. EmptyShell);
  2043. static bool classof(const Stmt *T) {
  2044. return T->getStmtClass() == OMPParallelForSimdDirectiveClass;
  2045. }
  2046. };
  2047. /// This represents '#pragma omp parallel master' directive.
  2048. ///
  2049. /// \code
  2050. /// #pragma omp parallel master private(a,b)
  2051. /// \endcode
  2052. /// In this example directive '#pragma omp parallel master' has clauses
  2053. /// 'private' with the variables 'a' and 'b'
  2054. ///
  2055. class OMPParallelMasterDirective : public OMPExecutableDirective {
  2056. friend class ASTStmtReader;
  2057. friend class OMPExecutableDirective;
  2058. OMPParallelMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2059. : OMPExecutableDirective(OMPParallelMasterDirectiveClass,
  2060. llvm::omp::OMPD_parallel_master, StartLoc,
  2061. EndLoc) {}
  2062. explicit OMPParallelMasterDirective()
  2063. : OMPExecutableDirective(OMPParallelMasterDirectiveClass,
  2064. llvm::omp::OMPD_parallel_master,
  2065. SourceLocation(), SourceLocation()) {}
  2066. /// Sets special task reduction descriptor.
  2067. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; }
  2068. public:
  2069. /// Creates directive with a list of \a Clauses.
  2070. ///
  2071. /// \param C AST context.
  2072. /// \param StartLoc Starting location of the directive kind.
  2073. /// \param EndLoc Ending Location of the directive.
  2074. /// \param Clauses List of clauses.
  2075. /// \param AssociatedStmt Statement, associated with the directive.
  2076. /// \param TaskRedRef Task reduction special reference expression to handle
  2077. /// taskgroup descriptor.
  2078. ///
  2079. static OMPParallelMasterDirective *
  2080. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2081. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef);
  2082. /// Creates an empty directive with the place for \a NumClauses
  2083. /// clauses.
  2084. ///
  2085. /// \param C AST context.
  2086. /// \param NumClauses Number of clauses.
  2087. ///
  2088. static OMPParallelMasterDirective *
  2089. CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
  2090. /// Returns special task reduction reference expression.
  2091. Expr *getTaskReductionRefExpr() {
  2092. return cast_or_null<Expr>(Data->getChildren()[0]);
  2093. }
  2094. const Expr *getTaskReductionRefExpr() const {
  2095. return const_cast<OMPParallelMasterDirective *>(this)
  2096. ->getTaskReductionRefExpr();
  2097. }
  2098. static bool classof(const Stmt *T) {
  2099. return T->getStmtClass() == OMPParallelMasterDirectiveClass;
  2100. }
  2101. };
  2102. /// This represents '#pragma omp parallel sections' directive.
  2103. ///
  2104. /// \code
  2105. /// #pragma omp parallel sections private(a,b) reduction(+:c,d)
  2106. /// \endcode
  2107. /// In this example directive '#pragma omp parallel sections' has clauses
  2108. /// 'private' with the variables 'a' and 'b' and 'reduction' with operator '+'
  2109. /// and variables 'c' and 'd'.
  2110. ///
  2111. class OMPParallelSectionsDirective : public OMPExecutableDirective {
  2112. friend class ASTStmtReader;
  2113. friend class OMPExecutableDirective;
  2114. /// true if current directive has inner cancel directive.
  2115. bool HasCancel = false;
  2116. /// Build directive with the given start and end location.
  2117. ///
  2118. /// \param StartLoc Starting location of the directive kind.
  2119. /// \param EndLoc Ending location of the directive.
  2120. ///
  2121. OMPParallelSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2122. : OMPExecutableDirective(OMPParallelSectionsDirectiveClass,
  2123. llvm::omp::OMPD_parallel_sections, StartLoc,
  2124. EndLoc) {}
  2125. /// Build an empty directive.
  2126. ///
  2127. explicit OMPParallelSectionsDirective()
  2128. : OMPExecutableDirective(OMPParallelSectionsDirectiveClass,
  2129. llvm::omp::OMPD_parallel_sections,
  2130. SourceLocation(), SourceLocation()) {}
  2131. /// Sets special task reduction descriptor.
  2132. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; }
  2133. /// Set cancel state.
  2134. void setHasCancel(bool Has) { HasCancel = Has; }
  2135. public:
  2136. /// Creates directive with a list of \a Clauses.
  2137. ///
  2138. /// \param C AST context.
  2139. /// \param StartLoc Starting location of the directive kind.
  2140. /// \param EndLoc Ending Location of the directive.
  2141. /// \param Clauses List of clauses.
  2142. /// \param AssociatedStmt Statement, associated with the directive.
  2143. /// \param TaskRedRef Task reduction special reference expression to handle
  2144. /// taskgroup descriptor.
  2145. /// \param HasCancel true if current directive has inner cancel directive.
  2146. ///
  2147. static OMPParallelSectionsDirective *
  2148. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2149. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef,
  2150. bool HasCancel);
  2151. /// Creates an empty directive with the place for \a NumClauses
  2152. /// clauses.
  2153. ///
  2154. /// \param C AST context.
  2155. /// \param NumClauses Number of clauses.
  2156. ///
  2157. static OMPParallelSectionsDirective *
  2158. CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
  2159. /// Returns special task reduction reference expression.
  2160. Expr *getTaskReductionRefExpr() {
  2161. return cast_or_null<Expr>(Data->getChildren()[0]);
  2162. }
  2163. const Expr *getTaskReductionRefExpr() const {
  2164. return const_cast<OMPParallelSectionsDirective *>(this)
  2165. ->getTaskReductionRefExpr();
  2166. }
  2167. /// Return true if current directive has inner cancel directive.
  2168. bool hasCancel() const { return HasCancel; }
  2169. static bool classof(const Stmt *T) {
  2170. return T->getStmtClass() == OMPParallelSectionsDirectiveClass;
  2171. }
  2172. };
  2173. /// This represents '#pragma omp task' directive.
  2174. ///
  2175. /// \code
  2176. /// #pragma omp task private(a,b) final(d)
  2177. /// \endcode
  2178. /// In this example directive '#pragma omp task' has clauses 'private' with the
  2179. /// variables 'a' and 'b' and 'final' with condition 'd'.
  2180. ///
  2181. class OMPTaskDirective : public OMPExecutableDirective {
  2182. friend class ASTStmtReader;
  2183. friend class OMPExecutableDirective;
  2184. /// true if this directive has inner cancel directive.
  2185. bool HasCancel = false;
  2186. /// Build directive with the given start and end location.
  2187. ///
  2188. /// \param StartLoc Starting location of the directive kind.
  2189. /// \param EndLoc Ending location of the directive.
  2190. ///
  2191. OMPTaskDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2192. : OMPExecutableDirective(OMPTaskDirectiveClass, llvm::omp::OMPD_task,
  2193. StartLoc, EndLoc) {}
  2194. /// Build an empty directive.
  2195. ///
  2196. explicit OMPTaskDirective()
  2197. : OMPExecutableDirective(OMPTaskDirectiveClass, llvm::omp::OMPD_task,
  2198. SourceLocation(), SourceLocation()) {}
  2199. /// Set cancel state.
  2200. void setHasCancel(bool Has) { HasCancel = Has; }
  2201. public:
  2202. /// Creates directive with a list of \a Clauses.
  2203. ///
  2204. /// \param C AST context.
  2205. /// \param StartLoc Starting location of the directive kind.
  2206. /// \param EndLoc Ending Location of the directive.
  2207. /// \param Clauses List of clauses.
  2208. /// \param AssociatedStmt Statement, associated with the directive.
  2209. /// \param HasCancel true, if current directive has inner cancel directive.
  2210. ///
  2211. static OMPTaskDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  2212. SourceLocation EndLoc,
  2213. ArrayRef<OMPClause *> Clauses,
  2214. Stmt *AssociatedStmt, bool HasCancel);
  2215. /// Creates an empty directive with the place for \a NumClauses
  2216. /// clauses.
  2217. ///
  2218. /// \param C AST context.
  2219. /// \param NumClauses Number of clauses.
  2220. ///
  2221. static OMPTaskDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
  2222. EmptyShell);
  2223. /// Return true if current directive has inner cancel directive.
  2224. bool hasCancel() const { return HasCancel; }
  2225. static bool classof(const Stmt *T) {
  2226. return T->getStmtClass() == OMPTaskDirectiveClass;
  2227. }
  2228. };
  2229. /// This represents '#pragma omp taskyield' directive.
  2230. ///
  2231. /// \code
  2232. /// #pragma omp taskyield
  2233. /// \endcode
  2234. ///
  2235. class OMPTaskyieldDirective : public OMPExecutableDirective {
  2236. friend class ASTStmtReader;
  2237. friend class OMPExecutableDirective;
  2238. /// Build directive with the given start and end location.
  2239. ///
  2240. /// \param StartLoc Starting location of the directive kind.
  2241. /// \param EndLoc Ending location of the directive.
  2242. ///
  2243. OMPTaskyieldDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2244. : OMPExecutableDirective(OMPTaskyieldDirectiveClass,
  2245. llvm::omp::OMPD_taskyield, StartLoc, EndLoc) {}
  2246. /// Build an empty directive.
  2247. ///
  2248. explicit OMPTaskyieldDirective()
  2249. : OMPExecutableDirective(OMPTaskyieldDirectiveClass,
  2250. llvm::omp::OMPD_taskyield, SourceLocation(),
  2251. SourceLocation()) {}
  2252. public:
  2253. /// Creates directive.
  2254. ///
  2255. /// \param C AST context.
  2256. /// \param StartLoc Starting location of the directive kind.
  2257. /// \param EndLoc Ending Location of the directive.
  2258. ///
  2259. static OMPTaskyieldDirective *
  2260. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
  2261. /// Creates an empty directive.
  2262. ///
  2263. /// \param C AST context.
  2264. ///
  2265. static OMPTaskyieldDirective *CreateEmpty(const ASTContext &C, EmptyShell);
  2266. static bool classof(const Stmt *T) {
  2267. return T->getStmtClass() == OMPTaskyieldDirectiveClass;
  2268. }
  2269. };
  2270. /// This represents '#pragma omp barrier' directive.
  2271. ///
  2272. /// \code
  2273. /// #pragma omp barrier
  2274. /// \endcode
  2275. ///
  2276. class OMPBarrierDirective : public OMPExecutableDirective {
  2277. friend class ASTStmtReader;
  2278. friend class OMPExecutableDirective;
  2279. /// Build directive with the given start and end location.
  2280. ///
  2281. /// \param StartLoc Starting location of the directive kind.
  2282. /// \param EndLoc Ending location of the directive.
  2283. ///
  2284. OMPBarrierDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2285. : OMPExecutableDirective(OMPBarrierDirectiveClass,
  2286. llvm::omp::OMPD_barrier, StartLoc, EndLoc) {}
  2287. /// Build an empty directive.
  2288. ///
  2289. explicit OMPBarrierDirective()
  2290. : OMPExecutableDirective(OMPBarrierDirectiveClass,
  2291. llvm::omp::OMPD_barrier, SourceLocation(),
  2292. SourceLocation()) {}
  2293. public:
  2294. /// Creates directive.
  2295. ///
  2296. /// \param C AST context.
  2297. /// \param StartLoc Starting location of the directive kind.
  2298. /// \param EndLoc Ending Location of the directive.
  2299. ///
  2300. static OMPBarrierDirective *
  2301. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
  2302. /// Creates an empty directive.
  2303. ///
  2304. /// \param C AST context.
  2305. ///
  2306. static OMPBarrierDirective *CreateEmpty(const ASTContext &C, EmptyShell);
  2307. static bool classof(const Stmt *T) {
  2308. return T->getStmtClass() == OMPBarrierDirectiveClass;
  2309. }
  2310. };
  2311. /// This represents '#pragma omp taskwait' directive.
  2312. ///
  2313. /// \code
  2314. /// #pragma omp taskwait
  2315. /// \endcode
  2316. ///
  2317. class OMPTaskwaitDirective : public OMPExecutableDirective {
  2318. friend class ASTStmtReader;
  2319. friend class OMPExecutableDirective;
  2320. /// Build directive with the given start and end location.
  2321. ///
  2322. /// \param StartLoc Starting location of the directive kind.
  2323. /// \param EndLoc Ending location of the directive.
  2324. ///
  2325. OMPTaskwaitDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2326. : OMPExecutableDirective(OMPTaskwaitDirectiveClass,
  2327. llvm::omp::OMPD_taskwait, StartLoc, EndLoc) {}
  2328. /// Build an empty directive.
  2329. ///
  2330. explicit OMPTaskwaitDirective()
  2331. : OMPExecutableDirective(OMPTaskwaitDirectiveClass,
  2332. llvm::omp::OMPD_taskwait, SourceLocation(),
  2333. SourceLocation()) {}
  2334. public:
  2335. /// Creates directive.
  2336. ///
  2337. /// \param C AST context.
  2338. /// \param StartLoc Starting location of the directive kind.
  2339. /// \param EndLoc Ending Location of the directive.
  2340. /// \param Clauses List of clauses.
  2341. ///
  2342. static OMPTaskwaitDirective *Create(const ASTContext &C,
  2343. SourceLocation StartLoc,
  2344. SourceLocation EndLoc,
  2345. ArrayRef<OMPClause *> Clauses);
  2346. /// Creates an empty directive.
  2347. ///
  2348. /// \param C AST context.
  2349. /// \param NumClauses Number of clauses.
  2350. ///
  2351. static OMPTaskwaitDirective *CreateEmpty(const ASTContext &C,
  2352. unsigned NumClauses, EmptyShell);
  2353. static bool classof(const Stmt *T) {
  2354. return T->getStmtClass() == OMPTaskwaitDirectiveClass;
  2355. }
  2356. };
  2357. /// This represents '#pragma omp taskgroup' directive.
  2358. ///
  2359. /// \code
  2360. /// #pragma omp taskgroup
  2361. /// \endcode
  2362. ///
  2363. class OMPTaskgroupDirective : public OMPExecutableDirective {
  2364. friend class ASTStmtReader;
  2365. friend class OMPExecutableDirective;
  2366. /// Build directive with the given start and end location.
  2367. ///
  2368. /// \param StartLoc Starting location of the directive kind.
  2369. /// \param EndLoc Ending location of the directive.
  2370. ///
  2371. OMPTaskgroupDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2372. : OMPExecutableDirective(OMPTaskgroupDirectiveClass,
  2373. llvm::omp::OMPD_taskgroup, StartLoc, EndLoc) {}
  2374. /// Build an empty directive.
  2375. ///
  2376. explicit OMPTaskgroupDirective()
  2377. : OMPExecutableDirective(OMPTaskgroupDirectiveClass,
  2378. llvm::omp::OMPD_taskgroup, SourceLocation(),
  2379. SourceLocation()) {}
  2380. /// Sets the task_reduction return variable.
  2381. void setReductionRef(Expr *RR) { Data->getChildren()[0] = RR; }
  2382. public:
  2383. /// Creates directive.
  2384. ///
  2385. /// \param C AST context.
  2386. /// \param StartLoc Starting location of the directive kind.
  2387. /// \param EndLoc Ending Location of the directive.
  2388. /// \param Clauses List of clauses.
  2389. /// \param AssociatedStmt Statement, associated with the directive.
  2390. /// \param ReductionRef Reference to the task_reduction return variable.
  2391. ///
  2392. static OMPTaskgroupDirective *
  2393. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2394. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
  2395. Expr *ReductionRef);
  2396. /// Creates an empty directive.
  2397. ///
  2398. /// \param C AST context.
  2399. /// \param NumClauses Number of clauses.
  2400. ///
  2401. static OMPTaskgroupDirective *CreateEmpty(const ASTContext &C,
  2402. unsigned NumClauses, EmptyShell);
  2403. /// Returns reference to the task_reduction return variable.
  2404. const Expr *getReductionRef() const {
  2405. return const_cast<OMPTaskgroupDirective *>(this)->getReductionRef();
  2406. }
  2407. Expr *getReductionRef() { return cast_or_null<Expr>(Data->getChildren()[0]); }
  2408. static bool classof(const Stmt *T) {
  2409. return T->getStmtClass() == OMPTaskgroupDirectiveClass;
  2410. }
  2411. };
  2412. /// This represents '#pragma omp flush' directive.
  2413. ///
  2414. /// \code
  2415. /// #pragma omp flush(a,b)
  2416. /// \endcode
  2417. /// In this example directive '#pragma omp flush' has 2 arguments- variables 'a'
  2418. /// and 'b'.
  2419. /// 'omp flush' directive does not have clauses but have an optional list of
  2420. /// variables to flush. This list of variables is stored within some fake clause
  2421. /// FlushClause.
  2422. class OMPFlushDirective : public OMPExecutableDirective {
  2423. friend class ASTStmtReader;
  2424. friend class OMPExecutableDirective;
  2425. /// Build directive with the given start and end location.
  2426. ///
  2427. /// \param StartLoc Starting location of the directive kind.
  2428. /// \param EndLoc Ending location of the directive.
  2429. ///
  2430. OMPFlushDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2431. : OMPExecutableDirective(OMPFlushDirectiveClass, llvm::omp::OMPD_flush,
  2432. StartLoc, EndLoc) {}
  2433. /// Build an empty directive.
  2434. ///
  2435. explicit OMPFlushDirective()
  2436. : OMPExecutableDirective(OMPFlushDirectiveClass, llvm::omp::OMPD_flush,
  2437. SourceLocation(), SourceLocation()) {}
  2438. public:
  2439. /// Creates directive with a list of \a Clauses.
  2440. ///
  2441. /// \param C AST context.
  2442. /// \param StartLoc Starting location of the directive kind.
  2443. /// \param EndLoc Ending Location of the directive.
  2444. /// \param Clauses List of clauses (only single OMPFlushClause clause is
  2445. /// allowed).
  2446. ///
  2447. static OMPFlushDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  2448. SourceLocation EndLoc,
  2449. ArrayRef<OMPClause *> Clauses);
  2450. /// Creates an empty directive with the place for \a NumClauses
  2451. /// clauses.
  2452. ///
  2453. /// \param C AST context.
  2454. /// \param NumClauses Number of clauses.
  2455. ///
  2456. static OMPFlushDirective *CreateEmpty(const ASTContext &C,
  2457. unsigned NumClauses, EmptyShell);
  2458. static bool classof(const Stmt *T) {
  2459. return T->getStmtClass() == OMPFlushDirectiveClass;
  2460. }
  2461. };
  2462. /// This represents '#pragma omp depobj' directive.
  2463. ///
  2464. /// \code
  2465. /// #pragma omp depobj(a) depend(in:x,y)
  2466. /// \endcode
  2467. /// In this example directive '#pragma omp depobj' initializes a depobj object
  2468. /// 'a' with dependence type 'in' and a list with 'x' and 'y' locators.
  2469. class OMPDepobjDirective final : public OMPExecutableDirective {
  2470. friend class ASTStmtReader;
  2471. friend class OMPExecutableDirective;
  2472. /// Build directive with the given start and end location.
  2473. ///
  2474. /// \param StartLoc Starting location of the directive kind.
  2475. /// \param EndLoc Ending location of the directive.
  2476. ///
  2477. OMPDepobjDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2478. : OMPExecutableDirective(OMPDepobjDirectiveClass, llvm::omp::OMPD_depobj,
  2479. StartLoc, EndLoc) {}
  2480. /// Build an empty directive.
  2481. ///
  2482. explicit OMPDepobjDirective()
  2483. : OMPExecutableDirective(OMPDepobjDirectiveClass, llvm::omp::OMPD_depobj,
  2484. SourceLocation(), SourceLocation()) {}
  2485. public:
  2486. /// Creates directive with a list of \a Clauses.
  2487. ///
  2488. /// \param C AST context.
  2489. /// \param StartLoc Starting location of the directive kind.
  2490. /// \param EndLoc Ending Location of the directive.
  2491. /// \param Clauses List of clauses.
  2492. ///
  2493. static OMPDepobjDirective *Create(const ASTContext &C,
  2494. SourceLocation StartLoc,
  2495. SourceLocation EndLoc,
  2496. ArrayRef<OMPClause *> Clauses);
  2497. /// Creates an empty directive with the place for \a NumClauses
  2498. /// clauses.
  2499. ///
  2500. /// \param C AST context.
  2501. /// \param NumClauses Number of clauses.
  2502. ///
  2503. static OMPDepobjDirective *CreateEmpty(const ASTContext &C,
  2504. unsigned NumClauses, EmptyShell);
  2505. static bool classof(const Stmt *T) {
  2506. return T->getStmtClass() == OMPDepobjDirectiveClass;
  2507. }
  2508. };
  2509. /// This represents '#pragma omp ordered' directive.
  2510. ///
  2511. /// \code
  2512. /// #pragma omp ordered
  2513. /// \endcode
  2514. ///
  2515. class OMPOrderedDirective : public OMPExecutableDirective {
  2516. friend class ASTStmtReader;
  2517. friend class OMPExecutableDirective;
  2518. /// Build directive with the given start and end location.
  2519. ///
  2520. /// \param StartLoc Starting location of the directive kind.
  2521. /// \param EndLoc Ending location of the directive.
  2522. ///
  2523. OMPOrderedDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2524. : OMPExecutableDirective(OMPOrderedDirectiveClass,
  2525. llvm::omp::OMPD_ordered, StartLoc, EndLoc) {}
  2526. /// Build an empty directive.
  2527. ///
  2528. explicit OMPOrderedDirective()
  2529. : OMPExecutableDirective(OMPOrderedDirectiveClass,
  2530. llvm::omp::OMPD_ordered, SourceLocation(),
  2531. SourceLocation()) {}
  2532. public:
  2533. /// Creates directive.
  2534. ///
  2535. /// \param C AST context.
  2536. /// \param StartLoc Starting location of the directive kind.
  2537. /// \param EndLoc Ending Location of the directive.
  2538. /// \param Clauses List of clauses.
  2539. /// \param AssociatedStmt Statement, associated with the directive.
  2540. ///
  2541. static OMPOrderedDirective *
  2542. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2543. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  2544. /// Creates an empty directive.
  2545. ///
  2546. /// \param C AST context.
  2547. /// \param NumClauses Number of clauses.
  2548. /// \param IsStandalone true, if the the standalone directive is created.
  2549. ///
  2550. static OMPOrderedDirective *CreateEmpty(const ASTContext &C,
  2551. unsigned NumClauses,
  2552. bool IsStandalone, EmptyShell);
  2553. static bool classof(const Stmt *T) {
  2554. return T->getStmtClass() == OMPOrderedDirectiveClass;
  2555. }
  2556. };
  2557. /// This represents '#pragma omp atomic' directive.
  2558. ///
  2559. /// \code
  2560. /// #pragma omp atomic capture
  2561. /// \endcode
  2562. /// In this example directive '#pragma omp atomic' has clause 'capture'.
  2563. ///
  2564. class OMPAtomicDirective : public OMPExecutableDirective {
  2565. friend class ASTStmtReader;
  2566. friend class OMPExecutableDirective;
  2567. /// Used for 'atomic update' or 'atomic capture' constructs. They may
  2568. /// have atomic expressions of forms
  2569. /// \code
  2570. /// x = x binop expr;
  2571. /// x = expr binop x;
  2572. /// \endcode
  2573. /// This field is true for the first form of the expression and false for the
  2574. /// second. Required for correct codegen of non-associative operations (like
  2575. /// << or >>).
  2576. bool IsXLHSInRHSPart = false;
  2577. /// Used for 'atomic update' or 'atomic capture' constructs. They may
  2578. /// have atomic expressions of forms
  2579. /// \code
  2580. /// v = x; <update x>;
  2581. /// <update x>; v = x;
  2582. /// \endcode
  2583. /// This field is true for the first(postfix) form of the expression and false
  2584. /// otherwise.
  2585. bool IsPostfixUpdate = false;
  2586. /// Build directive with the given start and end location.
  2587. ///
  2588. /// \param StartLoc Starting location of the directive kind.
  2589. /// \param EndLoc Ending location of the directive.
  2590. ///
  2591. OMPAtomicDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2592. : OMPExecutableDirective(OMPAtomicDirectiveClass, llvm::omp::OMPD_atomic,
  2593. StartLoc, EndLoc) {}
  2594. /// Build an empty directive.
  2595. ///
  2596. explicit OMPAtomicDirective()
  2597. : OMPExecutableDirective(OMPAtomicDirectiveClass, llvm::omp::OMPD_atomic,
  2598. SourceLocation(), SourceLocation()) {}
  2599. enum DataPositionTy : size_t {
  2600. POS_X = 0,
  2601. POS_V,
  2602. POS_E,
  2603. POS_UpdateExpr,
  2604. };
  2605. /// Set 'x' part of the associated expression/statement.
  2606. void setX(Expr *X) { Data->getChildren()[DataPositionTy::POS_X] = X; }
  2607. /// Set helper expression of the form
  2608. /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or
  2609. /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
  2610. void setUpdateExpr(Expr *UE) {
  2611. Data->getChildren()[DataPositionTy::POS_UpdateExpr] = UE;
  2612. }
  2613. /// Set 'v' part of the associated expression/statement.
  2614. void setV(Expr *V) { Data->getChildren()[DataPositionTy::POS_V] = V; }
  2615. /// Set 'expr' part of the associated expression/statement.
  2616. void setExpr(Expr *E) { Data->getChildren()[DataPositionTy::POS_E] = E; }
  2617. public:
  2618. /// Creates directive with a list of \a Clauses and 'x', 'v' and 'expr'
  2619. /// parts of the atomic construct (see Section 2.12.6, atomic Construct, for
  2620. /// detailed description of 'x', 'v' and 'expr').
  2621. ///
  2622. /// \param C AST context.
  2623. /// \param StartLoc Starting location of the directive kind.
  2624. /// \param EndLoc Ending Location of the directive.
  2625. /// \param Clauses List of clauses.
  2626. /// \param AssociatedStmt Statement, associated with the directive.
  2627. /// \param X 'x' part of the associated expression/statement.
  2628. /// \param V 'v' part of the associated expression/statement.
  2629. /// \param E 'expr' part of the associated expression/statement.
  2630. /// \param UE Helper expression of the form
  2631. /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or
  2632. /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
  2633. /// \param IsXLHSInRHSPart true if \a UE has the first form and false if the
  2634. /// second.
  2635. /// \param IsPostfixUpdate true if original value of 'x' must be stored in
  2636. /// 'v', not an updated one.
  2637. static OMPAtomicDirective *
  2638. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2639. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V,
  2640. Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate);
  2641. /// Creates an empty directive with the place for \a NumClauses
  2642. /// clauses.
  2643. ///
  2644. /// \param C AST context.
  2645. /// \param NumClauses Number of clauses.
  2646. ///
  2647. static OMPAtomicDirective *CreateEmpty(const ASTContext &C,
  2648. unsigned NumClauses, EmptyShell);
  2649. /// Get 'x' part of the associated expression/statement.
  2650. Expr *getX() {
  2651. return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_X]);
  2652. }
  2653. const Expr *getX() const {
  2654. return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_X]);
  2655. }
  2656. /// Get helper expression of the form
  2657. /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or
  2658. /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
  2659. Expr *getUpdateExpr() {
  2660. return cast_or_null<Expr>(
  2661. Data->getChildren()[DataPositionTy::POS_UpdateExpr]);
  2662. }
  2663. const Expr *getUpdateExpr() const {
  2664. return cast_or_null<Expr>(
  2665. Data->getChildren()[DataPositionTy::POS_UpdateExpr]);
  2666. }
  2667. /// Return true if helper update expression has form
  2668. /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form
  2669. /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
  2670. bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; }
  2671. /// Return true if 'v' expression must be updated to original value of
  2672. /// 'x', false if 'v' must be updated to the new value of 'x'.
  2673. bool isPostfixUpdate() const { return IsPostfixUpdate; }
  2674. /// Get 'v' part of the associated expression/statement.
  2675. Expr *getV() {
  2676. return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_V]);
  2677. }
  2678. const Expr *getV() const {
  2679. return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_V]);
  2680. }
  2681. /// Get 'expr' part of the associated expression/statement.
  2682. Expr *getExpr() {
  2683. return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_E]);
  2684. }
  2685. const Expr *getExpr() const {
  2686. return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_E]);
  2687. }
  2688. static bool classof(const Stmt *T) {
  2689. return T->getStmtClass() == OMPAtomicDirectiveClass;
  2690. }
  2691. };
  2692. /// This represents '#pragma omp target' directive.
  2693. ///
  2694. /// \code
  2695. /// #pragma omp target if(a)
  2696. /// \endcode
  2697. /// In this example directive '#pragma omp target' has clause 'if' with
  2698. /// condition 'a'.
  2699. ///
  2700. class OMPTargetDirective : public OMPExecutableDirective {
  2701. friend class ASTStmtReader;
  2702. friend class OMPExecutableDirective;
  2703. /// Build directive with the given start and end location.
  2704. ///
  2705. /// \param StartLoc Starting location of the directive kind.
  2706. /// \param EndLoc Ending location of the directive.
  2707. ///
  2708. OMPTargetDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2709. : OMPExecutableDirective(OMPTargetDirectiveClass, llvm::omp::OMPD_target,
  2710. StartLoc, EndLoc) {}
  2711. /// Build an empty directive.
  2712. ///
  2713. explicit OMPTargetDirective()
  2714. : OMPExecutableDirective(OMPTargetDirectiveClass, llvm::omp::OMPD_target,
  2715. SourceLocation(), SourceLocation()) {}
  2716. public:
  2717. /// Creates directive with a list of \a Clauses.
  2718. ///
  2719. /// \param C AST context.
  2720. /// \param StartLoc Starting location of the directive kind.
  2721. /// \param EndLoc Ending Location of the directive.
  2722. /// \param Clauses List of clauses.
  2723. /// \param AssociatedStmt Statement, associated with the directive.
  2724. ///
  2725. static OMPTargetDirective *
  2726. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2727. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  2728. /// Creates an empty directive with the place for \a NumClauses
  2729. /// clauses.
  2730. ///
  2731. /// \param C AST context.
  2732. /// \param NumClauses Number of clauses.
  2733. ///
  2734. static OMPTargetDirective *CreateEmpty(const ASTContext &C,
  2735. unsigned NumClauses, EmptyShell);
  2736. static bool classof(const Stmt *T) {
  2737. return T->getStmtClass() == OMPTargetDirectiveClass;
  2738. }
  2739. };
  2740. /// This represents '#pragma omp target data' directive.
  2741. ///
  2742. /// \code
  2743. /// #pragma omp target data device(0) if(a) map(b[:])
  2744. /// \endcode
  2745. /// In this example directive '#pragma omp target data' has clauses 'device'
  2746. /// with the value '0', 'if' with condition 'a' and 'map' with array
  2747. /// section 'b[:]'.
  2748. ///
  2749. class OMPTargetDataDirective : public OMPExecutableDirective {
  2750. friend class ASTStmtReader;
  2751. friend class OMPExecutableDirective;
  2752. /// Build directive with the given start and end location.
  2753. ///
  2754. /// \param StartLoc Starting location of the directive kind.
  2755. /// \param EndLoc Ending Location of the directive.
  2756. ///
  2757. OMPTargetDataDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2758. : OMPExecutableDirective(OMPTargetDataDirectiveClass,
  2759. llvm::omp::OMPD_target_data, StartLoc, EndLoc) {}
  2760. /// Build an empty directive.
  2761. ///
  2762. explicit OMPTargetDataDirective()
  2763. : OMPExecutableDirective(OMPTargetDataDirectiveClass,
  2764. llvm::omp::OMPD_target_data, SourceLocation(),
  2765. SourceLocation()) {}
  2766. public:
  2767. /// Creates directive with a list of \a Clauses.
  2768. ///
  2769. /// \param C AST context.
  2770. /// \param StartLoc Starting location of the directive kind.
  2771. /// \param EndLoc Ending Location of the directive.
  2772. /// \param Clauses List of clauses.
  2773. /// \param AssociatedStmt Statement, associated with the directive.
  2774. ///
  2775. static OMPTargetDataDirective *
  2776. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2777. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  2778. /// Creates an empty directive with the place for \a N clauses.
  2779. ///
  2780. /// \param C AST context.
  2781. /// \param N The number of clauses.
  2782. ///
  2783. static OMPTargetDataDirective *CreateEmpty(const ASTContext &C, unsigned N,
  2784. EmptyShell);
  2785. static bool classof(const Stmt *T) {
  2786. return T->getStmtClass() == OMPTargetDataDirectiveClass;
  2787. }
  2788. };
  2789. /// This represents '#pragma omp target enter data' directive.
  2790. ///
  2791. /// \code
  2792. /// #pragma omp target enter data device(0) if(a) map(b[:])
  2793. /// \endcode
  2794. /// In this example directive '#pragma omp target enter data' has clauses
  2795. /// 'device' with the value '0', 'if' with condition 'a' and 'map' with array
  2796. /// section 'b[:]'.
  2797. ///
  2798. class OMPTargetEnterDataDirective : public OMPExecutableDirective {
  2799. friend class ASTStmtReader;
  2800. friend class OMPExecutableDirective;
  2801. /// Build directive with the given start and end location.
  2802. ///
  2803. /// \param StartLoc Starting location of the directive kind.
  2804. /// \param EndLoc Ending Location of the directive.
  2805. ///
  2806. OMPTargetEnterDataDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2807. : OMPExecutableDirective(OMPTargetEnterDataDirectiveClass,
  2808. llvm::omp::OMPD_target_enter_data, StartLoc,
  2809. EndLoc) {}
  2810. /// Build an empty directive.
  2811. ///
  2812. explicit OMPTargetEnterDataDirective()
  2813. : OMPExecutableDirective(OMPTargetEnterDataDirectiveClass,
  2814. llvm::omp::OMPD_target_enter_data,
  2815. SourceLocation(), SourceLocation()) {}
  2816. public:
  2817. /// Creates directive with a list of \a Clauses.
  2818. ///
  2819. /// \param C AST context.
  2820. /// \param StartLoc Starting location of the directive kind.
  2821. /// \param EndLoc Ending Location of the directive.
  2822. /// \param Clauses List of clauses.
  2823. /// \param AssociatedStmt Statement, associated with the directive.
  2824. ///
  2825. static OMPTargetEnterDataDirective *
  2826. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2827. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  2828. /// Creates an empty directive with the place for \a N clauses.
  2829. ///
  2830. /// \param C AST context.
  2831. /// \param N The number of clauses.
  2832. ///
  2833. static OMPTargetEnterDataDirective *CreateEmpty(const ASTContext &C,
  2834. unsigned N, EmptyShell);
  2835. static bool classof(const Stmt *T) {
  2836. return T->getStmtClass() == OMPTargetEnterDataDirectiveClass;
  2837. }
  2838. };
  2839. /// This represents '#pragma omp target exit data' directive.
  2840. ///
  2841. /// \code
  2842. /// #pragma omp target exit data device(0) if(a) map(b[:])
  2843. /// \endcode
  2844. /// In this example directive '#pragma omp target exit data' has clauses
  2845. /// 'device' with the value '0', 'if' with condition 'a' and 'map' with array
  2846. /// section 'b[:]'.
  2847. ///
  2848. class OMPTargetExitDataDirective : public OMPExecutableDirective {
  2849. friend class ASTStmtReader;
  2850. friend class OMPExecutableDirective;
  2851. /// Build directive with the given start and end location.
  2852. ///
  2853. /// \param StartLoc Starting location of the directive kind.
  2854. /// \param EndLoc Ending Location of the directive.
  2855. ///
  2856. OMPTargetExitDataDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2857. : OMPExecutableDirective(OMPTargetExitDataDirectiveClass,
  2858. llvm::omp::OMPD_target_exit_data, StartLoc,
  2859. EndLoc) {}
  2860. /// Build an empty directive.
  2861. ///
  2862. explicit OMPTargetExitDataDirective()
  2863. : OMPExecutableDirective(OMPTargetExitDataDirectiveClass,
  2864. llvm::omp::OMPD_target_exit_data,
  2865. SourceLocation(), SourceLocation()) {}
  2866. public:
  2867. /// Creates directive with a list of \a Clauses.
  2868. ///
  2869. /// \param C AST context.
  2870. /// \param StartLoc Starting location of the directive kind.
  2871. /// \param EndLoc Ending Location of the directive.
  2872. /// \param Clauses List of clauses.
  2873. /// \param AssociatedStmt Statement, associated with the directive.
  2874. ///
  2875. static OMPTargetExitDataDirective *
  2876. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2877. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  2878. /// Creates an empty directive with the place for \a N clauses.
  2879. ///
  2880. /// \param C AST context.
  2881. /// \param N The number of clauses.
  2882. ///
  2883. static OMPTargetExitDataDirective *CreateEmpty(const ASTContext &C,
  2884. unsigned N, EmptyShell);
  2885. static bool classof(const Stmt *T) {
  2886. return T->getStmtClass() == OMPTargetExitDataDirectiveClass;
  2887. }
  2888. };
  2889. /// This represents '#pragma omp target parallel' directive.
  2890. ///
  2891. /// \code
  2892. /// #pragma omp target parallel if(a)
  2893. /// \endcode
  2894. /// In this example directive '#pragma omp target parallel' has clause 'if' with
  2895. /// condition 'a'.
  2896. ///
  2897. class OMPTargetParallelDirective : public OMPExecutableDirective {
  2898. friend class ASTStmtReader;
  2899. friend class OMPExecutableDirective;
  2900. /// true if the construct has inner cancel directive.
  2901. bool HasCancel = false;
  2902. /// Build directive with the given start and end location.
  2903. ///
  2904. /// \param StartLoc Starting location of the directive kind.
  2905. /// \param EndLoc Ending location of the directive.
  2906. ///
  2907. OMPTargetParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  2908. : OMPExecutableDirective(OMPTargetParallelDirectiveClass,
  2909. llvm::omp::OMPD_target_parallel, StartLoc,
  2910. EndLoc) {}
  2911. /// Build an empty directive.
  2912. ///
  2913. explicit OMPTargetParallelDirective()
  2914. : OMPExecutableDirective(OMPTargetParallelDirectiveClass,
  2915. llvm::omp::OMPD_target_parallel,
  2916. SourceLocation(), SourceLocation()) {}
  2917. /// Sets special task reduction descriptor.
  2918. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; }
  2919. /// Set cancel state.
  2920. void setHasCancel(bool Has) { HasCancel = Has; }
  2921. public:
  2922. /// Creates directive with a list of \a Clauses.
  2923. ///
  2924. /// \param C AST context.
  2925. /// \param StartLoc Starting location of the directive kind.
  2926. /// \param EndLoc Ending Location of the directive.
  2927. /// \param Clauses List of clauses.
  2928. /// \param AssociatedStmt Statement, associated with the directive.
  2929. /// \param TaskRedRef Task reduction special reference expression to handle
  2930. /// taskgroup descriptor.
  2931. /// \param HasCancel true if this directive has inner cancel directive.
  2932. ///
  2933. static OMPTargetParallelDirective *
  2934. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  2935. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef,
  2936. bool HasCancel);
  2937. /// Creates an empty directive with the place for \a NumClauses
  2938. /// clauses.
  2939. ///
  2940. /// \param C AST context.
  2941. /// \param NumClauses Number of clauses.
  2942. ///
  2943. static OMPTargetParallelDirective *
  2944. CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
  2945. /// Returns special task reduction reference expression.
  2946. Expr *getTaskReductionRefExpr() {
  2947. return cast_or_null<Expr>(Data->getChildren()[0]);
  2948. }
  2949. const Expr *getTaskReductionRefExpr() const {
  2950. return const_cast<OMPTargetParallelDirective *>(this)
  2951. ->getTaskReductionRefExpr();
  2952. }
  2953. /// Return true if current directive has inner cancel directive.
  2954. bool hasCancel() const { return HasCancel; }
  2955. static bool classof(const Stmt *T) {
  2956. return T->getStmtClass() == OMPTargetParallelDirectiveClass;
  2957. }
  2958. };
  2959. /// This represents '#pragma omp target parallel for' directive.
  2960. ///
  2961. /// \code
  2962. /// #pragma omp target parallel for private(a,b) reduction(+:c,d)
  2963. /// \endcode
  2964. /// In this example directive '#pragma omp target parallel for' has clauses
  2965. /// 'private' with the variables 'a' and 'b' and 'reduction' with operator '+'
  2966. /// and variables 'c' and 'd'.
  2967. ///
  2968. class OMPTargetParallelForDirective : public OMPLoopDirective {
  2969. friend class ASTStmtReader;
  2970. friend class OMPExecutableDirective;
  2971. /// true if current region has inner cancel directive.
  2972. bool HasCancel = false;
  2973. /// Build directive with the given start and end location.
  2974. ///
  2975. /// \param StartLoc Starting location of the directive kind.
  2976. /// \param EndLoc Ending location of the directive.
  2977. /// \param CollapsedNum Number of collapsed nested loops.
  2978. ///
  2979. OMPTargetParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  2980. unsigned CollapsedNum)
  2981. : OMPLoopDirective(OMPTargetParallelForDirectiveClass,
  2982. llvm::omp::OMPD_target_parallel_for, StartLoc, EndLoc,
  2983. CollapsedNum) {}
  2984. /// Build an empty directive.
  2985. ///
  2986. /// \param CollapsedNum Number of collapsed nested loops.
  2987. ///
  2988. explicit OMPTargetParallelForDirective(unsigned CollapsedNum)
  2989. : OMPLoopDirective(OMPTargetParallelForDirectiveClass,
  2990. llvm::omp::OMPD_target_parallel_for, SourceLocation(),
  2991. SourceLocation(), CollapsedNum) {}
  2992. /// Sets special task reduction descriptor.
  2993. void setTaskReductionRefExpr(Expr *E) {
  2994. Data->getChildren()[numLoopChildren(
  2995. getLoopsNumber(), llvm::omp::OMPD_target_parallel_for)] = E;
  2996. }
  2997. /// Set cancel state.
  2998. void setHasCancel(bool Has) { HasCancel = Has; }
  2999. public:
  3000. /// Creates directive with a list of \a Clauses.
  3001. ///
  3002. /// \param C AST context.
  3003. /// \param StartLoc Starting location of the directive kind.
  3004. /// \param EndLoc Ending Location of the directive.
  3005. /// \param CollapsedNum Number of collapsed loops.
  3006. /// \param Clauses List of clauses.
  3007. /// \param AssociatedStmt Statement, associated with the directive.
  3008. /// \param Exprs Helper expressions for CodeGen.
  3009. /// \param TaskRedRef Task reduction special reference expression to handle
  3010. /// taskgroup descriptor.
  3011. /// \param HasCancel true if current directive has inner cancel directive.
  3012. ///
  3013. static OMPTargetParallelForDirective *
  3014. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3015. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3016. Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef,
  3017. bool HasCancel);
  3018. /// Creates an empty directive with the place
  3019. /// for \a NumClauses clauses.
  3020. ///
  3021. /// \param C AST context.
  3022. /// \param CollapsedNum Number of collapsed nested loops.
  3023. /// \param NumClauses Number of clauses.
  3024. ///
  3025. static OMPTargetParallelForDirective *CreateEmpty(const ASTContext &C,
  3026. unsigned NumClauses,
  3027. unsigned CollapsedNum,
  3028. EmptyShell);
  3029. /// Returns special task reduction reference expression.
  3030. Expr *getTaskReductionRefExpr() {
  3031. return cast_or_null<Expr>(Data->getChildren()[numLoopChildren(
  3032. getLoopsNumber(), llvm::omp::OMPD_target_parallel_for)]);
  3033. }
  3034. const Expr *getTaskReductionRefExpr() const {
  3035. return const_cast<OMPTargetParallelForDirective *>(this)
  3036. ->getTaskReductionRefExpr();
  3037. }
  3038. /// Return true if current directive has inner cancel directive.
  3039. bool hasCancel() const { return HasCancel; }
  3040. static bool classof(const Stmt *T) {
  3041. return T->getStmtClass() == OMPTargetParallelForDirectiveClass;
  3042. }
  3043. };
  3044. /// This represents '#pragma omp teams' directive.
  3045. ///
  3046. /// \code
  3047. /// #pragma omp teams if(a)
  3048. /// \endcode
  3049. /// In this example directive '#pragma omp teams' has clause 'if' with
  3050. /// condition 'a'.
  3051. ///
  3052. class OMPTeamsDirective : public OMPExecutableDirective {
  3053. friend class ASTStmtReader;
  3054. friend class OMPExecutableDirective;
  3055. /// Build directive with the given start and end location.
  3056. ///
  3057. /// \param StartLoc Starting location of the directive kind.
  3058. /// \param EndLoc Ending location of the directive.
  3059. ///
  3060. OMPTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  3061. : OMPExecutableDirective(OMPTeamsDirectiveClass, llvm::omp::OMPD_teams,
  3062. StartLoc, EndLoc) {}
  3063. /// Build an empty directive.
  3064. ///
  3065. explicit OMPTeamsDirective()
  3066. : OMPExecutableDirective(OMPTeamsDirectiveClass, llvm::omp::OMPD_teams,
  3067. SourceLocation(), SourceLocation()) {}
  3068. public:
  3069. /// Creates directive with a list of \a Clauses.
  3070. ///
  3071. /// \param C AST context.
  3072. /// \param StartLoc Starting location of the directive kind.
  3073. /// \param EndLoc Ending Location of the directive.
  3074. /// \param Clauses List of clauses.
  3075. /// \param AssociatedStmt Statement, associated with the directive.
  3076. ///
  3077. static OMPTeamsDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  3078. SourceLocation EndLoc,
  3079. ArrayRef<OMPClause *> Clauses,
  3080. Stmt *AssociatedStmt);
  3081. /// Creates an empty directive with the place for \a NumClauses
  3082. /// clauses.
  3083. ///
  3084. /// \param C AST context.
  3085. /// \param NumClauses Number of clauses.
  3086. ///
  3087. static OMPTeamsDirective *CreateEmpty(const ASTContext &C,
  3088. unsigned NumClauses, EmptyShell);
  3089. static bool classof(const Stmt *T) {
  3090. return T->getStmtClass() == OMPTeamsDirectiveClass;
  3091. }
  3092. };
  3093. /// This represents '#pragma omp cancellation point' directive.
  3094. ///
  3095. /// \code
  3096. /// #pragma omp cancellation point for
  3097. /// \endcode
  3098. ///
  3099. /// In this example a cancellation point is created for innermost 'for' region.
  3100. class OMPCancellationPointDirective : public OMPExecutableDirective {
  3101. friend class ASTStmtReader;
  3102. friend class OMPExecutableDirective;
  3103. OpenMPDirectiveKind CancelRegion = llvm::omp::OMPD_unknown;
  3104. /// Build directive with the given start and end location.
  3105. ///
  3106. /// \param StartLoc Starting location of the directive kind.
  3107. /// \param EndLoc Ending location of the directive.
  3108. /// statements and child expressions.
  3109. ///
  3110. OMPCancellationPointDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  3111. : OMPExecutableDirective(OMPCancellationPointDirectiveClass,
  3112. llvm::omp::OMPD_cancellation_point, StartLoc,
  3113. EndLoc) {}
  3114. /// Build an empty directive.
  3115. explicit OMPCancellationPointDirective()
  3116. : OMPExecutableDirective(OMPCancellationPointDirectiveClass,
  3117. llvm::omp::OMPD_cancellation_point,
  3118. SourceLocation(), SourceLocation()) {}
  3119. /// Set cancel region for current cancellation point.
  3120. /// \param CR Cancellation region.
  3121. void setCancelRegion(OpenMPDirectiveKind CR) { CancelRegion = CR; }
  3122. public:
  3123. /// Creates directive.
  3124. ///
  3125. /// \param C AST context.
  3126. /// \param StartLoc Starting location of the directive kind.
  3127. /// \param EndLoc Ending Location of the directive.
  3128. ///
  3129. static OMPCancellationPointDirective *
  3130. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3131. OpenMPDirectiveKind CancelRegion);
  3132. /// Creates an empty directive.
  3133. ///
  3134. /// \param C AST context.
  3135. ///
  3136. static OMPCancellationPointDirective *CreateEmpty(const ASTContext &C,
  3137. EmptyShell);
  3138. /// Get cancellation region for the current cancellation point.
  3139. OpenMPDirectiveKind getCancelRegion() const { return CancelRegion; }
  3140. static bool classof(const Stmt *T) {
  3141. return T->getStmtClass() == OMPCancellationPointDirectiveClass;
  3142. }
  3143. };
  3144. /// This represents '#pragma omp cancel' directive.
  3145. ///
  3146. /// \code
  3147. /// #pragma omp cancel for
  3148. /// \endcode
  3149. ///
  3150. /// In this example a cancel is created for innermost 'for' region.
  3151. class OMPCancelDirective : public OMPExecutableDirective {
  3152. friend class ASTStmtReader;
  3153. friend class OMPExecutableDirective;
  3154. OpenMPDirectiveKind CancelRegion = llvm::omp::OMPD_unknown;
  3155. /// Build directive with the given start and end location.
  3156. ///
  3157. /// \param StartLoc Starting location of the directive kind.
  3158. /// \param EndLoc Ending location of the directive.
  3159. ///
  3160. OMPCancelDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  3161. : OMPExecutableDirective(OMPCancelDirectiveClass, llvm::omp::OMPD_cancel,
  3162. StartLoc, EndLoc) {}
  3163. /// Build an empty directive.
  3164. ///
  3165. explicit OMPCancelDirective()
  3166. : OMPExecutableDirective(OMPCancelDirectiveClass, llvm::omp::OMPD_cancel,
  3167. SourceLocation(), SourceLocation()) {}
  3168. /// Set cancel region for current cancellation point.
  3169. /// \param CR Cancellation region.
  3170. void setCancelRegion(OpenMPDirectiveKind CR) { CancelRegion = CR; }
  3171. public:
  3172. /// Creates directive.
  3173. ///
  3174. /// \param C AST context.
  3175. /// \param StartLoc Starting location of the directive kind.
  3176. /// \param EndLoc Ending Location of the directive.
  3177. /// \param Clauses List of clauses.
  3178. ///
  3179. static OMPCancelDirective *
  3180. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3181. ArrayRef<OMPClause *> Clauses, OpenMPDirectiveKind CancelRegion);
  3182. /// Creates an empty directive.
  3183. ///
  3184. /// \param C AST context.
  3185. /// \param NumClauses Number of clauses.
  3186. ///
  3187. static OMPCancelDirective *CreateEmpty(const ASTContext &C,
  3188. unsigned NumClauses, EmptyShell);
  3189. /// Get cancellation region for the current cancellation point.
  3190. OpenMPDirectiveKind getCancelRegion() const { return CancelRegion; }
  3191. static bool classof(const Stmt *T) {
  3192. return T->getStmtClass() == OMPCancelDirectiveClass;
  3193. }
  3194. };
  3195. /// This represents '#pragma omp taskloop' directive.
  3196. ///
  3197. /// \code
  3198. /// #pragma omp taskloop private(a,b) grainsize(val) num_tasks(num)
  3199. /// \endcode
  3200. /// In this example directive '#pragma omp taskloop' has clauses 'private'
  3201. /// with the variables 'a' and 'b', 'grainsize' with expression 'val' and
  3202. /// 'num_tasks' with expression 'num'.
  3203. ///
  3204. class OMPTaskLoopDirective : public OMPLoopDirective {
  3205. friend class ASTStmtReader;
  3206. friend class OMPExecutableDirective;
  3207. /// true if the construct has inner cancel directive.
  3208. bool HasCancel = false;
  3209. /// Build directive with the given start and end location.
  3210. ///
  3211. /// \param StartLoc Starting location of the directive kind.
  3212. /// \param EndLoc Ending location of the directive.
  3213. /// \param CollapsedNum Number of collapsed nested loops.
  3214. ///
  3215. OMPTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  3216. unsigned CollapsedNum)
  3217. : OMPLoopDirective(OMPTaskLoopDirectiveClass, llvm::omp::OMPD_taskloop,
  3218. StartLoc, EndLoc, CollapsedNum) {}
  3219. /// Build an empty directive.
  3220. ///
  3221. /// \param CollapsedNum Number of collapsed nested loops.
  3222. ///
  3223. explicit OMPTaskLoopDirective(unsigned CollapsedNum)
  3224. : OMPLoopDirective(OMPTaskLoopDirectiveClass, llvm::omp::OMPD_taskloop,
  3225. SourceLocation(), SourceLocation(), CollapsedNum) {}
  3226. /// Set cancel state.
  3227. void setHasCancel(bool Has) { HasCancel = Has; }
  3228. public:
  3229. /// Creates directive with a list of \a Clauses.
  3230. ///
  3231. /// \param C AST context.
  3232. /// \param StartLoc Starting location of the directive kind.
  3233. /// \param EndLoc Ending Location of the directive.
  3234. /// \param CollapsedNum Number of collapsed loops.
  3235. /// \param Clauses List of clauses.
  3236. /// \param AssociatedStmt Statement, associated with the directive.
  3237. /// \param Exprs Helper expressions for CodeGen.
  3238. /// \param HasCancel true if this directive has inner cancel directive.
  3239. ///
  3240. static OMPTaskLoopDirective *
  3241. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3242. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3243. Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel);
  3244. /// Creates an empty directive with the place
  3245. /// for \a NumClauses clauses.
  3246. ///
  3247. /// \param C AST context.
  3248. /// \param CollapsedNum Number of collapsed nested loops.
  3249. /// \param NumClauses Number of clauses.
  3250. ///
  3251. static OMPTaskLoopDirective *CreateEmpty(const ASTContext &C,
  3252. unsigned NumClauses,
  3253. unsigned CollapsedNum, EmptyShell);
  3254. /// Return true if current directive has inner cancel directive.
  3255. bool hasCancel() const { return HasCancel; }
  3256. static bool classof(const Stmt *T) {
  3257. return T->getStmtClass() == OMPTaskLoopDirectiveClass;
  3258. }
  3259. };
  3260. /// This represents '#pragma omp taskloop simd' directive.
  3261. ///
  3262. /// \code
  3263. /// #pragma omp taskloop simd private(a,b) grainsize(val) num_tasks(num)
  3264. /// \endcode
  3265. /// In this example directive '#pragma omp taskloop simd' has clauses 'private'
  3266. /// with the variables 'a' and 'b', 'grainsize' with expression 'val' and
  3267. /// 'num_tasks' with expression 'num'.
  3268. ///
  3269. class OMPTaskLoopSimdDirective : public OMPLoopDirective {
  3270. friend class ASTStmtReader;
  3271. friend class OMPExecutableDirective;
  3272. /// Build directive with the given start and end location.
  3273. ///
  3274. /// \param StartLoc Starting location of the directive kind.
  3275. /// \param EndLoc Ending location of the directive.
  3276. /// \param CollapsedNum Number of collapsed nested loops.
  3277. ///
  3278. OMPTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  3279. unsigned CollapsedNum)
  3280. : OMPLoopDirective(OMPTaskLoopSimdDirectiveClass,
  3281. llvm::omp::OMPD_taskloop_simd, StartLoc, EndLoc,
  3282. CollapsedNum) {}
  3283. /// Build an empty directive.
  3284. ///
  3285. /// \param CollapsedNum Number of collapsed nested loops.
  3286. ///
  3287. explicit OMPTaskLoopSimdDirective(unsigned CollapsedNum)
  3288. : OMPLoopDirective(OMPTaskLoopSimdDirectiveClass,
  3289. llvm::omp::OMPD_taskloop_simd, SourceLocation(),
  3290. SourceLocation(), CollapsedNum) {}
  3291. public:
  3292. /// Creates directive with a list of \a Clauses.
  3293. ///
  3294. /// \param C AST context.
  3295. /// \param StartLoc Starting location of the directive kind.
  3296. /// \param EndLoc Ending Location of the directive.
  3297. /// \param CollapsedNum Number of collapsed loops.
  3298. /// \param Clauses List of clauses.
  3299. /// \param AssociatedStmt Statement, associated with the directive.
  3300. /// \param Exprs Helper expressions for CodeGen.
  3301. ///
  3302. static OMPTaskLoopSimdDirective *
  3303. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3304. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3305. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  3306. /// Creates an empty directive with the place
  3307. /// for \a NumClauses clauses.
  3308. ///
  3309. /// \param C AST context.
  3310. /// \param CollapsedNum Number of collapsed nested loops.
  3311. /// \param NumClauses Number of clauses.
  3312. ///
  3313. static OMPTaskLoopSimdDirective *CreateEmpty(const ASTContext &C,
  3314. unsigned NumClauses,
  3315. unsigned CollapsedNum,
  3316. EmptyShell);
  3317. static bool classof(const Stmt *T) {
  3318. return T->getStmtClass() == OMPTaskLoopSimdDirectiveClass;
  3319. }
  3320. };
  3321. /// This represents '#pragma omp master taskloop' directive.
  3322. ///
  3323. /// \code
  3324. /// #pragma omp master taskloop private(a,b) grainsize(val) num_tasks(num)
  3325. /// \endcode
  3326. /// In this example directive '#pragma omp master taskloop' has clauses
  3327. /// 'private' with the variables 'a' and 'b', 'grainsize' with expression 'val'
  3328. /// and 'num_tasks' with expression 'num'.
  3329. ///
  3330. class OMPMasterTaskLoopDirective : public OMPLoopDirective {
  3331. friend class ASTStmtReader;
  3332. friend class OMPExecutableDirective;
  3333. /// true if the construct has inner cancel directive.
  3334. bool HasCancel = false;
  3335. /// Build directive with the given start and end location.
  3336. ///
  3337. /// \param StartLoc Starting location of the directive kind.
  3338. /// \param EndLoc Ending location of the directive.
  3339. /// \param CollapsedNum Number of collapsed nested loops.
  3340. ///
  3341. OMPMasterTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  3342. unsigned CollapsedNum)
  3343. : OMPLoopDirective(OMPMasterTaskLoopDirectiveClass,
  3344. llvm::omp::OMPD_master_taskloop, StartLoc, EndLoc,
  3345. CollapsedNum) {}
  3346. /// Build an empty directive.
  3347. ///
  3348. /// \param CollapsedNum Number of collapsed nested loops.
  3349. ///
  3350. explicit OMPMasterTaskLoopDirective(unsigned CollapsedNum)
  3351. : OMPLoopDirective(OMPMasterTaskLoopDirectiveClass,
  3352. llvm::omp::OMPD_master_taskloop, SourceLocation(),
  3353. SourceLocation(), CollapsedNum) {}
  3354. /// Set cancel state.
  3355. void setHasCancel(bool Has) { HasCancel = Has; }
  3356. public:
  3357. /// Creates directive with a list of \a Clauses.
  3358. ///
  3359. /// \param C AST context.
  3360. /// \param StartLoc Starting location of the directive kind.
  3361. /// \param EndLoc Ending Location of the directive.
  3362. /// \param CollapsedNum Number of collapsed loops.
  3363. /// \param Clauses List of clauses.
  3364. /// \param AssociatedStmt Statement, associated with the directive.
  3365. /// \param Exprs Helper expressions for CodeGen.
  3366. /// \param HasCancel true if this directive has inner cancel directive.
  3367. ///
  3368. static OMPMasterTaskLoopDirective *
  3369. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3370. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3371. Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel);
  3372. /// Creates an empty directive with the place
  3373. /// for \a NumClauses clauses.
  3374. ///
  3375. /// \param C AST context.
  3376. /// \param CollapsedNum Number of collapsed nested loops.
  3377. /// \param NumClauses Number of clauses.
  3378. ///
  3379. static OMPMasterTaskLoopDirective *CreateEmpty(const ASTContext &C,
  3380. unsigned NumClauses,
  3381. unsigned CollapsedNum,
  3382. EmptyShell);
  3383. /// Return true if current directive has inner cancel directive.
  3384. bool hasCancel() const { return HasCancel; }
  3385. static bool classof(const Stmt *T) {
  3386. return T->getStmtClass() == OMPMasterTaskLoopDirectiveClass;
  3387. }
  3388. };
  3389. /// This represents '#pragma omp master taskloop simd' directive.
  3390. ///
  3391. /// \code
  3392. /// #pragma omp master taskloop simd private(a,b) grainsize(val) num_tasks(num)
  3393. /// \endcode
  3394. /// In this example directive '#pragma omp master taskloop simd' has clauses
  3395. /// 'private' with the variables 'a' and 'b', 'grainsize' with expression 'val'
  3396. /// and 'num_tasks' with expression 'num'.
  3397. ///
  3398. class OMPMasterTaskLoopSimdDirective : public OMPLoopDirective {
  3399. friend class ASTStmtReader;
  3400. friend class OMPExecutableDirective;
  3401. /// Build directive with the given start and end location.
  3402. ///
  3403. /// \param StartLoc Starting location of the directive kind.
  3404. /// \param EndLoc Ending location of the directive.
  3405. /// \param CollapsedNum Number of collapsed nested loops.
  3406. ///
  3407. OMPMasterTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  3408. unsigned CollapsedNum)
  3409. : OMPLoopDirective(OMPMasterTaskLoopSimdDirectiveClass,
  3410. llvm::omp::OMPD_master_taskloop_simd, StartLoc, EndLoc,
  3411. CollapsedNum) {}
  3412. /// Build an empty directive.
  3413. ///
  3414. /// \param CollapsedNum Number of collapsed nested loops.
  3415. ///
  3416. explicit OMPMasterTaskLoopSimdDirective(unsigned CollapsedNum)
  3417. : OMPLoopDirective(OMPMasterTaskLoopSimdDirectiveClass,
  3418. llvm::omp::OMPD_master_taskloop_simd, SourceLocation(),
  3419. SourceLocation(), CollapsedNum) {}
  3420. public:
  3421. /// Creates directive with a list of \p Clauses.
  3422. ///
  3423. /// \param C AST context.
  3424. /// \param StartLoc Starting location of the directive kind.
  3425. /// \param EndLoc Ending Location of the directive.
  3426. /// \param CollapsedNum Number of collapsed loops.
  3427. /// \param Clauses List of clauses.
  3428. /// \param AssociatedStmt Statement, associated with the directive.
  3429. /// \param Exprs Helper expressions for CodeGen.
  3430. ///
  3431. static OMPMasterTaskLoopSimdDirective *
  3432. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3433. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3434. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  3435. /// Creates an empty directive with the place for \p NumClauses clauses.
  3436. ///
  3437. /// \param C AST context.
  3438. /// \param CollapsedNum Number of collapsed nested loops.
  3439. /// \param NumClauses Number of clauses.
  3440. ///
  3441. static OMPMasterTaskLoopSimdDirective *CreateEmpty(const ASTContext &C,
  3442. unsigned NumClauses,
  3443. unsigned CollapsedNum,
  3444. EmptyShell);
  3445. static bool classof(const Stmt *T) {
  3446. return T->getStmtClass() == OMPMasterTaskLoopSimdDirectiveClass;
  3447. }
  3448. };
  3449. /// This represents '#pragma omp parallel master taskloop' directive.
  3450. ///
  3451. /// \code
  3452. /// #pragma omp parallel master taskloop private(a,b) grainsize(val)
  3453. /// num_tasks(num)
  3454. /// \endcode
  3455. /// In this example directive '#pragma omp parallel master taskloop' has clauses
  3456. /// 'private' with the variables 'a' and 'b', 'grainsize' with expression 'val'
  3457. /// and 'num_tasks' with expression 'num'.
  3458. ///
  3459. class OMPParallelMasterTaskLoopDirective : public OMPLoopDirective {
  3460. friend class ASTStmtReader;
  3461. friend class OMPExecutableDirective;
  3462. /// true if the construct has inner cancel directive.
  3463. bool HasCancel = false;
  3464. /// Build directive with the given start and end location.
  3465. ///
  3466. /// \param StartLoc Starting location of the directive kind.
  3467. /// \param EndLoc Ending location of the directive.
  3468. /// \param CollapsedNum Number of collapsed nested loops.
  3469. ///
  3470. OMPParallelMasterTaskLoopDirective(SourceLocation StartLoc,
  3471. SourceLocation EndLoc,
  3472. unsigned CollapsedNum)
  3473. : OMPLoopDirective(OMPParallelMasterTaskLoopDirectiveClass,
  3474. llvm::omp::OMPD_parallel_master_taskloop, StartLoc,
  3475. EndLoc, CollapsedNum) {}
  3476. /// Build an empty directive.
  3477. ///
  3478. /// \param CollapsedNum Number of collapsed nested loops.
  3479. ///
  3480. explicit OMPParallelMasterTaskLoopDirective(unsigned CollapsedNum)
  3481. : OMPLoopDirective(OMPParallelMasterTaskLoopDirectiveClass,
  3482. llvm::omp::OMPD_parallel_master_taskloop,
  3483. SourceLocation(), SourceLocation(), CollapsedNum) {}
  3484. /// Set cancel state.
  3485. void setHasCancel(bool Has) { HasCancel = Has; }
  3486. public:
  3487. /// Creates directive with a list of \a Clauses.
  3488. ///
  3489. /// \param C AST context.
  3490. /// \param StartLoc Starting location of the directive kind.
  3491. /// \param EndLoc Ending Location of the directive.
  3492. /// \param CollapsedNum Number of collapsed loops.
  3493. /// \param Clauses List of clauses.
  3494. /// \param AssociatedStmt Statement, associated with the directive.
  3495. /// \param Exprs Helper expressions for CodeGen.
  3496. /// \param HasCancel true if this directive has inner cancel directive.
  3497. ///
  3498. static OMPParallelMasterTaskLoopDirective *
  3499. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3500. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3501. Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel);
  3502. /// Creates an empty directive with the place
  3503. /// for \a NumClauses clauses.
  3504. ///
  3505. /// \param C AST context.
  3506. /// \param CollapsedNum Number of collapsed nested loops.
  3507. /// \param NumClauses Number of clauses.
  3508. ///
  3509. static OMPParallelMasterTaskLoopDirective *CreateEmpty(const ASTContext &C,
  3510. unsigned NumClauses,
  3511. unsigned CollapsedNum,
  3512. EmptyShell);
  3513. /// Return true if current directive has inner cancel directive.
  3514. bool hasCancel() const { return HasCancel; }
  3515. static bool classof(const Stmt *T) {
  3516. return T->getStmtClass() == OMPParallelMasterTaskLoopDirectiveClass;
  3517. }
  3518. };
  3519. /// This represents '#pragma omp parallel master taskloop simd' directive.
  3520. ///
  3521. /// \code
  3522. /// #pragma omp parallel master taskloop simd private(a,b) grainsize(val)
  3523. /// num_tasks(num)
  3524. /// \endcode
  3525. /// In this example directive '#pragma omp parallel master taskloop simd' has
  3526. /// clauses 'private' with the variables 'a' and 'b', 'grainsize' with
  3527. /// expression 'val' and 'num_tasks' with expression 'num'.
  3528. ///
  3529. class OMPParallelMasterTaskLoopSimdDirective : public OMPLoopDirective {
  3530. friend class ASTStmtReader;
  3531. friend class OMPExecutableDirective;
  3532. /// Build directive with the given start and end location.
  3533. ///
  3534. /// \param StartLoc Starting location of the directive kind.
  3535. /// \param EndLoc Ending location of the directive.
  3536. /// \param CollapsedNum Number of collapsed nested loops.
  3537. ///
  3538. OMPParallelMasterTaskLoopSimdDirective(SourceLocation StartLoc,
  3539. SourceLocation EndLoc,
  3540. unsigned CollapsedNum)
  3541. : OMPLoopDirective(OMPParallelMasterTaskLoopSimdDirectiveClass,
  3542. llvm::omp::OMPD_parallel_master_taskloop_simd,
  3543. StartLoc, EndLoc, CollapsedNum) {}
  3544. /// Build an empty directive.
  3545. ///
  3546. /// \param CollapsedNum Number of collapsed nested loops.
  3547. ///
  3548. explicit OMPParallelMasterTaskLoopSimdDirective(unsigned CollapsedNum)
  3549. : OMPLoopDirective(OMPParallelMasterTaskLoopSimdDirectiveClass,
  3550. llvm::omp::OMPD_parallel_master_taskloop_simd,
  3551. SourceLocation(), SourceLocation(), CollapsedNum) {}
  3552. public:
  3553. /// Creates directive with a list of \p Clauses.
  3554. ///
  3555. /// \param C AST context.
  3556. /// \param StartLoc Starting location of the directive kind.
  3557. /// \param EndLoc Ending Location of the directive.
  3558. /// \param CollapsedNum Number of collapsed loops.
  3559. /// \param Clauses List of clauses.
  3560. /// \param AssociatedStmt Statement, associated with the directive.
  3561. /// \param Exprs Helper expressions for CodeGen.
  3562. ///
  3563. static OMPParallelMasterTaskLoopSimdDirective *
  3564. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3565. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3566. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  3567. /// Creates an empty directive with the place
  3568. /// for \a NumClauses clauses.
  3569. ///
  3570. /// \param C AST context.
  3571. /// \param CollapsedNum Number of collapsed nested loops.
  3572. /// \param NumClauses Number of clauses.
  3573. ///
  3574. static OMPParallelMasterTaskLoopSimdDirective *
  3575. CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  3576. EmptyShell);
  3577. static bool classof(const Stmt *T) {
  3578. return T->getStmtClass() == OMPParallelMasterTaskLoopSimdDirectiveClass;
  3579. }
  3580. };
  3581. /// This represents '#pragma omp distribute' directive.
  3582. ///
  3583. /// \code
  3584. /// #pragma omp distribute private(a,b)
  3585. /// \endcode
  3586. /// In this example directive '#pragma omp distribute' has clauses 'private'
  3587. /// with the variables 'a' and 'b'
  3588. ///
  3589. class OMPDistributeDirective : public OMPLoopDirective {
  3590. friend class ASTStmtReader;
  3591. friend class OMPExecutableDirective;
  3592. /// Build directive with the given start and end location.
  3593. ///
  3594. /// \param StartLoc Starting location of the directive kind.
  3595. /// \param EndLoc Ending location of the directive.
  3596. /// \param CollapsedNum Number of collapsed nested loops.
  3597. ///
  3598. OMPDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  3599. unsigned CollapsedNum)
  3600. : OMPLoopDirective(OMPDistributeDirectiveClass,
  3601. llvm::omp::OMPD_distribute, StartLoc, EndLoc,
  3602. CollapsedNum) {}
  3603. /// Build an empty directive.
  3604. ///
  3605. /// \param CollapsedNum Number of collapsed nested loops.
  3606. ///
  3607. explicit OMPDistributeDirective(unsigned CollapsedNum)
  3608. : OMPLoopDirective(OMPDistributeDirectiveClass,
  3609. llvm::omp::OMPD_distribute, SourceLocation(),
  3610. SourceLocation(), CollapsedNum) {}
  3611. public:
  3612. /// Creates directive with a list of \a Clauses.
  3613. ///
  3614. /// \param C AST context.
  3615. /// \param StartLoc Starting location of the directive kind.
  3616. /// \param EndLoc Ending Location of the directive.
  3617. /// \param CollapsedNum Number of collapsed loops.
  3618. /// \param Clauses List of clauses.
  3619. /// \param AssociatedStmt Statement, associated with the directive.
  3620. /// \param Exprs Helper expressions for CodeGen.
  3621. ///
  3622. static OMPDistributeDirective *
  3623. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3624. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3625. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  3626. /// Creates an empty directive with the place
  3627. /// for \a NumClauses clauses.
  3628. ///
  3629. /// \param C AST context.
  3630. /// \param CollapsedNum Number of collapsed nested loops.
  3631. /// \param NumClauses Number of clauses.
  3632. ///
  3633. static OMPDistributeDirective *CreateEmpty(const ASTContext &C,
  3634. unsigned NumClauses,
  3635. unsigned CollapsedNum, EmptyShell);
  3636. static bool classof(const Stmt *T) {
  3637. return T->getStmtClass() == OMPDistributeDirectiveClass;
  3638. }
  3639. };
  3640. /// This represents '#pragma omp target update' directive.
  3641. ///
  3642. /// \code
  3643. /// #pragma omp target update to(a) from(b) device(1)
  3644. /// \endcode
  3645. /// In this example directive '#pragma omp target update' has clause 'to' with
  3646. /// argument 'a', clause 'from' with argument 'b' and clause 'device' with
  3647. /// argument '1'.
  3648. ///
  3649. class OMPTargetUpdateDirective : public OMPExecutableDirective {
  3650. friend class ASTStmtReader;
  3651. friend class OMPExecutableDirective;
  3652. /// Build directive with the given start and end location.
  3653. ///
  3654. /// \param StartLoc Starting location of the directive kind.
  3655. /// \param EndLoc Ending Location of the directive.
  3656. ///
  3657. OMPTargetUpdateDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  3658. : OMPExecutableDirective(OMPTargetUpdateDirectiveClass,
  3659. llvm::omp::OMPD_target_update, StartLoc,
  3660. EndLoc) {}
  3661. /// Build an empty directive.
  3662. ///
  3663. explicit OMPTargetUpdateDirective()
  3664. : OMPExecutableDirective(OMPTargetUpdateDirectiveClass,
  3665. llvm::omp::OMPD_target_update, SourceLocation(),
  3666. SourceLocation()) {}
  3667. public:
  3668. /// Creates directive with a list of \a Clauses.
  3669. ///
  3670. /// \param C AST context.
  3671. /// \param StartLoc Starting location of the directive kind.
  3672. /// \param EndLoc Ending Location of the directive.
  3673. /// \param Clauses List of clauses.
  3674. /// \param AssociatedStmt Statement, associated with the directive.
  3675. ///
  3676. static OMPTargetUpdateDirective *
  3677. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3678. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  3679. /// Creates an empty directive with the place for \a NumClauses
  3680. /// clauses.
  3681. ///
  3682. /// \param C AST context.
  3683. /// \param NumClauses The number of clauses.
  3684. ///
  3685. static OMPTargetUpdateDirective *CreateEmpty(const ASTContext &C,
  3686. unsigned NumClauses, EmptyShell);
  3687. static bool classof(const Stmt *T) {
  3688. return T->getStmtClass() == OMPTargetUpdateDirectiveClass;
  3689. }
  3690. };
  3691. /// This represents '#pragma omp distribute parallel for' composite
  3692. /// directive.
  3693. ///
  3694. /// \code
  3695. /// #pragma omp distribute parallel for private(a,b)
  3696. /// \endcode
  3697. /// In this example directive '#pragma omp distribute parallel for' has clause
  3698. /// 'private' with the variables 'a' and 'b'
  3699. ///
  3700. class OMPDistributeParallelForDirective : public OMPLoopDirective {
  3701. friend class ASTStmtReader;
  3702. friend class OMPExecutableDirective;
  3703. /// true if the construct has inner cancel directive.
  3704. bool HasCancel = false;
  3705. /// Build directive with the given start and end location.
  3706. ///
  3707. /// \param StartLoc Starting location of the directive kind.
  3708. /// \param EndLoc Ending location of the directive.
  3709. /// \param CollapsedNum Number of collapsed nested loops.
  3710. ///
  3711. OMPDistributeParallelForDirective(SourceLocation StartLoc,
  3712. SourceLocation EndLoc,
  3713. unsigned CollapsedNum)
  3714. : OMPLoopDirective(OMPDistributeParallelForDirectiveClass,
  3715. llvm::omp::OMPD_distribute_parallel_for, StartLoc,
  3716. EndLoc, CollapsedNum) {}
  3717. /// Build an empty directive.
  3718. ///
  3719. /// \param CollapsedNum Number of collapsed nested loops.
  3720. ///
  3721. explicit OMPDistributeParallelForDirective(unsigned CollapsedNum)
  3722. : OMPLoopDirective(OMPDistributeParallelForDirectiveClass,
  3723. llvm::omp::OMPD_distribute_parallel_for,
  3724. SourceLocation(), SourceLocation(), CollapsedNum) {}
  3725. /// Sets special task reduction descriptor.
  3726. void setTaskReductionRefExpr(Expr *E) {
  3727. Data->getChildren()[numLoopChildren(
  3728. getLoopsNumber(), llvm::omp::OMPD_distribute_parallel_for)] = E;
  3729. }
  3730. /// Set cancel state.
  3731. void setHasCancel(bool Has) { HasCancel = Has; }
  3732. public:
  3733. /// Creates directive with a list of \a Clauses.
  3734. ///
  3735. /// \param C AST context.
  3736. /// \param StartLoc Starting location of the directive kind.
  3737. /// \param EndLoc Ending Location of the directive.
  3738. /// \param CollapsedNum Number of collapsed loops.
  3739. /// \param Clauses List of clauses.
  3740. /// \param AssociatedStmt Statement, associated with the directive.
  3741. /// \param Exprs Helper expressions for CodeGen.
  3742. /// \param TaskRedRef Task reduction special reference expression to handle
  3743. /// taskgroup descriptor.
  3744. /// \param HasCancel true if this directive has inner cancel directive.
  3745. ///
  3746. static OMPDistributeParallelForDirective *
  3747. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3748. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3749. Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef,
  3750. bool HasCancel);
  3751. /// Creates an empty directive with the place
  3752. /// for \a NumClauses clauses.
  3753. ///
  3754. /// \param C AST context.
  3755. /// \param CollapsedNum Number of collapsed nested loops.
  3756. /// \param NumClauses Number of clauses.
  3757. ///
  3758. static OMPDistributeParallelForDirective *CreateEmpty(const ASTContext &C,
  3759. unsigned NumClauses,
  3760. unsigned CollapsedNum,
  3761. EmptyShell);
  3762. /// Returns special task reduction reference expression.
  3763. Expr *getTaskReductionRefExpr() {
  3764. return cast_or_null<Expr>(Data->getChildren()[numLoopChildren(
  3765. getLoopsNumber(), llvm::omp::OMPD_distribute_parallel_for)]);
  3766. }
  3767. const Expr *getTaskReductionRefExpr() const {
  3768. return const_cast<OMPDistributeParallelForDirective *>(this)
  3769. ->getTaskReductionRefExpr();
  3770. }
  3771. /// Return true if current directive has inner cancel directive.
  3772. bool hasCancel() const { return HasCancel; }
  3773. static bool classof(const Stmt *T) {
  3774. return T->getStmtClass() == OMPDistributeParallelForDirectiveClass;
  3775. }
  3776. };
  3777. /// This represents '#pragma omp distribute parallel for simd' composite
  3778. /// directive.
  3779. ///
  3780. /// \code
  3781. /// #pragma omp distribute parallel for simd private(x)
  3782. /// \endcode
  3783. /// In this example directive '#pragma omp distribute parallel for simd' has
  3784. /// clause 'private' with the variables 'x'
  3785. ///
  3786. class OMPDistributeParallelForSimdDirective final : public OMPLoopDirective {
  3787. friend class ASTStmtReader;
  3788. friend class OMPExecutableDirective;
  3789. /// Build directive with the given start and end location.
  3790. ///
  3791. /// \param StartLoc Starting location of the directive kind.
  3792. /// \param EndLoc Ending location of the directive.
  3793. /// \param CollapsedNum Number of collapsed nested loops.
  3794. ///
  3795. OMPDistributeParallelForSimdDirective(SourceLocation StartLoc,
  3796. SourceLocation EndLoc,
  3797. unsigned CollapsedNum)
  3798. : OMPLoopDirective(OMPDistributeParallelForSimdDirectiveClass,
  3799. llvm::omp::OMPD_distribute_parallel_for_simd, StartLoc,
  3800. EndLoc, CollapsedNum) {}
  3801. /// Build an empty directive.
  3802. ///
  3803. /// \param CollapsedNum Number of collapsed nested loops.
  3804. ///
  3805. explicit OMPDistributeParallelForSimdDirective(unsigned CollapsedNum)
  3806. : OMPLoopDirective(OMPDistributeParallelForSimdDirectiveClass,
  3807. llvm::omp::OMPD_distribute_parallel_for_simd,
  3808. SourceLocation(), SourceLocation(), CollapsedNum) {}
  3809. public:
  3810. /// Creates directive with a list of \a Clauses.
  3811. ///
  3812. /// \param C AST context.
  3813. /// \param StartLoc Starting location of the directive kind.
  3814. /// \param EndLoc Ending Location of the directive.
  3815. /// \param CollapsedNum Number of collapsed loops.
  3816. /// \param Clauses List of clauses.
  3817. /// \param AssociatedStmt Statement, associated with the directive.
  3818. /// \param Exprs Helper expressions for CodeGen.
  3819. ///
  3820. static OMPDistributeParallelForSimdDirective *Create(
  3821. const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3822. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3823. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  3824. /// Creates an empty directive with the place for \a NumClauses clauses.
  3825. ///
  3826. /// \param C AST context.
  3827. /// \param CollapsedNum Number of collapsed nested loops.
  3828. /// \param NumClauses Number of clauses.
  3829. ///
  3830. static OMPDistributeParallelForSimdDirective *CreateEmpty(
  3831. const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  3832. EmptyShell);
  3833. static bool classof(const Stmt *T) {
  3834. return T->getStmtClass() == OMPDistributeParallelForSimdDirectiveClass;
  3835. }
  3836. };
  3837. /// This represents '#pragma omp distribute simd' composite directive.
  3838. ///
  3839. /// \code
  3840. /// #pragma omp distribute simd private(x)
  3841. /// \endcode
  3842. /// In this example directive '#pragma omp distribute simd' has clause
  3843. /// 'private' with the variables 'x'
  3844. ///
  3845. class OMPDistributeSimdDirective final : public OMPLoopDirective {
  3846. friend class ASTStmtReader;
  3847. friend class OMPExecutableDirective;
  3848. /// Build directive with the given start and end location.
  3849. ///
  3850. /// \param StartLoc Starting location of the directive kind.
  3851. /// \param EndLoc Ending location of the directive.
  3852. /// \param CollapsedNum Number of collapsed nested loops.
  3853. ///
  3854. OMPDistributeSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  3855. unsigned CollapsedNum)
  3856. : OMPLoopDirective(OMPDistributeSimdDirectiveClass,
  3857. llvm::omp::OMPD_distribute_simd, StartLoc, EndLoc,
  3858. CollapsedNum) {}
  3859. /// Build an empty directive.
  3860. ///
  3861. /// \param CollapsedNum Number of collapsed nested loops.
  3862. ///
  3863. explicit OMPDistributeSimdDirective(unsigned CollapsedNum)
  3864. : OMPLoopDirective(OMPDistributeSimdDirectiveClass,
  3865. llvm::omp::OMPD_distribute_simd, SourceLocation(),
  3866. SourceLocation(), CollapsedNum) {}
  3867. public:
  3868. /// Creates directive with a list of \a Clauses.
  3869. ///
  3870. /// \param C AST context.
  3871. /// \param StartLoc Starting location of the directive kind.
  3872. /// \param EndLoc Ending Location of the directive.
  3873. /// \param CollapsedNum Number of collapsed loops.
  3874. /// \param Clauses List of clauses.
  3875. /// \param AssociatedStmt Statement, associated with the directive.
  3876. /// \param Exprs Helper expressions for CodeGen.
  3877. ///
  3878. static OMPDistributeSimdDirective *
  3879. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3880. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3881. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  3882. /// Creates an empty directive with the place for \a NumClauses clauses.
  3883. ///
  3884. /// \param C AST context.
  3885. /// \param CollapsedNum Number of collapsed nested loops.
  3886. /// \param NumClauses Number of clauses.
  3887. ///
  3888. static OMPDistributeSimdDirective *CreateEmpty(const ASTContext &C,
  3889. unsigned NumClauses,
  3890. unsigned CollapsedNum,
  3891. EmptyShell);
  3892. static bool classof(const Stmt *T) {
  3893. return T->getStmtClass() == OMPDistributeSimdDirectiveClass;
  3894. }
  3895. };
  3896. /// This represents '#pragma omp target parallel for simd' directive.
  3897. ///
  3898. /// \code
  3899. /// #pragma omp target parallel for simd private(a) map(b) safelen(c)
  3900. /// \endcode
  3901. /// In this example directive '#pragma omp target parallel for simd' has clauses
  3902. /// 'private' with the variable 'a', 'map' with the variable 'b' and 'safelen'
  3903. /// with the variable 'c'.
  3904. ///
  3905. class OMPTargetParallelForSimdDirective final : public OMPLoopDirective {
  3906. friend class ASTStmtReader;
  3907. friend class OMPExecutableDirective;
  3908. /// Build directive with the given start and end location.
  3909. ///
  3910. /// \param StartLoc Starting location of the directive kind.
  3911. /// \param EndLoc Ending location of the directive.
  3912. /// \param CollapsedNum Number of collapsed nested loops.
  3913. ///
  3914. OMPTargetParallelForSimdDirective(SourceLocation StartLoc,
  3915. SourceLocation EndLoc,
  3916. unsigned CollapsedNum)
  3917. : OMPLoopDirective(OMPTargetParallelForSimdDirectiveClass,
  3918. llvm::omp::OMPD_target_parallel_for_simd, StartLoc,
  3919. EndLoc, CollapsedNum) {}
  3920. /// Build an empty directive.
  3921. ///
  3922. /// \param CollapsedNum Number of collapsed nested loops.
  3923. ///
  3924. explicit OMPTargetParallelForSimdDirective(unsigned CollapsedNum)
  3925. : OMPLoopDirective(OMPTargetParallelForSimdDirectiveClass,
  3926. llvm::omp::OMPD_target_parallel_for_simd,
  3927. SourceLocation(), SourceLocation(), CollapsedNum) {}
  3928. public:
  3929. /// Creates directive with a list of \a Clauses.
  3930. ///
  3931. /// \param C AST context.
  3932. /// \param StartLoc Starting location of the directive kind.
  3933. /// \param EndLoc Ending Location of the directive.
  3934. /// \param CollapsedNum Number of collapsed loops.
  3935. /// \param Clauses List of clauses.
  3936. /// \param AssociatedStmt Statement, associated with the directive.
  3937. /// \param Exprs Helper expressions for CodeGen.
  3938. ///
  3939. static OMPTargetParallelForSimdDirective *
  3940. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  3941. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  3942. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  3943. /// Creates an empty directive with the place for \a NumClauses clauses.
  3944. ///
  3945. /// \param C AST context.
  3946. /// \param CollapsedNum Number of collapsed nested loops.
  3947. /// \param NumClauses Number of clauses.
  3948. ///
  3949. static OMPTargetParallelForSimdDirective *CreateEmpty(const ASTContext &C,
  3950. unsigned NumClauses,
  3951. unsigned CollapsedNum,
  3952. EmptyShell);
  3953. static bool classof(const Stmt *T) {
  3954. return T->getStmtClass() == OMPTargetParallelForSimdDirectiveClass;
  3955. }
  3956. };
  3957. /// This represents '#pragma omp target simd' directive.
  3958. ///
  3959. /// \code
  3960. /// #pragma omp target simd private(a) map(b) safelen(c)
  3961. /// \endcode
  3962. /// In this example directive '#pragma omp target simd' has clauses 'private'
  3963. /// with the variable 'a', 'map' with the variable 'b' and 'safelen' with
  3964. /// the variable 'c'.
  3965. ///
  3966. class OMPTargetSimdDirective final : public OMPLoopDirective {
  3967. friend class ASTStmtReader;
  3968. friend class OMPExecutableDirective;
  3969. /// Build directive with the given start and end location.
  3970. ///
  3971. /// \param StartLoc Starting location of the directive kind.
  3972. /// \param EndLoc Ending location of the directive.
  3973. /// \param CollapsedNum Number of collapsed nested loops.
  3974. ///
  3975. OMPTargetSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  3976. unsigned CollapsedNum)
  3977. : OMPLoopDirective(OMPTargetSimdDirectiveClass,
  3978. llvm::omp::OMPD_target_simd, StartLoc, EndLoc,
  3979. CollapsedNum) {}
  3980. /// Build an empty directive.
  3981. ///
  3982. /// \param CollapsedNum Number of collapsed nested loops.
  3983. ///
  3984. explicit OMPTargetSimdDirective(unsigned CollapsedNum)
  3985. : OMPLoopDirective(OMPTargetSimdDirectiveClass,
  3986. llvm::omp::OMPD_target_simd, SourceLocation(),
  3987. SourceLocation(), CollapsedNum) {}
  3988. public:
  3989. /// Creates directive with a list of \a Clauses.
  3990. ///
  3991. /// \param C AST context.
  3992. /// \param StartLoc Starting location of the directive kind.
  3993. /// \param EndLoc Ending Location of the directive.
  3994. /// \param CollapsedNum Number of collapsed loops.
  3995. /// \param Clauses List of clauses.
  3996. /// \param AssociatedStmt Statement, associated with the directive.
  3997. /// \param Exprs Helper expressions for CodeGen.
  3998. ///
  3999. static OMPTargetSimdDirective *
  4000. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4001. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4002. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  4003. /// Creates an empty directive with the place for \a NumClauses clauses.
  4004. ///
  4005. /// \param C AST context.
  4006. /// \param CollapsedNum Number of collapsed nested loops.
  4007. /// \param NumClauses Number of clauses.
  4008. ///
  4009. static OMPTargetSimdDirective *CreateEmpty(const ASTContext &C,
  4010. unsigned NumClauses,
  4011. unsigned CollapsedNum,
  4012. EmptyShell);
  4013. static bool classof(const Stmt *T) {
  4014. return T->getStmtClass() == OMPTargetSimdDirectiveClass;
  4015. }
  4016. };
  4017. /// This represents '#pragma omp teams distribute' directive.
  4018. ///
  4019. /// \code
  4020. /// #pragma omp teams distribute private(a,b)
  4021. /// \endcode
  4022. /// In this example directive '#pragma omp teams distribute' has clauses
  4023. /// 'private' with the variables 'a' and 'b'
  4024. ///
  4025. class OMPTeamsDistributeDirective final : public OMPLoopDirective {
  4026. friend class ASTStmtReader;
  4027. friend class OMPExecutableDirective;
  4028. /// Build directive with the given start and end location.
  4029. ///
  4030. /// \param StartLoc Starting location of the directive kind.
  4031. /// \param EndLoc Ending location of the directive.
  4032. /// \param CollapsedNum Number of collapsed nested loops.
  4033. ///
  4034. OMPTeamsDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  4035. unsigned CollapsedNum)
  4036. : OMPLoopDirective(OMPTeamsDistributeDirectiveClass,
  4037. llvm::omp::OMPD_teams_distribute, StartLoc, EndLoc,
  4038. CollapsedNum) {}
  4039. /// Build an empty directive.
  4040. ///
  4041. /// \param CollapsedNum Number of collapsed nested loops.
  4042. ///
  4043. explicit OMPTeamsDistributeDirective(unsigned CollapsedNum)
  4044. : OMPLoopDirective(OMPTeamsDistributeDirectiveClass,
  4045. llvm::omp::OMPD_teams_distribute, SourceLocation(),
  4046. SourceLocation(), CollapsedNum) {}
  4047. public:
  4048. /// Creates directive with a list of \a Clauses.
  4049. ///
  4050. /// \param C AST context.
  4051. /// \param StartLoc Starting location of the directive kind.
  4052. /// \param EndLoc Ending Location of the directive.
  4053. /// \param CollapsedNum Number of collapsed loops.
  4054. /// \param Clauses List of clauses.
  4055. /// \param AssociatedStmt Statement, associated with the directive.
  4056. /// \param Exprs Helper expressions for CodeGen.
  4057. ///
  4058. static OMPTeamsDistributeDirective *
  4059. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4060. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4061. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  4062. /// Creates an empty directive with the place for \a NumClauses clauses.
  4063. ///
  4064. /// \param C AST context.
  4065. /// \param CollapsedNum Number of collapsed nested loops.
  4066. /// \param NumClauses Number of clauses.
  4067. ///
  4068. static OMPTeamsDistributeDirective *CreateEmpty(const ASTContext &C,
  4069. unsigned NumClauses,
  4070. unsigned CollapsedNum,
  4071. EmptyShell);
  4072. static bool classof(const Stmt *T) {
  4073. return T->getStmtClass() == OMPTeamsDistributeDirectiveClass;
  4074. }
  4075. };
  4076. /// This represents '#pragma omp teams distribute simd'
  4077. /// combined directive.
  4078. ///
  4079. /// \code
  4080. /// #pragma omp teams distribute simd private(a,b)
  4081. /// \endcode
  4082. /// In this example directive '#pragma omp teams distribute simd'
  4083. /// has clause 'private' with the variables 'a' and 'b'
  4084. ///
  4085. class OMPTeamsDistributeSimdDirective final : public OMPLoopDirective {
  4086. friend class ASTStmtReader;
  4087. friend class OMPExecutableDirective;
  4088. /// Build directive with the given start and end location.
  4089. ///
  4090. /// \param StartLoc Starting location of the directive kind.
  4091. /// \param EndLoc Ending location of the directive.
  4092. /// \param CollapsedNum Number of collapsed nested loops.
  4093. ///
  4094. OMPTeamsDistributeSimdDirective(SourceLocation StartLoc,
  4095. SourceLocation EndLoc, unsigned CollapsedNum)
  4096. : OMPLoopDirective(OMPTeamsDistributeSimdDirectiveClass,
  4097. llvm::omp::OMPD_teams_distribute_simd, StartLoc,
  4098. EndLoc, CollapsedNum) {}
  4099. /// Build an empty directive.
  4100. ///
  4101. /// \param CollapsedNum Number of collapsed nested loops.
  4102. ///
  4103. explicit OMPTeamsDistributeSimdDirective(unsigned CollapsedNum)
  4104. : OMPLoopDirective(OMPTeamsDistributeSimdDirectiveClass,
  4105. llvm::omp::OMPD_teams_distribute_simd,
  4106. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4107. public:
  4108. /// Creates directive with a list of \a Clauses.
  4109. ///
  4110. /// \param C AST context.
  4111. /// \param StartLoc Starting location of the directive kind.
  4112. /// \param EndLoc Ending Location of the directive.
  4113. /// \param CollapsedNum Number of collapsed loops.
  4114. /// \param Clauses List of clauses.
  4115. /// \param AssociatedStmt Statement, associated with the directive.
  4116. /// \param Exprs Helper expressions for CodeGen.
  4117. ///
  4118. static OMPTeamsDistributeSimdDirective *
  4119. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4120. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4121. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  4122. /// Creates an empty directive with the place
  4123. /// for \a NumClauses clauses.
  4124. ///
  4125. /// \param C AST context.
  4126. /// \param CollapsedNum Number of collapsed nested loops.
  4127. /// \param NumClauses Number of clauses.
  4128. ///
  4129. static OMPTeamsDistributeSimdDirective *CreateEmpty(const ASTContext &C,
  4130. unsigned NumClauses,
  4131. unsigned CollapsedNum,
  4132. EmptyShell);
  4133. static bool classof(const Stmt *T) {
  4134. return T->getStmtClass() == OMPTeamsDistributeSimdDirectiveClass;
  4135. }
  4136. };
  4137. /// This represents '#pragma omp teams distribute parallel for simd' composite
  4138. /// directive.
  4139. ///
  4140. /// \code
  4141. /// #pragma omp teams distribute parallel for simd private(x)
  4142. /// \endcode
  4143. /// In this example directive '#pragma omp teams distribute parallel for simd'
  4144. /// has clause 'private' with the variables 'x'
  4145. ///
  4146. class OMPTeamsDistributeParallelForSimdDirective final
  4147. : public OMPLoopDirective {
  4148. friend class ASTStmtReader;
  4149. friend class OMPExecutableDirective;
  4150. /// Build directive with the given start and end location.
  4151. ///
  4152. /// \param StartLoc Starting location of the directive kind.
  4153. /// \param EndLoc Ending location of the directive.
  4154. /// \param CollapsedNum Number of collapsed nested loops.
  4155. ///
  4156. OMPTeamsDistributeParallelForSimdDirective(SourceLocation StartLoc,
  4157. SourceLocation EndLoc,
  4158. unsigned CollapsedNum)
  4159. : OMPLoopDirective(OMPTeamsDistributeParallelForSimdDirectiveClass,
  4160. llvm::omp::OMPD_teams_distribute_parallel_for_simd,
  4161. StartLoc, EndLoc, CollapsedNum) {}
  4162. /// Build an empty directive.
  4163. ///
  4164. /// \param CollapsedNum Number of collapsed nested loops.
  4165. ///
  4166. explicit OMPTeamsDistributeParallelForSimdDirective(unsigned CollapsedNum)
  4167. : OMPLoopDirective(OMPTeamsDistributeParallelForSimdDirectiveClass,
  4168. llvm::omp::OMPD_teams_distribute_parallel_for_simd,
  4169. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4170. public:
  4171. /// Creates directive with a list of \a Clauses.
  4172. ///
  4173. /// \param C AST context.
  4174. /// \param StartLoc Starting location of the directive kind.
  4175. /// \param EndLoc Ending Location of the directive.
  4176. /// \param CollapsedNum Number of collapsed loops.
  4177. /// \param Clauses List of clauses.
  4178. /// \param AssociatedStmt Statement, associated with the directive.
  4179. /// \param Exprs Helper expressions for CodeGen.
  4180. ///
  4181. static OMPTeamsDistributeParallelForSimdDirective *
  4182. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4183. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4184. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  4185. /// Creates an empty directive with the place for \a NumClauses clauses.
  4186. ///
  4187. /// \param C AST context.
  4188. /// \param CollapsedNum Number of collapsed nested loops.
  4189. /// \param NumClauses Number of clauses.
  4190. ///
  4191. static OMPTeamsDistributeParallelForSimdDirective *
  4192. CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  4193. EmptyShell);
  4194. static bool classof(const Stmt *T) {
  4195. return T->getStmtClass() == OMPTeamsDistributeParallelForSimdDirectiveClass;
  4196. }
  4197. };
  4198. /// This represents '#pragma omp teams distribute parallel for' composite
  4199. /// directive.
  4200. ///
  4201. /// \code
  4202. /// #pragma omp teams distribute parallel for private(x)
  4203. /// \endcode
  4204. /// In this example directive '#pragma omp teams distribute parallel for'
  4205. /// has clause 'private' with the variables 'x'
  4206. ///
  4207. class OMPTeamsDistributeParallelForDirective final : public OMPLoopDirective {
  4208. friend class ASTStmtReader;
  4209. friend class OMPExecutableDirective;
  4210. /// true if the construct has inner cancel directive.
  4211. bool HasCancel = false;
  4212. /// Build directive with the given start and end location.
  4213. ///
  4214. /// \param StartLoc Starting location of the directive kind.
  4215. /// \param EndLoc Ending location of the directive.
  4216. /// \param CollapsedNum Number of collapsed nested loops.
  4217. ///
  4218. OMPTeamsDistributeParallelForDirective(SourceLocation StartLoc,
  4219. SourceLocation EndLoc,
  4220. unsigned CollapsedNum)
  4221. : OMPLoopDirective(OMPTeamsDistributeParallelForDirectiveClass,
  4222. llvm::omp::OMPD_teams_distribute_parallel_for,
  4223. StartLoc, EndLoc, CollapsedNum) {}
  4224. /// Build an empty directive.
  4225. ///
  4226. /// \param CollapsedNum Number of collapsed nested loops.
  4227. ///
  4228. explicit OMPTeamsDistributeParallelForDirective(unsigned CollapsedNum)
  4229. : OMPLoopDirective(OMPTeamsDistributeParallelForDirectiveClass,
  4230. llvm::omp::OMPD_teams_distribute_parallel_for,
  4231. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4232. /// Sets special task reduction descriptor.
  4233. void setTaskReductionRefExpr(Expr *E) {
  4234. Data->getChildren()[numLoopChildren(
  4235. getLoopsNumber(), llvm::omp::OMPD_teams_distribute_parallel_for)] = E;
  4236. }
  4237. /// Set cancel state.
  4238. void setHasCancel(bool Has) { HasCancel = Has; }
  4239. public:
  4240. /// Creates directive with a list of \a Clauses.
  4241. ///
  4242. /// \param C AST context.
  4243. /// \param StartLoc Starting location of the directive kind.
  4244. /// \param EndLoc Ending Location of the directive.
  4245. /// \param CollapsedNum Number of collapsed loops.
  4246. /// \param Clauses List of clauses.
  4247. /// \param AssociatedStmt Statement, associated with the directive.
  4248. /// \param Exprs Helper expressions for CodeGen.
  4249. /// \param TaskRedRef Task reduction special reference expression to handle
  4250. /// taskgroup descriptor.
  4251. /// \param HasCancel true if this directive has inner cancel directive.
  4252. ///
  4253. static OMPTeamsDistributeParallelForDirective *
  4254. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4255. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4256. Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef,
  4257. bool HasCancel);
  4258. /// Creates an empty directive with the place for \a NumClauses clauses.
  4259. ///
  4260. /// \param C AST context.
  4261. /// \param CollapsedNum Number of collapsed nested loops.
  4262. /// \param NumClauses Number of clauses.
  4263. ///
  4264. static OMPTeamsDistributeParallelForDirective *
  4265. CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  4266. EmptyShell);
  4267. /// Returns special task reduction reference expression.
  4268. Expr *getTaskReductionRefExpr() {
  4269. return cast_or_null<Expr>(Data->getChildren()[numLoopChildren(
  4270. getLoopsNumber(), llvm::omp::OMPD_teams_distribute_parallel_for)]);
  4271. }
  4272. const Expr *getTaskReductionRefExpr() const {
  4273. return const_cast<OMPTeamsDistributeParallelForDirective *>(this)
  4274. ->getTaskReductionRefExpr();
  4275. }
  4276. /// Return true if current directive has inner cancel directive.
  4277. bool hasCancel() const { return HasCancel; }
  4278. static bool classof(const Stmt *T) {
  4279. return T->getStmtClass() == OMPTeamsDistributeParallelForDirectiveClass;
  4280. }
  4281. };
  4282. /// This represents '#pragma omp target teams' directive.
  4283. ///
  4284. /// \code
  4285. /// #pragma omp target teams if(a>0)
  4286. /// \endcode
  4287. /// In this example directive '#pragma omp target teams' has clause 'if' with
  4288. /// condition 'a>0'.
  4289. ///
  4290. class OMPTargetTeamsDirective final : public OMPExecutableDirective {
  4291. friend class ASTStmtReader;
  4292. friend class OMPExecutableDirective;
  4293. /// Build directive with the given start and end location.
  4294. ///
  4295. /// \param StartLoc Starting location of the directive kind.
  4296. /// \param EndLoc Ending location of the directive.
  4297. ///
  4298. OMPTargetTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  4299. : OMPExecutableDirective(OMPTargetTeamsDirectiveClass,
  4300. llvm::omp::OMPD_target_teams, StartLoc, EndLoc) {
  4301. }
  4302. /// Build an empty directive.
  4303. ///
  4304. explicit OMPTargetTeamsDirective()
  4305. : OMPExecutableDirective(OMPTargetTeamsDirectiveClass,
  4306. llvm::omp::OMPD_target_teams, SourceLocation(),
  4307. SourceLocation()) {}
  4308. public:
  4309. /// Creates directive with a list of \a Clauses.
  4310. ///
  4311. /// \param C AST context.
  4312. /// \param StartLoc Starting location of the directive kind.
  4313. /// \param EndLoc Ending Location of the directive.
  4314. /// \param Clauses List of clauses.
  4315. /// \param AssociatedStmt Statement, associated with the directive.
  4316. ///
  4317. static OMPTargetTeamsDirective *Create(const ASTContext &C,
  4318. SourceLocation StartLoc,
  4319. SourceLocation EndLoc,
  4320. ArrayRef<OMPClause *> Clauses,
  4321. Stmt *AssociatedStmt);
  4322. /// Creates an empty directive with the place for \a NumClauses clauses.
  4323. ///
  4324. /// \param C AST context.
  4325. /// \param NumClauses Number of clauses.
  4326. ///
  4327. static OMPTargetTeamsDirective *CreateEmpty(const ASTContext &C,
  4328. unsigned NumClauses, EmptyShell);
  4329. static bool classof(const Stmt *T) {
  4330. return T->getStmtClass() == OMPTargetTeamsDirectiveClass;
  4331. }
  4332. };
  4333. /// This represents '#pragma omp target teams distribute' combined directive.
  4334. ///
  4335. /// \code
  4336. /// #pragma omp target teams distribute private(x)
  4337. /// \endcode
  4338. /// In this example directive '#pragma omp target teams distribute' has clause
  4339. /// 'private' with the variables 'x'
  4340. ///
  4341. class OMPTargetTeamsDistributeDirective final : public OMPLoopDirective {
  4342. friend class ASTStmtReader;
  4343. friend class OMPExecutableDirective;
  4344. /// Build directive with the given start and end location.
  4345. ///
  4346. /// \param StartLoc Starting location of the directive kind.
  4347. /// \param EndLoc Ending location of the directive.
  4348. /// \param CollapsedNum Number of collapsed nested loops.
  4349. ///
  4350. OMPTargetTeamsDistributeDirective(SourceLocation StartLoc,
  4351. SourceLocation EndLoc,
  4352. unsigned CollapsedNum)
  4353. : OMPLoopDirective(OMPTargetTeamsDistributeDirectiveClass,
  4354. llvm::omp::OMPD_target_teams_distribute, StartLoc,
  4355. EndLoc, CollapsedNum) {}
  4356. /// Build an empty directive.
  4357. ///
  4358. /// \param CollapsedNum Number of collapsed nested loops.
  4359. ///
  4360. explicit OMPTargetTeamsDistributeDirective(unsigned CollapsedNum)
  4361. : OMPLoopDirective(OMPTargetTeamsDistributeDirectiveClass,
  4362. llvm::omp::OMPD_target_teams_distribute,
  4363. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4364. public:
  4365. /// Creates directive with a list of \a Clauses.
  4366. ///
  4367. /// \param C AST context.
  4368. /// \param StartLoc Starting location of the directive kind.
  4369. /// \param EndLoc Ending Location of the directive.
  4370. /// \param CollapsedNum Number of collapsed loops.
  4371. /// \param Clauses List of clauses.
  4372. /// \param AssociatedStmt Statement, associated with the directive.
  4373. /// \param Exprs Helper expressions for CodeGen.
  4374. ///
  4375. static OMPTargetTeamsDistributeDirective *
  4376. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4377. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4378. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  4379. /// Creates an empty directive with the place for \a NumClauses clauses.
  4380. ///
  4381. /// \param C AST context.
  4382. /// \param CollapsedNum Number of collapsed nested loops.
  4383. /// \param NumClauses Number of clauses.
  4384. ///
  4385. static OMPTargetTeamsDistributeDirective *
  4386. CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  4387. EmptyShell);
  4388. static bool classof(const Stmt *T) {
  4389. return T->getStmtClass() == OMPTargetTeamsDistributeDirectiveClass;
  4390. }
  4391. };
  4392. /// This represents '#pragma omp target teams distribute parallel for' combined
  4393. /// directive.
  4394. ///
  4395. /// \code
  4396. /// #pragma omp target teams distribute parallel for private(x)
  4397. /// \endcode
  4398. /// In this example directive '#pragma omp target teams distribute parallel
  4399. /// for' has clause 'private' with the variables 'x'
  4400. ///
  4401. class OMPTargetTeamsDistributeParallelForDirective final
  4402. : public OMPLoopDirective {
  4403. friend class ASTStmtReader;
  4404. friend class OMPExecutableDirective;
  4405. /// true if the construct has inner cancel directive.
  4406. bool HasCancel = false;
  4407. /// Build directive with the given start and end location.
  4408. ///
  4409. /// \param StartLoc Starting location of the directive kind.
  4410. /// \param EndLoc Ending location of the directive.
  4411. /// \param CollapsedNum Number of collapsed nested loops.
  4412. ///
  4413. OMPTargetTeamsDistributeParallelForDirective(SourceLocation StartLoc,
  4414. SourceLocation EndLoc,
  4415. unsigned CollapsedNum)
  4416. : OMPLoopDirective(OMPTargetTeamsDistributeParallelForDirectiveClass,
  4417. llvm::omp::OMPD_target_teams_distribute_parallel_for,
  4418. StartLoc, EndLoc, CollapsedNum) {}
  4419. /// Build an empty directive.
  4420. ///
  4421. /// \param CollapsedNum Number of collapsed nested loops.
  4422. ///
  4423. explicit OMPTargetTeamsDistributeParallelForDirective(unsigned CollapsedNum)
  4424. : OMPLoopDirective(OMPTargetTeamsDistributeParallelForDirectiveClass,
  4425. llvm::omp::OMPD_target_teams_distribute_parallel_for,
  4426. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4427. /// Sets special task reduction descriptor.
  4428. void setTaskReductionRefExpr(Expr *E) {
  4429. Data->getChildren()[numLoopChildren(
  4430. getLoopsNumber(),
  4431. llvm::omp::OMPD_target_teams_distribute_parallel_for)] = E;
  4432. }
  4433. /// Set cancel state.
  4434. void setHasCancel(bool Has) { HasCancel = Has; }
  4435. public:
  4436. /// Creates directive with a list of \a Clauses.
  4437. ///
  4438. /// \param C AST context.
  4439. /// \param StartLoc Starting location of the directive kind.
  4440. /// \param EndLoc Ending Location of the directive.
  4441. /// \param CollapsedNum Number of collapsed loops.
  4442. /// \param Clauses List of clauses.
  4443. /// \param AssociatedStmt Statement, associated with the directive.
  4444. /// \param Exprs Helper expressions for CodeGen.
  4445. /// \param TaskRedRef Task reduction special reference expression to handle
  4446. /// taskgroup descriptor.
  4447. /// \param HasCancel true if this directive has inner cancel directive.
  4448. ///
  4449. static OMPTargetTeamsDistributeParallelForDirective *
  4450. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4451. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4452. Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef,
  4453. bool HasCancel);
  4454. /// Creates an empty directive with the place for \a NumClauses clauses.
  4455. ///
  4456. /// \param C AST context.
  4457. /// \param CollapsedNum Number of collapsed nested loops.
  4458. /// \param NumClauses Number of clauses.
  4459. ///
  4460. static OMPTargetTeamsDistributeParallelForDirective *
  4461. CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  4462. EmptyShell);
  4463. /// Returns special task reduction reference expression.
  4464. Expr *getTaskReductionRefExpr() {
  4465. return cast_or_null<Expr>(Data->getChildren()[numLoopChildren(
  4466. getLoopsNumber(),
  4467. llvm::omp::OMPD_target_teams_distribute_parallel_for)]);
  4468. }
  4469. const Expr *getTaskReductionRefExpr() const {
  4470. return const_cast<OMPTargetTeamsDistributeParallelForDirective *>(this)
  4471. ->getTaskReductionRefExpr();
  4472. }
  4473. /// Return true if current directive has inner cancel directive.
  4474. bool hasCancel() const { return HasCancel; }
  4475. static bool classof(const Stmt *T) {
  4476. return T->getStmtClass() ==
  4477. OMPTargetTeamsDistributeParallelForDirectiveClass;
  4478. }
  4479. };
  4480. /// This represents '#pragma omp target teams distribute parallel for simd'
  4481. /// combined directive.
  4482. ///
  4483. /// \code
  4484. /// #pragma omp target teams distribute parallel for simd private(x)
  4485. /// \endcode
  4486. /// In this example directive '#pragma omp target teams distribute parallel
  4487. /// for simd' has clause 'private' with the variables 'x'
  4488. ///
  4489. class OMPTargetTeamsDistributeParallelForSimdDirective final
  4490. : public OMPLoopDirective {
  4491. friend class ASTStmtReader;
  4492. friend class OMPExecutableDirective;
  4493. /// Build directive with the given start and end location.
  4494. ///
  4495. /// \param StartLoc Starting location of the directive kind.
  4496. /// \param EndLoc Ending location of the directive.
  4497. /// \param CollapsedNum Number of collapsed nested loops.
  4498. ///
  4499. OMPTargetTeamsDistributeParallelForSimdDirective(SourceLocation StartLoc,
  4500. SourceLocation EndLoc,
  4501. unsigned CollapsedNum)
  4502. : OMPLoopDirective(
  4503. OMPTargetTeamsDistributeParallelForSimdDirectiveClass,
  4504. llvm::omp::OMPD_target_teams_distribute_parallel_for_simd, StartLoc,
  4505. EndLoc, CollapsedNum) {}
  4506. /// Build an empty directive.
  4507. ///
  4508. /// \param CollapsedNum Number of collapsed nested loops.
  4509. ///
  4510. explicit OMPTargetTeamsDistributeParallelForSimdDirective(
  4511. unsigned CollapsedNum)
  4512. : OMPLoopDirective(
  4513. OMPTargetTeamsDistributeParallelForSimdDirectiveClass,
  4514. llvm::omp::OMPD_target_teams_distribute_parallel_for_simd,
  4515. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4516. public:
  4517. /// Creates directive with a list of \a Clauses.
  4518. ///
  4519. /// \param C AST context.
  4520. /// \param StartLoc Starting location of the directive kind.
  4521. /// \param EndLoc Ending Location of the directive.
  4522. /// \param CollapsedNum Number of collapsed loops.
  4523. /// \param Clauses List of clauses.
  4524. /// \param AssociatedStmt Statement, associated with the directive.
  4525. /// \param Exprs Helper expressions for CodeGen.
  4526. ///
  4527. static OMPTargetTeamsDistributeParallelForSimdDirective *
  4528. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4529. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4530. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  4531. /// Creates an empty directive with the place for \a NumClauses clauses.
  4532. ///
  4533. /// \param C AST context.
  4534. /// \param CollapsedNum Number of collapsed nested loops.
  4535. /// \param NumClauses Number of clauses.
  4536. ///
  4537. static OMPTargetTeamsDistributeParallelForSimdDirective *
  4538. CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  4539. EmptyShell);
  4540. static bool classof(const Stmt *T) {
  4541. return T->getStmtClass() ==
  4542. OMPTargetTeamsDistributeParallelForSimdDirectiveClass;
  4543. }
  4544. };
  4545. /// This represents '#pragma omp target teams distribute simd' combined
  4546. /// directive.
  4547. ///
  4548. /// \code
  4549. /// #pragma omp target teams distribute simd private(x)
  4550. /// \endcode
  4551. /// In this example directive '#pragma omp target teams distribute simd'
  4552. /// has clause 'private' with the variables 'x'
  4553. ///
  4554. class OMPTargetTeamsDistributeSimdDirective final : public OMPLoopDirective {
  4555. friend class ASTStmtReader;
  4556. friend class OMPExecutableDirective;
  4557. /// Build directive with the given start and end location.
  4558. ///
  4559. /// \param StartLoc Starting location of the directive kind.
  4560. /// \param EndLoc Ending location of the directive.
  4561. /// \param CollapsedNum Number of collapsed nested loops.
  4562. ///
  4563. OMPTargetTeamsDistributeSimdDirective(SourceLocation StartLoc,
  4564. SourceLocation EndLoc,
  4565. unsigned CollapsedNum)
  4566. : OMPLoopDirective(OMPTargetTeamsDistributeSimdDirectiveClass,
  4567. llvm::omp::OMPD_target_teams_distribute_simd, StartLoc,
  4568. EndLoc, CollapsedNum) {}
  4569. /// Build an empty directive.
  4570. ///
  4571. /// \param CollapsedNum Number of collapsed nested loops.
  4572. ///
  4573. explicit OMPTargetTeamsDistributeSimdDirective(unsigned CollapsedNum)
  4574. : OMPLoopDirective(OMPTargetTeamsDistributeSimdDirectiveClass,
  4575. llvm::omp::OMPD_target_teams_distribute_simd,
  4576. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4577. public:
  4578. /// Creates directive with a list of \a Clauses.
  4579. ///
  4580. /// \param C AST context.
  4581. /// \param StartLoc Starting location of the directive kind.
  4582. /// \param EndLoc Ending Location of the directive.
  4583. /// \param CollapsedNum Number of collapsed loops.
  4584. /// \param Clauses List of clauses.
  4585. /// \param AssociatedStmt Statement, associated with the directive.
  4586. /// \param Exprs Helper expressions for CodeGen.
  4587. ///
  4588. static OMPTargetTeamsDistributeSimdDirective *
  4589. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4590. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  4591. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  4592. /// Creates an empty directive with the place for \a NumClauses clauses.
  4593. ///
  4594. /// \param C AST context.
  4595. /// \param CollapsedNum Number of collapsed nested loops.
  4596. /// \param NumClauses Number of clauses.
  4597. ///
  4598. static OMPTargetTeamsDistributeSimdDirective *
  4599. CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum,
  4600. EmptyShell);
  4601. static bool classof(const Stmt *T) {
  4602. return T->getStmtClass() == OMPTargetTeamsDistributeSimdDirectiveClass;
  4603. }
  4604. };
  4605. /// This represents the '#pragma omp tile' loop transformation directive.
  4606. class OMPTileDirective final : public OMPLoopTransformationDirective {
  4607. friend class ASTStmtReader;
  4608. friend class OMPExecutableDirective;
  4609. /// Default list of offsets.
  4610. enum {
  4611. PreInitsOffset = 0,
  4612. TransformedStmtOffset,
  4613. };
  4614. explicit OMPTileDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  4615. unsigned NumLoops)
  4616. : OMPLoopTransformationDirective(OMPTileDirectiveClass,
  4617. llvm::omp::OMPD_tile, StartLoc, EndLoc,
  4618. NumLoops) {
  4619. setNumGeneratedLoops(3 * NumLoops);
  4620. }
  4621. void setPreInits(Stmt *PreInits) {
  4622. Data->getChildren()[PreInitsOffset] = PreInits;
  4623. }
  4624. void setTransformedStmt(Stmt *S) {
  4625. Data->getChildren()[TransformedStmtOffset] = S;
  4626. }
  4627. public:
  4628. /// Create a new AST node representation for '#pragma omp tile'.
  4629. ///
  4630. /// \param C Context of the AST.
  4631. /// \param StartLoc Location of the introducer (e.g. the 'omp' token).
  4632. /// \param EndLoc Location of the directive's end (e.g. the tok::eod).
  4633. /// \param Clauses The directive's clauses.
  4634. /// \param NumLoops Number of associated loops (number of items in the
  4635. /// 'sizes' clause).
  4636. /// \param AssociatedStmt The outermost associated loop.
  4637. /// \param TransformedStmt The loop nest after tiling, or nullptr in
  4638. /// dependent contexts.
  4639. /// \param PreInits Helper preinits statements for the loop nest.
  4640. static OMPTileDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  4641. SourceLocation EndLoc,
  4642. ArrayRef<OMPClause *> Clauses,
  4643. unsigned NumLoops, Stmt *AssociatedStmt,
  4644. Stmt *TransformedStmt, Stmt *PreInits);
  4645. /// Build an empty '#pragma omp tile' AST node for deserialization.
  4646. ///
  4647. /// \param C Context of the AST.
  4648. /// \param NumClauses Number of clauses to allocate.
  4649. /// \param NumLoops Number of associated loops to allocate.
  4650. static OMPTileDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
  4651. unsigned NumLoops);
  4652. /// Gets/sets the associated loops after tiling.
  4653. ///
  4654. /// This is in de-sugared format stored as a CompoundStmt.
  4655. ///
  4656. /// \code
  4657. /// for (...)
  4658. /// ...
  4659. /// \endcode
  4660. ///
  4661. /// Note that if the generated loops a become associated loops of another
  4662. /// directive, they may need to be hoisted before them.
  4663. Stmt *getTransformedStmt() const {
  4664. return Data->getChildren()[TransformedStmtOffset];
  4665. }
  4666. /// Return preinits statement.
  4667. Stmt *getPreInits() const { return Data->getChildren()[PreInitsOffset]; }
  4668. static bool classof(const Stmt *T) {
  4669. return T->getStmtClass() == OMPTileDirectiveClass;
  4670. }
  4671. };
  4672. /// This represents the '#pragma omp unroll' loop transformation directive.
  4673. ///
  4674. /// \code
  4675. /// #pragma omp unroll
  4676. /// for (int i = 0; i < 64; ++i)
  4677. /// \endcode
  4678. class OMPUnrollDirective final : public OMPLoopTransformationDirective {
  4679. friend class ASTStmtReader;
  4680. friend class OMPExecutableDirective;
  4681. /// Default list of offsets.
  4682. enum {
  4683. PreInitsOffset = 0,
  4684. TransformedStmtOffset,
  4685. };
  4686. explicit OMPUnrollDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  4687. : OMPLoopTransformationDirective(OMPUnrollDirectiveClass,
  4688. llvm::omp::OMPD_unroll, StartLoc, EndLoc,
  4689. 1) {}
  4690. /// Set the pre-init statements.
  4691. void setPreInits(Stmt *PreInits) {
  4692. Data->getChildren()[PreInitsOffset] = PreInits;
  4693. }
  4694. /// Set the de-sugared statement.
  4695. void setTransformedStmt(Stmt *S) {
  4696. Data->getChildren()[TransformedStmtOffset] = S;
  4697. }
  4698. public:
  4699. /// Create a new AST node representation for '#pragma omp unroll'.
  4700. ///
  4701. /// \param C Context of the AST.
  4702. /// \param StartLoc Location of the introducer (e.g. the 'omp' token).
  4703. /// \param EndLoc Location of the directive's end (e.g. the tok::eod).
  4704. /// \param Clauses The directive's clauses.
  4705. /// \param AssociatedStmt The outermost associated loop.
  4706. /// \param TransformedStmt The loop nest after tiling, or nullptr in
  4707. /// dependent contexts.
  4708. /// \param PreInits Helper preinits statements for the loop nest.
  4709. static OMPUnrollDirective *
  4710. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4711. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
  4712. unsigned NumGeneratedLoops, Stmt *TransformedStmt, Stmt *PreInits);
  4713. /// Build an empty '#pragma omp unroll' AST node for deserialization.
  4714. ///
  4715. /// \param C Context of the AST.
  4716. /// \param NumClauses Number of clauses to allocate.
  4717. static OMPUnrollDirective *CreateEmpty(const ASTContext &C,
  4718. unsigned NumClauses);
  4719. /// Get the de-sugared associated loops after unrolling.
  4720. ///
  4721. /// This is only used if the unrolled loop becomes an associated loop of
  4722. /// another directive, otherwise the loop is emitted directly using loop
  4723. /// transformation metadata. When the unrolled loop cannot be used by another
  4724. /// directive (e.g. because of the full clause), the transformed stmt can also
  4725. /// be nullptr.
  4726. Stmt *getTransformedStmt() const {
  4727. return Data->getChildren()[TransformedStmtOffset];
  4728. }
  4729. /// Return the pre-init statements.
  4730. Stmt *getPreInits() const { return Data->getChildren()[PreInitsOffset]; }
  4731. static bool classof(const Stmt *T) {
  4732. return T->getStmtClass() == OMPUnrollDirectiveClass;
  4733. }
  4734. };
  4735. /// This represents '#pragma omp scan' directive.
  4736. ///
  4737. /// \code
  4738. /// #pragma omp scan inclusive(a)
  4739. /// \endcode
  4740. /// In this example directive '#pragma omp scan' has clause 'inclusive' with
  4741. /// list item 'a'.
  4742. class OMPScanDirective final : public OMPExecutableDirective {
  4743. friend class ASTStmtReader;
  4744. friend class OMPExecutableDirective;
  4745. /// Build directive with the given start and end location.
  4746. ///
  4747. /// \param StartLoc Starting location of the directive kind.
  4748. /// \param EndLoc Ending location of the directive.
  4749. ///
  4750. OMPScanDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  4751. : OMPExecutableDirective(OMPScanDirectiveClass, llvm::omp::OMPD_scan,
  4752. StartLoc, EndLoc) {}
  4753. /// Build an empty directive.
  4754. ///
  4755. explicit OMPScanDirective()
  4756. : OMPExecutableDirective(OMPScanDirectiveClass, llvm::omp::OMPD_scan,
  4757. SourceLocation(), SourceLocation()) {}
  4758. public:
  4759. /// Creates directive with a list of \a Clauses.
  4760. ///
  4761. /// \param C AST context.
  4762. /// \param StartLoc Starting location of the directive kind.
  4763. /// \param EndLoc Ending Location of the directive.
  4764. /// \param Clauses List of clauses (only single OMPFlushClause clause is
  4765. /// allowed).
  4766. ///
  4767. static OMPScanDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  4768. SourceLocation EndLoc,
  4769. ArrayRef<OMPClause *> Clauses);
  4770. /// Creates an empty directive with the place for \a NumClauses
  4771. /// clauses.
  4772. ///
  4773. /// \param C AST context.
  4774. /// \param NumClauses Number of clauses.
  4775. ///
  4776. static OMPScanDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
  4777. EmptyShell);
  4778. static bool classof(const Stmt *T) {
  4779. return T->getStmtClass() == OMPScanDirectiveClass;
  4780. }
  4781. };
  4782. /// This represents '#pragma omp interop' directive.
  4783. ///
  4784. /// \code
  4785. /// #pragma omp interop init(target:obj) device(x) depend(inout:y) nowait
  4786. /// \endcode
  4787. /// In this example directive '#pragma omp interop' has
  4788. /// clauses 'init', 'device', 'depend' and 'nowait'.
  4789. ///
  4790. class OMPInteropDirective final : public OMPExecutableDirective {
  4791. friend class ASTStmtReader;
  4792. friend class OMPExecutableDirective;
  4793. /// Build directive with the given start and end location.
  4794. ///
  4795. /// \param StartLoc Starting location of the directive.
  4796. /// \param EndLoc Ending location of the directive.
  4797. ///
  4798. OMPInteropDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  4799. : OMPExecutableDirective(OMPInteropDirectiveClass,
  4800. llvm::omp::OMPD_interop, StartLoc, EndLoc) {}
  4801. /// Build an empty directive.
  4802. ///
  4803. explicit OMPInteropDirective()
  4804. : OMPExecutableDirective(OMPInteropDirectiveClass,
  4805. llvm::omp::OMPD_interop, SourceLocation(),
  4806. SourceLocation()) {}
  4807. public:
  4808. /// Creates directive.
  4809. ///
  4810. /// \param C AST context.
  4811. /// \param StartLoc Starting location of the directive.
  4812. /// \param EndLoc Ending Location of the directive.
  4813. /// \param Clauses The directive's clauses.
  4814. ///
  4815. static OMPInteropDirective *Create(const ASTContext &C,
  4816. SourceLocation StartLoc,
  4817. SourceLocation EndLoc,
  4818. ArrayRef<OMPClause *> Clauses);
  4819. /// Creates an empty directive.
  4820. ///
  4821. /// \param C AST context.
  4822. ///
  4823. static OMPInteropDirective *CreateEmpty(const ASTContext &C,
  4824. unsigned NumClauses, EmptyShell);
  4825. static bool classof(const Stmt *T) {
  4826. return T->getStmtClass() == OMPInteropDirectiveClass;
  4827. }
  4828. };
  4829. /// This represents '#pragma omp dispatch' directive.
  4830. ///
  4831. /// \code
  4832. /// #pragma omp dispatch device(dnum)
  4833. /// \endcode
  4834. /// This example shows a directive '#pragma omp dispatch' with a
  4835. /// device clause with variable 'dnum'.
  4836. ///
  4837. class OMPDispatchDirective final : public OMPExecutableDirective {
  4838. friend class ASTStmtReader;
  4839. friend class OMPExecutableDirective;
  4840. /// The location of the target-call.
  4841. SourceLocation TargetCallLoc;
  4842. /// Set the location of the target-call.
  4843. void setTargetCallLoc(SourceLocation Loc) { TargetCallLoc = Loc; }
  4844. /// Build directive with the given start and end location.
  4845. ///
  4846. /// \param StartLoc Starting location of the directive kind.
  4847. /// \param EndLoc Ending location of the directive.
  4848. ///
  4849. OMPDispatchDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  4850. : OMPExecutableDirective(OMPDispatchDirectiveClass,
  4851. llvm::omp::OMPD_dispatch, StartLoc, EndLoc) {}
  4852. /// Build an empty directive.
  4853. ///
  4854. explicit OMPDispatchDirective()
  4855. : OMPExecutableDirective(OMPDispatchDirectiveClass,
  4856. llvm::omp::OMPD_dispatch, SourceLocation(),
  4857. SourceLocation()) {}
  4858. public:
  4859. /// Creates directive with a list of \a Clauses.
  4860. ///
  4861. /// \param C AST context.
  4862. /// \param StartLoc Starting location of the directive kind.
  4863. /// \param EndLoc Ending Location of the directive.
  4864. /// \param Clauses List of clauses.
  4865. /// \param AssociatedStmt Statement, associated with the directive.
  4866. /// \param TargetCallLoc Location of the target-call.
  4867. ///
  4868. static OMPDispatchDirective *
  4869. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4870. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
  4871. SourceLocation TargetCallLoc);
  4872. /// Creates an empty directive with the place for \a NumClauses
  4873. /// clauses.
  4874. ///
  4875. /// \param C AST context.
  4876. /// \param NumClauses Number of clauses.
  4877. ///
  4878. static OMPDispatchDirective *CreateEmpty(const ASTContext &C,
  4879. unsigned NumClauses, EmptyShell);
  4880. /// Return location of target-call.
  4881. SourceLocation getTargetCallLoc() const { return TargetCallLoc; }
  4882. static bool classof(const Stmt *T) {
  4883. return T->getStmtClass() == OMPDispatchDirectiveClass;
  4884. }
  4885. };
  4886. /// This represents '#pragma omp masked' directive.
  4887. /// \code
  4888. /// #pragma omp masked filter(tid)
  4889. /// \endcode
  4890. /// This example shows a directive '#pragma omp masked' with a filter clause
  4891. /// with variable 'tid'.
  4892. ///
  4893. class OMPMaskedDirective final : public OMPExecutableDirective {
  4894. friend class ASTStmtReader;
  4895. friend class OMPExecutableDirective;
  4896. /// Build directive with the given start and end location.
  4897. ///
  4898. /// \param StartLoc Starting location of the directive kind.
  4899. /// \param EndLoc Ending location of the directive.
  4900. ///
  4901. OMPMaskedDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  4902. : OMPExecutableDirective(OMPMaskedDirectiveClass, llvm::omp::OMPD_masked,
  4903. StartLoc, EndLoc) {}
  4904. /// Build an empty directive.
  4905. ///
  4906. explicit OMPMaskedDirective()
  4907. : OMPExecutableDirective(OMPMaskedDirectiveClass, llvm::omp::OMPD_masked,
  4908. SourceLocation(), SourceLocation()) {}
  4909. public:
  4910. /// Creates directive.
  4911. ///
  4912. /// \param C AST context.
  4913. /// \param StartLoc Starting location of the directive kind.
  4914. /// \param EndLoc Ending Location of the directive.
  4915. /// \param AssociatedStmt Statement, associated with the directive.
  4916. ///
  4917. static OMPMaskedDirective *
  4918. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  4919. ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
  4920. /// Creates an empty directive.
  4921. ///
  4922. /// \param C AST context.
  4923. ///
  4924. static OMPMaskedDirective *CreateEmpty(const ASTContext &C,
  4925. unsigned NumClauses, EmptyShell);
  4926. static bool classof(const Stmt *T) {
  4927. return T->getStmtClass() == OMPMaskedDirectiveClass;
  4928. }
  4929. };
  4930. /// This represents '#pragma omp metadirective' directive.
  4931. ///
  4932. /// \code
  4933. /// #pragma omp metadirective when(user={condition(N>10)}: parallel for)
  4934. /// \endcode
  4935. /// In this example directive '#pragma omp metadirective' has clauses 'when'
  4936. /// with a dynamic user condition to check if a variable 'N > 10'
  4937. ///
  4938. class OMPMetaDirective final : public OMPExecutableDirective {
  4939. friend class ASTStmtReader;
  4940. friend class OMPExecutableDirective;
  4941. Stmt *IfStmt;
  4942. OMPMetaDirective(SourceLocation StartLoc, SourceLocation EndLoc)
  4943. : OMPExecutableDirective(OMPMetaDirectiveClass,
  4944. llvm::omp::OMPD_metadirective, StartLoc,
  4945. EndLoc) {}
  4946. explicit OMPMetaDirective()
  4947. : OMPExecutableDirective(OMPMetaDirectiveClass,
  4948. llvm::omp::OMPD_metadirective, SourceLocation(),
  4949. SourceLocation()) {}
  4950. void setIfStmt(Stmt *S) { IfStmt = S; }
  4951. public:
  4952. static OMPMetaDirective *Create(const ASTContext &C, SourceLocation StartLoc,
  4953. SourceLocation EndLoc,
  4954. ArrayRef<OMPClause *> Clauses,
  4955. Stmt *AssociatedStmt, Stmt *IfStmt);
  4956. static OMPMetaDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
  4957. EmptyShell);
  4958. Stmt *getIfStmt() const { return IfStmt; }
  4959. static bool classof(const Stmt *T) {
  4960. return T->getStmtClass() == OMPMetaDirectiveClass;
  4961. }
  4962. };
  4963. /// This represents '#pragma omp loop' directive.
  4964. ///
  4965. /// \code
  4966. /// #pragma omp loop private(a,b) binding(parallel) order(concurrent)
  4967. /// \endcode
  4968. /// In this example directive '#pragma omp loop' has
  4969. /// clauses 'private' with the variables 'a' and 'b', 'binding' with
  4970. /// modifier 'parallel' and 'order(concurrent).
  4971. ///
  4972. class OMPGenericLoopDirective final : public OMPLoopDirective {
  4973. friend class ASTStmtReader;
  4974. friend class OMPExecutableDirective;
  4975. /// Build directive with the given start and end location.
  4976. ///
  4977. /// \param StartLoc Starting location of the directive kind.
  4978. /// \param EndLoc Ending location of the directive.
  4979. /// \param CollapsedNum Number of collapsed nested loops.
  4980. ///
  4981. OMPGenericLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc,
  4982. unsigned CollapsedNum)
  4983. : OMPLoopDirective(OMPGenericLoopDirectiveClass, llvm::omp::OMPD_loop,
  4984. StartLoc, EndLoc, CollapsedNum) {}
  4985. /// Build an empty directive.
  4986. ///
  4987. /// \param CollapsedNum Number of collapsed nested loops.
  4988. ///
  4989. explicit OMPGenericLoopDirective(unsigned CollapsedNum)
  4990. : OMPLoopDirective(OMPGenericLoopDirectiveClass, llvm::omp::OMPD_loop,
  4991. SourceLocation(), SourceLocation(), CollapsedNum) {}
  4992. public:
  4993. /// Creates directive with a list of \p Clauses.
  4994. ///
  4995. /// \param C AST context.
  4996. /// \param StartLoc Starting location of the directive kind.
  4997. /// \param EndLoc Ending Location of the directive.
  4998. /// \param CollapsedNum Number of collapsed loops.
  4999. /// \param Clauses List of clauses.
  5000. /// \param AssociatedStmt Statement, associated with the directive.
  5001. /// \param Exprs Helper expressions for CodeGen.
  5002. ///
  5003. static OMPGenericLoopDirective *
  5004. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  5005. unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
  5006. Stmt *AssociatedStmt, const HelperExprs &Exprs);
  5007. /// Creates an empty directive with a place for \a NumClauses clauses.
  5008. ///
  5009. /// \param C AST context.
  5010. /// \param NumClauses Number of clauses.
  5011. /// \param CollapsedNum Number of collapsed nested loops.
  5012. ///
  5013. static OMPGenericLoopDirective *CreateEmpty(const ASTContext &C,
  5014. unsigned NumClauses,
  5015. unsigned CollapsedNum,
  5016. EmptyShell);
  5017. static bool classof(const Stmt *T) {
  5018. return T->getStmtClass() == OMPGenericLoopDirectiveClass;
  5019. }
  5020. };
  5021. } // end namespace clang
  5022. #endif
  5023. #ifdef __GNUC__
  5024. #pragma GCC diagnostic pop
  5025. #endif