StmtOpenMP.h 239 KB

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