OpenMPClause.h 327 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- 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. //
  14. /// \file
  15. /// This file defines OpenMP AST classes for clauses.
  16. /// There are clauses for executable directives, clauses for declarative
  17. /// directives and clauses which can be used in both kinds of directives.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
  21. #define LLVM_CLANG_AST_OPENMPCLAUSE_H
  22. #include "clang/AST/ASTFwd.h"
  23. #include "clang/AST/Decl.h"
  24. #include "clang/AST/DeclarationName.h"
  25. #include "clang/AST/Expr.h"
  26. #include "clang/AST/NestedNameSpecifier.h"
  27. #include "clang/AST/Stmt.h"
  28. #include "clang/AST/StmtIterator.h"
  29. #include "clang/Basic/LLVM.h"
  30. #include "clang/Basic/OpenMPKinds.h"
  31. #include "clang/Basic/SourceLocation.h"
  32. #include "llvm/ADT/ArrayRef.h"
  33. #include "llvm/ADT/MapVector.h"
  34. #include "llvm/ADT/PointerIntPair.h"
  35. #include "llvm/ADT/SmallVector.h"
  36. #include "llvm/ADT/iterator.h"
  37. #include "llvm/ADT/iterator_range.h"
  38. #include "llvm/Frontend/OpenMP/OMPAssume.h"
  39. #include "llvm/Frontend/OpenMP/OMPConstants.h"
  40. #include "llvm/Frontend/OpenMP/OMPContext.h"
  41. #include "llvm/Support/Casting.h"
  42. #include "llvm/Support/Compiler.h"
  43. #include "llvm/Support/TrailingObjects.h"
  44. #include <cassert>
  45. #include <cstddef>
  46. #include <iterator>
  47. #include <utility>
  48. namespace clang {
  49. class ASTContext;
  50. //===----------------------------------------------------------------------===//
  51. // AST classes for clauses.
  52. //===----------------------------------------------------------------------===//
  53. /// This is a basic class for representing single OpenMP clause.
  54. class OMPClause {
  55. /// Starting location of the clause (the clause keyword).
  56. SourceLocation StartLoc;
  57. /// Ending location of the clause.
  58. SourceLocation EndLoc;
  59. /// Kind of the clause.
  60. OpenMPClauseKind Kind;
  61. protected:
  62. OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
  63. : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
  64. public:
  65. /// Returns the starting location of the clause.
  66. SourceLocation getBeginLoc() const { return StartLoc; }
  67. /// Returns the ending location of the clause.
  68. SourceLocation getEndLoc() const { return EndLoc; }
  69. /// Sets the starting location of the clause.
  70. void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
  71. /// Sets the ending location of the clause.
  72. void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
  73. /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
  74. OpenMPClauseKind getClauseKind() const { return Kind; }
  75. bool isImplicit() const { return StartLoc.isInvalid(); }
  76. using child_iterator = StmtIterator;
  77. using const_child_iterator = ConstStmtIterator;
  78. using child_range = llvm::iterator_range<child_iterator>;
  79. using const_child_range = llvm::iterator_range<const_child_iterator>;
  80. child_range children();
  81. const_child_range children() const {
  82. auto Children = const_cast<OMPClause *>(this)->children();
  83. return const_child_range(Children.begin(), Children.end());
  84. }
  85. /// Get the iterator range for the expressions used in the clauses. Used
  86. /// expressions include only the children that must be evaluated at the
  87. /// runtime before entering the construct.
  88. child_range used_children();
  89. const_child_range used_children() const {
  90. auto Children = const_cast<OMPClause *>(this)->children();
  91. return const_child_range(Children.begin(), Children.end());
  92. }
  93. static bool classof(const OMPClause *) { return true; }
  94. };
  95. template <OpenMPClauseKind ClauseKind>
  96. struct OMPNoChildClause : public OMPClause {
  97. /// Build '\p ClauseKind' clause.
  98. ///
  99. /// \param StartLoc Starting location of the clause.
  100. /// \param EndLoc Ending location of the clause.
  101. OMPNoChildClause(SourceLocation StartLoc, SourceLocation EndLoc)
  102. : OMPClause(ClauseKind, StartLoc, EndLoc) {}
  103. /// Build an empty clause.
  104. OMPNoChildClause()
  105. : OMPClause(ClauseKind, SourceLocation(), SourceLocation()) {}
  106. child_range children() {
  107. return child_range(child_iterator(), child_iterator());
  108. }
  109. const_child_range children() const {
  110. return const_child_range(const_child_iterator(), const_child_iterator());
  111. }
  112. child_range used_children() {
  113. return child_range(child_iterator(), child_iterator());
  114. }
  115. const_child_range used_children() const {
  116. return const_child_range(const_child_iterator(), const_child_iterator());
  117. }
  118. static bool classof(const OMPClause *T) {
  119. return T->getClauseKind() == ClauseKind;
  120. }
  121. };
  122. template <OpenMPClauseKind ClauseKind, class Base>
  123. class OMPOneStmtClause : public Base {
  124. /// Location of '('.
  125. SourceLocation LParenLoc;
  126. /// Sub-expression.
  127. Stmt *S = nullptr;
  128. protected:
  129. void setStmt(Stmt *S) { this->S = S; }
  130. public:
  131. OMPOneStmtClause(Stmt *S, SourceLocation StartLoc, SourceLocation LParenLoc,
  132. SourceLocation EndLoc)
  133. : Base(ClauseKind, StartLoc, EndLoc), LParenLoc(LParenLoc), S(S) {}
  134. OMPOneStmtClause() : Base(ClauseKind, SourceLocation(), SourceLocation()) {}
  135. /// Return the associated statement, potentially casted to \p T.
  136. template <typename T> T *getStmtAs() const { return cast_or_null<T>(S); }
  137. /// Sets the location of '('.
  138. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  139. /// Returns the location of '('.
  140. SourceLocation getLParenLoc() const { return LParenLoc; }
  141. using child_iterator = StmtIterator;
  142. using const_child_iterator = ConstStmtIterator;
  143. using child_range = llvm::iterator_range<child_iterator>;
  144. using const_child_range = llvm::iterator_range<const_child_iterator>;
  145. child_range children() { return child_range(&S, &S + 1); }
  146. const_child_range children() const { return const_child_range(&S, &S + 1); }
  147. // TODO: Consider making the getAddrOfExprAsWritten version the default.
  148. child_range used_children() {
  149. return child_range(child_iterator(), child_iterator());
  150. }
  151. const_child_range used_children() const {
  152. return const_child_range(const_child_iterator(), const_child_iterator());
  153. }
  154. static bool classof(const OMPClause *T) {
  155. return T->getClauseKind() == ClauseKind;
  156. }
  157. };
  158. /// Class that handles pre-initialization statement for some clauses, like
  159. /// 'shedule', 'firstprivate' etc.
  160. class OMPClauseWithPreInit {
  161. friend class OMPClauseReader;
  162. /// Pre-initialization statement for the clause.
  163. Stmt *PreInit = nullptr;
  164. /// Region that captures the associated stmt.
  165. OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
  166. protected:
  167. OMPClauseWithPreInit(const OMPClause *This) {
  168. assert(get(This) && "get is not tuned for pre-init.");
  169. }
  170. /// Set pre-initialization statement for the clause.
  171. void
  172. setPreInitStmt(Stmt *S,
  173. OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
  174. PreInit = S;
  175. CaptureRegion = ThisRegion;
  176. }
  177. public:
  178. /// Get pre-initialization statement for the clause.
  179. const Stmt *getPreInitStmt() const { return PreInit; }
  180. /// Get pre-initialization statement for the clause.
  181. Stmt *getPreInitStmt() { return PreInit; }
  182. /// Get capture region for the stmt in the clause.
  183. OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
  184. static OMPClauseWithPreInit *get(OMPClause *C);
  185. static const OMPClauseWithPreInit *get(const OMPClause *C);
  186. };
  187. /// Class that handles post-update expression for some clauses, like
  188. /// 'lastprivate', 'reduction' etc.
  189. class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
  190. friend class OMPClauseReader;
  191. /// Post-update expression for the clause.
  192. Expr *PostUpdate = nullptr;
  193. protected:
  194. OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
  195. assert(get(This) && "get is not tuned for post-update.");
  196. }
  197. /// Set pre-initialization statement for the clause.
  198. void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
  199. public:
  200. /// Get post-update expression for the clause.
  201. const Expr *getPostUpdateExpr() const { return PostUpdate; }
  202. /// Get post-update expression for the clause.
  203. Expr *getPostUpdateExpr() { return PostUpdate; }
  204. static OMPClauseWithPostUpdate *get(OMPClause *C);
  205. static const OMPClauseWithPostUpdate *get(const OMPClause *C);
  206. };
  207. /// This structure contains most locations needed for by an OMPVarListClause.
  208. struct OMPVarListLocTy {
  209. /// Starting location of the clause (the clause keyword).
  210. SourceLocation StartLoc;
  211. /// Location of '('.
  212. SourceLocation LParenLoc;
  213. /// Ending location of the clause.
  214. SourceLocation EndLoc;
  215. OMPVarListLocTy() = default;
  216. OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc,
  217. SourceLocation EndLoc)
  218. : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {}
  219. };
  220. /// This represents clauses with the list of variables like 'private',
  221. /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
  222. /// '#pragma omp ...' directives.
  223. template <class T> class OMPVarListClause : public OMPClause {
  224. friend class OMPClauseReader;
  225. /// Location of '('.
  226. SourceLocation LParenLoc;
  227. /// Number of variables in the list.
  228. unsigned NumVars;
  229. protected:
  230. /// Build a clause with \a N variables
  231. ///
  232. /// \param K Kind of the clause.
  233. /// \param StartLoc Starting location of the clause (the clause keyword).
  234. /// \param LParenLoc Location of '('.
  235. /// \param EndLoc Ending location of the clause.
  236. /// \param N Number of the variables in the clause.
  237. OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
  238. SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
  239. : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
  240. /// Fetches list of variables associated with this clause.
  241. MutableArrayRef<Expr *> getVarRefs() {
  242. return MutableArrayRef<Expr *>(
  243. static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
  244. }
  245. /// Sets the list of variables for this clause.
  246. void setVarRefs(ArrayRef<Expr *> VL) {
  247. assert(VL.size() == NumVars &&
  248. "Number of variables is not the same as the preallocated buffer");
  249. std::copy(VL.begin(), VL.end(),
  250. static_cast<T *>(this)->template getTrailingObjects<Expr *>());
  251. }
  252. public:
  253. using varlist_iterator = MutableArrayRef<Expr *>::iterator;
  254. using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
  255. using varlist_range = llvm::iterator_range<varlist_iterator>;
  256. using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
  257. unsigned varlist_size() const { return NumVars; }
  258. bool varlist_empty() const { return NumVars == 0; }
  259. varlist_range varlists() {
  260. return varlist_range(varlist_begin(), varlist_end());
  261. }
  262. varlist_const_range varlists() const {
  263. return varlist_const_range(varlist_begin(), varlist_end());
  264. }
  265. varlist_iterator varlist_begin() { return getVarRefs().begin(); }
  266. varlist_iterator varlist_end() { return getVarRefs().end(); }
  267. varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
  268. varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
  269. /// Sets the location of '('.
  270. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  271. /// Returns the location of '('.
  272. SourceLocation getLParenLoc() const { return LParenLoc; }
  273. /// Fetches list of all variables in the clause.
  274. ArrayRef<const Expr *> getVarRefs() const {
  275. return llvm::ArrayRef(
  276. static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
  277. NumVars);
  278. }
  279. };
  280. /// This represents 'allocator' clause in the '#pragma omp ...'
  281. /// directive.
  282. ///
  283. /// \code
  284. /// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
  285. /// \endcode
  286. /// In this example directive '#pragma omp allocate' has simple 'allocator'
  287. /// clause with the allocator 'omp_default_mem_alloc'.
  288. class OMPAllocatorClause final
  289. : public OMPOneStmtClause<llvm::omp::OMPC_allocator, OMPClause> {
  290. friend class OMPClauseReader;
  291. /// Set allocator.
  292. void setAllocator(Expr *A) { setStmt(A); }
  293. public:
  294. /// Build 'allocator' clause with the given allocator.
  295. ///
  296. /// \param A Allocator.
  297. /// \param StartLoc Starting location of the clause.
  298. /// \param LParenLoc Location of '('.
  299. /// \param EndLoc Ending location of the clause.
  300. OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
  301. SourceLocation EndLoc)
  302. : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
  303. /// Build an empty clause.
  304. OMPAllocatorClause() : OMPOneStmtClause() {}
  305. /// Returns allocator.
  306. Expr *getAllocator() const { return getStmtAs<Expr>(); }
  307. };
  308. /// This represents the 'align' clause in the '#pragma omp allocate'
  309. /// directive.
  310. ///
  311. /// \code
  312. /// #pragma omp allocate(a) allocator(omp_default_mem_alloc) align(8)
  313. /// \endcode
  314. /// In this example directive '#pragma omp allocate' has simple 'allocator'
  315. /// clause with the allocator 'omp_default_mem_alloc' and align clause with
  316. /// value of 8.
  317. class OMPAlignClause final
  318. : public OMPOneStmtClause<llvm::omp::OMPC_align, OMPClause> {
  319. friend class OMPClauseReader;
  320. /// Set alignment value.
  321. void setAlignment(Expr *A) { setStmt(A); }
  322. /// Build 'align' clause with the given alignment
  323. ///
  324. /// \param A Alignment value.
  325. /// \param StartLoc Starting location of the clause.
  326. /// \param LParenLoc Location of '('.
  327. /// \param EndLoc Ending location of the clause.
  328. OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
  329. SourceLocation EndLoc)
  330. : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
  331. /// Build an empty clause.
  332. OMPAlignClause() : OMPOneStmtClause() {}
  333. public:
  334. /// Build 'align' clause with the given alignment
  335. ///
  336. /// \param A Alignment value.
  337. /// \param StartLoc Starting location of the clause.
  338. /// \param LParenLoc Location of '('.
  339. /// \param EndLoc Ending location of the clause.
  340. static OMPAlignClause *Create(const ASTContext &C, Expr *A,
  341. SourceLocation StartLoc,
  342. SourceLocation LParenLoc,
  343. SourceLocation EndLoc);
  344. /// Returns alignment
  345. Expr *getAlignment() const { return getStmtAs<Expr>(); }
  346. };
  347. /// This represents clause 'allocate' in the '#pragma omp ...' directives.
  348. ///
  349. /// \code
  350. /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
  351. /// \endcode
  352. /// In this example directive '#pragma omp parallel' has clause 'private'
  353. /// and clause 'allocate' for the variable 'a'.
  354. class OMPAllocateClause final
  355. : public OMPVarListClause<OMPAllocateClause>,
  356. private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
  357. friend class OMPClauseReader;
  358. friend OMPVarListClause;
  359. friend TrailingObjects;
  360. /// Allocator specified in the clause, or 'nullptr' if the default one is
  361. /// used.
  362. Expr *Allocator = nullptr;
  363. /// Position of the ':' delimiter in the clause;
  364. SourceLocation ColonLoc;
  365. /// Build clause with number of variables \a N.
  366. ///
  367. /// \param StartLoc Starting location of the clause.
  368. /// \param LParenLoc Location of '('.
  369. /// \param Allocator Allocator expression.
  370. /// \param ColonLoc Location of ':' delimiter.
  371. /// \param EndLoc Ending location of the clause.
  372. /// \param N Number of the variables in the clause.
  373. OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  374. Expr *Allocator, SourceLocation ColonLoc,
  375. SourceLocation EndLoc, unsigned N)
  376. : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
  377. LParenLoc, EndLoc, N),
  378. Allocator(Allocator), ColonLoc(ColonLoc) {}
  379. /// Build an empty clause.
  380. ///
  381. /// \param N Number of variables.
  382. explicit OMPAllocateClause(unsigned N)
  383. : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
  384. SourceLocation(), SourceLocation(),
  385. SourceLocation(), N) {}
  386. /// Sets location of ':' symbol in clause.
  387. void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
  388. void setAllocator(Expr *A) { Allocator = A; }
  389. public:
  390. /// Creates clause with a list of variables \a VL.
  391. ///
  392. /// \param C AST context.
  393. /// \param StartLoc Starting location of the clause.
  394. /// \param LParenLoc Location of '('.
  395. /// \param Allocator Allocator expression.
  396. /// \param ColonLoc Location of ':' delimiter.
  397. /// \param EndLoc Ending location of the clause.
  398. /// \param VL List of references to the variables.
  399. static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
  400. SourceLocation LParenLoc, Expr *Allocator,
  401. SourceLocation ColonLoc,
  402. SourceLocation EndLoc, ArrayRef<Expr *> VL);
  403. /// Returns the allocator expression or nullptr, if no allocator is specified.
  404. Expr *getAllocator() const { return Allocator; }
  405. /// Returns the location of the ':' delimiter.
  406. SourceLocation getColonLoc() const { return ColonLoc; }
  407. /// Creates an empty clause with the place for \a N variables.
  408. ///
  409. /// \param C AST context.
  410. /// \param N The number of variables.
  411. static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
  412. child_range children() {
  413. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  414. reinterpret_cast<Stmt **>(varlist_end()));
  415. }
  416. const_child_range children() const {
  417. auto Children = const_cast<OMPAllocateClause *>(this)->children();
  418. return const_child_range(Children.begin(), Children.end());
  419. }
  420. child_range used_children() {
  421. return child_range(child_iterator(), child_iterator());
  422. }
  423. const_child_range used_children() const {
  424. return const_child_range(const_child_iterator(), const_child_iterator());
  425. }
  426. static bool classof(const OMPClause *T) {
  427. return T->getClauseKind() == llvm::omp::OMPC_allocate;
  428. }
  429. };
  430. /// This represents 'if' clause in the '#pragma omp ...' directive.
  431. ///
  432. /// \code
  433. /// #pragma omp parallel if(parallel:a > 5)
  434. /// \endcode
  435. /// In this example directive '#pragma omp parallel' has simple 'if' clause with
  436. /// condition 'a > 5' and directive name modifier 'parallel'.
  437. class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
  438. friend class OMPClauseReader;
  439. /// Location of '('.
  440. SourceLocation LParenLoc;
  441. /// Condition of the 'if' clause.
  442. Stmt *Condition = nullptr;
  443. /// Location of ':' (if any).
  444. SourceLocation ColonLoc;
  445. /// Directive name modifier for the clause.
  446. OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
  447. /// Name modifier location.
  448. SourceLocation NameModifierLoc;
  449. /// Set condition.
  450. void setCondition(Expr *Cond) { Condition = Cond; }
  451. /// Set directive name modifier for the clause.
  452. void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
  453. /// Set location of directive name modifier for the clause.
  454. void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
  455. /// Set location of ':'.
  456. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  457. public:
  458. /// Build 'if' clause with condition \a Cond.
  459. ///
  460. /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
  461. /// \param Cond Condition of the clause.
  462. /// \param HelperCond Helper condition for the clause.
  463. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  464. /// clause must be captured.
  465. /// \param StartLoc Starting location of the clause.
  466. /// \param LParenLoc Location of '('.
  467. /// \param NameModifierLoc Location of directive name modifier.
  468. /// \param ColonLoc [OpenMP 4.1] Location of ':'.
  469. /// \param EndLoc Ending location of the clause.
  470. OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
  471. OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
  472. SourceLocation LParenLoc, SourceLocation NameModifierLoc,
  473. SourceLocation ColonLoc, SourceLocation EndLoc)
  474. : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
  475. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
  476. ColonLoc(ColonLoc), NameModifier(NameModifier),
  477. NameModifierLoc(NameModifierLoc) {
  478. setPreInitStmt(HelperCond, CaptureRegion);
  479. }
  480. /// Build an empty clause.
  481. OMPIfClause()
  482. : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()),
  483. OMPClauseWithPreInit(this) {}
  484. /// Sets the location of '('.
  485. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  486. /// Returns the location of '('.
  487. SourceLocation getLParenLoc() const { return LParenLoc; }
  488. /// Return the location of ':'.
  489. SourceLocation getColonLoc() const { return ColonLoc; }
  490. /// Returns condition.
  491. Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
  492. /// Return directive name modifier associated with the clause.
  493. OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
  494. /// Return the location of directive name modifier.
  495. SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
  496. child_range children() { return child_range(&Condition, &Condition + 1); }
  497. const_child_range children() const {
  498. return const_child_range(&Condition, &Condition + 1);
  499. }
  500. child_range used_children();
  501. const_child_range used_children() const {
  502. auto Children = const_cast<OMPIfClause *>(this)->used_children();
  503. return const_child_range(Children.begin(), Children.end());
  504. }
  505. static bool classof(const OMPClause *T) {
  506. return T->getClauseKind() == llvm::omp::OMPC_if;
  507. }
  508. };
  509. /// This represents 'final' clause in the '#pragma omp ...' directive.
  510. ///
  511. /// \code
  512. /// #pragma omp task final(a > 5)
  513. /// \endcode
  514. /// In this example directive '#pragma omp task' has simple 'final'
  515. /// clause with condition 'a > 5'.
  516. class OMPFinalClause final
  517. : public OMPOneStmtClause<llvm::omp::OMPC_final, OMPClause>,
  518. public OMPClauseWithPreInit {
  519. friend class OMPClauseReader;
  520. /// Set condition.
  521. void setCondition(Expr *Cond) { setStmt(Cond); }
  522. public:
  523. /// Build 'final' clause with condition \a Cond.
  524. ///
  525. /// \param Cond Condition of the clause.
  526. /// \param HelperCond Helper condition for the construct.
  527. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  528. /// clause must be captured.
  529. /// \param StartLoc Starting location of the clause.
  530. /// \param LParenLoc Location of '('.
  531. /// \param EndLoc Ending location of the clause.
  532. OMPFinalClause(Expr *Cond, Stmt *HelperCond,
  533. OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
  534. SourceLocation LParenLoc, SourceLocation EndLoc)
  535. : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
  536. OMPClauseWithPreInit(this) {
  537. setPreInitStmt(HelperCond, CaptureRegion);
  538. }
  539. /// Build an empty clause.
  540. OMPFinalClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
  541. /// Returns condition.
  542. Expr *getCondition() const { return getStmtAs<Expr>(); }
  543. child_range used_children();
  544. const_child_range used_children() const {
  545. auto Children = const_cast<OMPFinalClause *>(this)->used_children();
  546. return const_child_range(Children.begin(), Children.end());
  547. }
  548. };
  549. /// This represents 'num_threads' clause in the '#pragma omp ...'
  550. /// directive.
  551. ///
  552. /// \code
  553. /// #pragma omp parallel num_threads(6)
  554. /// \endcode
  555. /// In this example directive '#pragma omp parallel' has simple 'num_threads'
  556. /// clause with number of threads '6'.
  557. class OMPNumThreadsClause final
  558. : public OMPOneStmtClause<llvm::omp::OMPC_num_threads, OMPClause>,
  559. public OMPClauseWithPreInit {
  560. friend class OMPClauseReader;
  561. /// Set condition.
  562. void setNumThreads(Expr *NThreads) { setStmt(NThreads); }
  563. public:
  564. /// Build 'num_threads' clause with condition \a NumThreads.
  565. ///
  566. /// \param NumThreads Number of threads for the construct.
  567. /// \param HelperNumThreads Helper Number of threads for the construct.
  568. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  569. /// clause must be captured.
  570. /// \param StartLoc Starting location of the clause.
  571. /// \param LParenLoc Location of '('.
  572. /// \param EndLoc Ending location of the clause.
  573. OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
  574. OpenMPDirectiveKind CaptureRegion,
  575. SourceLocation StartLoc, SourceLocation LParenLoc,
  576. SourceLocation EndLoc)
  577. : OMPOneStmtClause(NumThreads, StartLoc, LParenLoc, EndLoc),
  578. OMPClauseWithPreInit(this) {
  579. setPreInitStmt(HelperNumThreads, CaptureRegion);
  580. }
  581. /// Build an empty clause.
  582. OMPNumThreadsClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
  583. /// Returns number of threads.
  584. Expr *getNumThreads() const { return getStmtAs<Expr>(); }
  585. };
  586. /// This represents 'safelen' clause in the '#pragma omp ...'
  587. /// directive.
  588. ///
  589. /// \code
  590. /// #pragma omp simd safelen(4)
  591. /// \endcode
  592. /// In this example directive '#pragma omp simd' has clause 'safelen'
  593. /// with single expression '4'.
  594. /// If the safelen clause is used then no two iterations executed
  595. /// concurrently with SIMD instructions can have a greater distance
  596. /// in the logical iteration space than its value. The parameter of
  597. /// the safelen clause must be a constant positive integer expression.
  598. class OMPSafelenClause final
  599. : public OMPOneStmtClause<llvm::omp::OMPC_safelen, OMPClause> {
  600. friend class OMPClauseReader;
  601. /// Set safelen.
  602. void setSafelen(Expr *Len) { setStmt(Len); }
  603. public:
  604. /// Build 'safelen' clause.
  605. ///
  606. /// \param Len Expression associated with this clause.
  607. /// \param StartLoc Starting location of the clause.
  608. /// \param EndLoc Ending location of the clause.
  609. OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
  610. SourceLocation EndLoc)
  611. : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
  612. /// Build an empty clause.
  613. explicit OMPSafelenClause() : OMPOneStmtClause() {}
  614. /// Return safe iteration space distance.
  615. Expr *getSafelen() const { return getStmtAs<Expr>(); }
  616. };
  617. /// This represents 'simdlen' clause in the '#pragma omp ...'
  618. /// directive.
  619. ///
  620. /// \code
  621. /// #pragma omp simd simdlen(4)
  622. /// \endcode
  623. /// In this example directive '#pragma omp simd' has clause 'simdlen'
  624. /// with single expression '4'.
  625. /// If the 'simdlen' clause is used then it specifies the preferred number of
  626. /// iterations to be executed concurrently. The parameter of the 'simdlen'
  627. /// clause must be a constant positive integer expression.
  628. class OMPSimdlenClause final
  629. : public OMPOneStmtClause<llvm::omp::OMPC_simdlen, OMPClause> {
  630. friend class OMPClauseReader;
  631. /// Set simdlen.
  632. void setSimdlen(Expr *Len) { setStmt(Len); }
  633. public:
  634. /// Build 'simdlen' clause.
  635. ///
  636. /// \param Len Expression associated with this clause.
  637. /// \param StartLoc Starting location of the clause.
  638. /// \param EndLoc Ending location of the clause.
  639. OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
  640. SourceLocation EndLoc)
  641. : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
  642. /// Build an empty clause.
  643. explicit OMPSimdlenClause() : OMPOneStmtClause() {}
  644. /// Return safe iteration space distance.
  645. Expr *getSimdlen() const { return getStmtAs<Expr>(); }
  646. };
  647. /// This represents the 'sizes' clause in the '#pragma omp tile' directive.
  648. ///
  649. /// \code
  650. /// #pragma omp tile sizes(5,5)
  651. /// for (int i = 0; i < 64; ++i)
  652. /// for (int j = 0; j < 64; ++j)
  653. /// \endcode
  654. class OMPSizesClause final
  655. : public OMPClause,
  656. private llvm::TrailingObjects<OMPSizesClause, Expr *> {
  657. friend class OMPClauseReader;
  658. friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
  659. /// Location of '('.
  660. SourceLocation LParenLoc;
  661. /// Number of tile sizes in the clause.
  662. unsigned NumSizes;
  663. /// Build an empty clause.
  664. explicit OMPSizesClause(int NumSizes)
  665. : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
  666. NumSizes(NumSizes) {}
  667. public:
  668. /// Build a 'sizes' AST node.
  669. ///
  670. /// \param C Context of the AST.
  671. /// \param StartLoc Location of the 'sizes' identifier.
  672. /// \param LParenLoc Location of '('.
  673. /// \param EndLoc Location of ')'.
  674. /// \param Sizes Content of the clause.
  675. static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
  676. SourceLocation LParenLoc, SourceLocation EndLoc,
  677. ArrayRef<Expr *> Sizes);
  678. /// Build an empty 'sizes' AST node for deserialization.
  679. ///
  680. /// \param C Context of the AST.
  681. /// \param NumSizes Number of items in the clause.
  682. static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
  683. /// Sets the location of '('.
  684. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  685. /// Returns the location of '('.
  686. SourceLocation getLParenLoc() const { return LParenLoc; }
  687. /// Returns the number of list items.
  688. unsigned getNumSizes() const { return NumSizes; }
  689. /// Returns the tile size expressions.
  690. MutableArrayRef<Expr *> getSizesRefs() {
  691. return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this)
  692. ->template getTrailingObjects<Expr *>(),
  693. NumSizes);
  694. }
  695. ArrayRef<Expr *> getSizesRefs() const {
  696. return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this)
  697. ->template getTrailingObjects<Expr *>(),
  698. NumSizes);
  699. }
  700. /// Sets the tile size expressions.
  701. void setSizesRefs(ArrayRef<Expr *> VL) {
  702. assert(VL.size() == NumSizes);
  703. std::copy(VL.begin(), VL.end(),
  704. static_cast<OMPSizesClause *>(this)
  705. ->template getTrailingObjects<Expr *>());
  706. }
  707. child_range children() {
  708. MutableArrayRef<Expr *> Sizes = getSizesRefs();
  709. return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
  710. reinterpret_cast<Stmt **>(Sizes.end()));
  711. }
  712. const_child_range children() const {
  713. ArrayRef<Expr *> Sizes = getSizesRefs();
  714. return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
  715. reinterpret_cast<Stmt *const *>(Sizes.end()));
  716. }
  717. child_range used_children() {
  718. return child_range(child_iterator(), child_iterator());
  719. }
  720. const_child_range used_children() const {
  721. return const_child_range(const_child_iterator(), const_child_iterator());
  722. }
  723. static bool classof(const OMPClause *T) {
  724. return T->getClauseKind() == llvm::omp::OMPC_sizes;
  725. }
  726. };
  727. /// Representation of the 'full' clause of the '#pragma omp unroll' directive.
  728. ///
  729. /// \code
  730. /// #pragma omp unroll full
  731. /// for (int i = 0; i < 64; ++i)
  732. /// \endcode
  733. class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
  734. friend class OMPClauseReader;
  735. /// Build an empty clause.
  736. explicit OMPFullClause() : OMPNoChildClause() {}
  737. public:
  738. /// Build an AST node for a 'full' clause.
  739. ///
  740. /// \param C Context of the AST.
  741. /// \param StartLoc Starting location of the clause.
  742. /// \param EndLoc Ending location of the clause.
  743. static OMPFullClause *Create(const ASTContext &C, SourceLocation StartLoc,
  744. SourceLocation EndLoc);
  745. /// Build an empty 'full' AST node for deserialization.
  746. ///
  747. /// \param C Context of the AST.
  748. static OMPFullClause *CreateEmpty(const ASTContext &C);
  749. };
  750. /// Representation of the 'partial' clause of the '#pragma omp unroll'
  751. /// directive.
  752. ///
  753. /// \code
  754. /// #pragma omp unroll partial(4)
  755. /// for (int i = start; i < end; ++i)
  756. /// \endcode
  757. class OMPPartialClause final : public OMPClause {
  758. friend class OMPClauseReader;
  759. /// Location of '('.
  760. SourceLocation LParenLoc;
  761. /// Optional argument to the clause (unroll factor).
  762. Stmt *Factor;
  763. /// Build an empty clause.
  764. explicit OMPPartialClause() : OMPClause(llvm::omp::OMPC_partial, {}, {}) {}
  765. /// Set the unroll factor.
  766. void setFactor(Expr *E) { Factor = E; }
  767. /// Sets the location of '('.
  768. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  769. public:
  770. /// Build an AST node for a 'partial' clause.
  771. ///
  772. /// \param C Context of the AST.
  773. /// \param StartLoc Location of the 'partial' identifier.
  774. /// \param LParenLoc Location of '('.
  775. /// \param EndLoc Location of ')'.
  776. /// \param Factor Clause argument.
  777. static OMPPartialClause *Create(const ASTContext &C, SourceLocation StartLoc,
  778. SourceLocation LParenLoc,
  779. SourceLocation EndLoc, Expr *Factor);
  780. /// Build an empty 'partial' AST node for deserialization.
  781. ///
  782. /// \param C Context of the AST.
  783. static OMPPartialClause *CreateEmpty(const ASTContext &C);
  784. /// Returns the location of '('.
  785. SourceLocation getLParenLoc() const { return LParenLoc; }
  786. /// Returns the argument of the clause or nullptr if not set.
  787. Expr *getFactor() const { return cast_or_null<Expr>(Factor); }
  788. child_range children() { return child_range(&Factor, &Factor + 1); }
  789. const_child_range children() const {
  790. return const_child_range(&Factor, &Factor + 1);
  791. }
  792. child_range used_children() {
  793. return child_range(child_iterator(), child_iterator());
  794. }
  795. const_child_range used_children() const {
  796. return const_child_range(const_child_iterator(), const_child_iterator());
  797. }
  798. static bool classof(const OMPClause *T) {
  799. return T->getClauseKind() == llvm::omp::OMPC_partial;
  800. }
  801. };
  802. /// This represents 'collapse' clause in the '#pragma omp ...'
  803. /// directive.
  804. ///
  805. /// \code
  806. /// #pragma omp simd collapse(3)
  807. /// \endcode
  808. /// In this example directive '#pragma omp simd' has clause 'collapse'
  809. /// with single expression '3'.
  810. /// The parameter must be a constant positive integer expression, it specifies
  811. /// the number of nested loops that should be collapsed into a single iteration
  812. /// space.
  813. class OMPCollapseClause final
  814. : public OMPOneStmtClause<llvm::omp::OMPC_collapse, OMPClause> {
  815. friend class OMPClauseReader;
  816. /// Set the number of associated for-loops.
  817. void setNumForLoops(Expr *Num) { setStmt(Num); }
  818. public:
  819. /// Build 'collapse' clause.
  820. ///
  821. /// \param Num Expression associated with this clause.
  822. /// \param StartLoc Starting location of the clause.
  823. /// \param LParenLoc Location of '('.
  824. /// \param EndLoc Ending location of the clause.
  825. OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
  826. SourceLocation LParenLoc, SourceLocation EndLoc)
  827. : OMPOneStmtClause(Num, StartLoc, LParenLoc, EndLoc) {}
  828. /// Build an empty clause.
  829. explicit OMPCollapseClause() : OMPOneStmtClause() {}
  830. /// Return the number of associated for-loops.
  831. Expr *getNumForLoops() const { return getStmtAs<Expr>(); }
  832. };
  833. /// This represents 'default' clause in the '#pragma omp ...' directive.
  834. ///
  835. /// \code
  836. /// #pragma omp parallel default(shared)
  837. /// \endcode
  838. /// In this example directive '#pragma omp parallel' has simple 'default'
  839. /// clause with kind 'shared'.
  840. class OMPDefaultClause : public OMPClause {
  841. friend class OMPClauseReader;
  842. /// Location of '('.
  843. SourceLocation LParenLoc;
  844. /// A kind of the 'default' clause.
  845. llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
  846. /// Start location of the kind in source code.
  847. SourceLocation KindKwLoc;
  848. /// Set kind of the clauses.
  849. ///
  850. /// \param K Argument of clause.
  851. void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
  852. /// Set argument location.
  853. ///
  854. /// \param KLoc Argument location.
  855. void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
  856. public:
  857. /// Build 'default' clause with argument \a A ('none' or 'shared').
  858. ///
  859. /// \param A Argument of the clause ('none' or 'shared').
  860. /// \param ALoc Starting location of the argument.
  861. /// \param StartLoc Starting location of the clause.
  862. /// \param LParenLoc Location of '('.
  863. /// \param EndLoc Ending location of the clause.
  864. OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
  865. SourceLocation StartLoc, SourceLocation LParenLoc,
  866. SourceLocation EndLoc)
  867. : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
  868. LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
  869. /// Build an empty clause.
  870. OMPDefaultClause()
  871. : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
  872. }
  873. /// Sets the location of '('.
  874. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  875. /// Returns the location of '('.
  876. SourceLocation getLParenLoc() const { return LParenLoc; }
  877. /// Returns kind of the clause.
  878. llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
  879. /// Returns location of clause kind.
  880. SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
  881. child_range children() {
  882. return child_range(child_iterator(), child_iterator());
  883. }
  884. const_child_range children() const {
  885. return const_child_range(const_child_iterator(), const_child_iterator());
  886. }
  887. child_range used_children() {
  888. return child_range(child_iterator(), child_iterator());
  889. }
  890. const_child_range used_children() const {
  891. return const_child_range(const_child_iterator(), const_child_iterator());
  892. }
  893. static bool classof(const OMPClause *T) {
  894. return T->getClauseKind() == llvm::omp::OMPC_default;
  895. }
  896. };
  897. /// This represents 'proc_bind' clause in the '#pragma omp ...'
  898. /// directive.
  899. ///
  900. /// \code
  901. /// #pragma omp parallel proc_bind(master)
  902. /// \endcode
  903. /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
  904. /// clause with kind 'master'.
  905. class OMPProcBindClause : public OMPClause {
  906. friend class OMPClauseReader;
  907. /// Location of '('.
  908. SourceLocation LParenLoc;
  909. /// A kind of the 'proc_bind' clause.
  910. llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
  911. /// Start location of the kind in source code.
  912. SourceLocation KindKwLoc;
  913. /// Set kind of the clause.
  914. ///
  915. /// \param K Kind of clause.
  916. void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
  917. /// Set clause kind location.
  918. ///
  919. /// \param KLoc Kind location.
  920. void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
  921. public:
  922. /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
  923. /// 'spread').
  924. ///
  925. /// \param A Argument of the clause ('master', 'close' or 'spread').
  926. /// \param ALoc Starting location of the argument.
  927. /// \param StartLoc Starting location of the clause.
  928. /// \param LParenLoc Location of '('.
  929. /// \param EndLoc Ending location of the clause.
  930. OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
  931. SourceLocation StartLoc, SourceLocation LParenLoc,
  932. SourceLocation EndLoc)
  933. : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
  934. LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
  935. /// Build an empty clause.
  936. OMPProcBindClause()
  937. : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
  938. SourceLocation()) {}
  939. /// Sets the location of '('.
  940. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  941. /// Returns the location of '('.
  942. SourceLocation getLParenLoc() const { return LParenLoc; }
  943. /// Returns kind of the clause.
  944. llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
  945. /// Returns location of clause kind.
  946. SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
  947. child_range children() {
  948. return child_range(child_iterator(), child_iterator());
  949. }
  950. const_child_range children() const {
  951. return const_child_range(const_child_iterator(), const_child_iterator());
  952. }
  953. child_range used_children() {
  954. return child_range(child_iterator(), child_iterator());
  955. }
  956. const_child_range used_children() const {
  957. return const_child_range(const_child_iterator(), const_child_iterator());
  958. }
  959. static bool classof(const OMPClause *T) {
  960. return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
  961. }
  962. };
  963. /// This represents 'unified_address' clause in the '#pragma omp requires'
  964. /// directive.
  965. ///
  966. /// \code
  967. /// #pragma omp requires unified_address
  968. /// \endcode
  969. /// In this example directive '#pragma omp requires' has 'unified_address'
  970. /// clause.
  971. class OMPUnifiedAddressClause final
  972. : public OMPNoChildClause<llvm::omp::OMPC_unified_address> {
  973. public:
  974. friend class OMPClauseReader;
  975. /// Build 'unified_address' clause.
  976. ///
  977. /// \param StartLoc Starting location of the clause.
  978. /// \param EndLoc Ending location of the clause.
  979. OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
  980. : OMPNoChildClause(StartLoc, EndLoc) {}
  981. /// Build an empty clause.
  982. OMPUnifiedAddressClause() : OMPNoChildClause() {}
  983. };
  984. /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
  985. /// directive.
  986. ///
  987. /// \code
  988. /// #pragma omp requires unified_shared_memory
  989. /// \endcode
  990. /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
  991. /// clause.
  992. class OMPUnifiedSharedMemoryClause final : public OMPClause {
  993. public:
  994. friend class OMPClauseReader;
  995. /// Build 'unified_shared_memory' clause.
  996. ///
  997. /// \param StartLoc Starting location of the clause.
  998. /// \param EndLoc Ending location of the clause.
  999. OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1000. : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
  1001. /// Build an empty clause.
  1002. OMPUnifiedSharedMemoryClause()
  1003. : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
  1004. SourceLocation()) {}
  1005. child_range children() {
  1006. return child_range(child_iterator(), child_iterator());
  1007. }
  1008. const_child_range children() const {
  1009. return const_child_range(const_child_iterator(), const_child_iterator());
  1010. }
  1011. child_range used_children() {
  1012. return child_range(child_iterator(), child_iterator());
  1013. }
  1014. const_child_range used_children() const {
  1015. return const_child_range(const_child_iterator(), const_child_iterator());
  1016. }
  1017. static bool classof(const OMPClause *T) {
  1018. return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
  1019. }
  1020. };
  1021. /// This represents 'reverse_offload' clause in the '#pragma omp requires'
  1022. /// directive.
  1023. ///
  1024. /// \code
  1025. /// #pragma omp requires reverse_offload
  1026. /// \endcode
  1027. /// In this example directive '#pragma omp requires' has 'reverse_offload'
  1028. /// clause.
  1029. class OMPReverseOffloadClause final : public OMPClause {
  1030. public:
  1031. friend class OMPClauseReader;
  1032. /// Build 'reverse_offload' clause.
  1033. ///
  1034. /// \param StartLoc Starting location of the clause.
  1035. /// \param EndLoc Ending location of the clause.
  1036. OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1037. : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
  1038. /// Build an empty clause.
  1039. OMPReverseOffloadClause()
  1040. : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
  1041. SourceLocation()) {}
  1042. child_range children() {
  1043. return child_range(child_iterator(), child_iterator());
  1044. }
  1045. const_child_range children() const {
  1046. return const_child_range(const_child_iterator(), const_child_iterator());
  1047. }
  1048. child_range used_children() {
  1049. return child_range(child_iterator(), child_iterator());
  1050. }
  1051. const_child_range used_children() const {
  1052. return const_child_range(const_child_iterator(), const_child_iterator());
  1053. }
  1054. static bool classof(const OMPClause *T) {
  1055. return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
  1056. }
  1057. };
  1058. /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
  1059. /// directive.
  1060. ///
  1061. /// \code
  1062. /// #pragma omp requires dynamic_allocators
  1063. /// \endcode
  1064. /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
  1065. /// clause.
  1066. class OMPDynamicAllocatorsClause final : public OMPClause {
  1067. public:
  1068. friend class OMPClauseReader;
  1069. /// Build 'dynamic_allocators' clause.
  1070. ///
  1071. /// \param StartLoc Starting location of the clause.
  1072. /// \param EndLoc Ending location of the clause.
  1073. OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1074. : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
  1075. /// Build an empty clause.
  1076. OMPDynamicAllocatorsClause()
  1077. : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
  1078. SourceLocation()) {}
  1079. child_range children() {
  1080. return child_range(child_iterator(), child_iterator());
  1081. }
  1082. const_child_range children() const {
  1083. return const_child_range(const_child_iterator(), const_child_iterator());
  1084. }
  1085. child_range used_children() {
  1086. return child_range(child_iterator(), child_iterator());
  1087. }
  1088. const_child_range used_children() const {
  1089. return const_child_range(const_child_iterator(), const_child_iterator());
  1090. }
  1091. static bool classof(const OMPClause *T) {
  1092. return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
  1093. }
  1094. };
  1095. /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
  1096. /// requires' directive.
  1097. ///
  1098. /// \code
  1099. /// #pragma omp requires atomic_default_mem_order(seq_cst)
  1100. /// \endcode
  1101. /// In this example directive '#pragma omp requires' has simple
  1102. /// atomic_default_mem_order' clause with kind 'seq_cst'.
  1103. class OMPAtomicDefaultMemOrderClause final : public OMPClause {
  1104. friend class OMPClauseReader;
  1105. /// Location of '('
  1106. SourceLocation LParenLoc;
  1107. /// A kind of the 'atomic_default_mem_order' clause.
  1108. OpenMPAtomicDefaultMemOrderClauseKind Kind =
  1109. OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown;
  1110. /// Start location of the kind in source code.
  1111. SourceLocation KindKwLoc;
  1112. /// Set kind of the clause.
  1113. ///
  1114. /// \param K Kind of clause.
  1115. void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
  1116. Kind = K;
  1117. }
  1118. /// Set clause kind location.
  1119. ///
  1120. /// \param KLoc Kind location.
  1121. void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
  1122. KindKwLoc = KLoc;
  1123. }
  1124. public:
  1125. /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
  1126. /// 'acq_rel' or 'relaxed').
  1127. ///
  1128. /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
  1129. /// \param ALoc Starting location of the argument.
  1130. /// \param StartLoc Starting location of the clause.
  1131. /// \param LParenLoc Location of '('.
  1132. /// \param EndLoc Ending location of the clause.
  1133. OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
  1134. SourceLocation ALoc, SourceLocation StartLoc,
  1135. SourceLocation LParenLoc,
  1136. SourceLocation EndLoc)
  1137. : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
  1138. LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
  1139. /// Build an empty clause.
  1140. OMPAtomicDefaultMemOrderClause()
  1141. : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
  1142. SourceLocation()) {}
  1143. /// Sets the location of '('.
  1144. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  1145. /// Returns the locaiton of '('.
  1146. SourceLocation getLParenLoc() const { return LParenLoc; }
  1147. /// Returns kind of the clause.
  1148. OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
  1149. return Kind;
  1150. }
  1151. /// Returns location of clause kind.
  1152. SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
  1153. child_range children() {
  1154. return child_range(child_iterator(), child_iterator());
  1155. }
  1156. const_child_range children() const {
  1157. return const_child_range(const_child_iterator(), const_child_iterator());
  1158. }
  1159. child_range used_children() {
  1160. return child_range(child_iterator(), child_iterator());
  1161. }
  1162. const_child_range used_children() const {
  1163. return const_child_range(const_child_iterator(), const_child_iterator());
  1164. }
  1165. static bool classof(const OMPClause *T) {
  1166. return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
  1167. }
  1168. };
  1169. /// This represents 'at' clause in the '#pragma omp error' directive
  1170. ///
  1171. /// \code
  1172. /// #pragma omp error at(compilation)
  1173. /// \endcode
  1174. /// In this example directive '#pragma omp error' has simple
  1175. /// 'at' clause with kind 'complilation'.
  1176. class OMPAtClause final : public OMPClause {
  1177. friend class OMPClauseReader;
  1178. /// Location of '('
  1179. SourceLocation LParenLoc;
  1180. /// A kind of the 'at' clause.
  1181. OpenMPAtClauseKind Kind = OMPC_AT_unknown;
  1182. /// Start location of the kind in source code.
  1183. SourceLocation KindKwLoc;
  1184. /// Set kind of the clause.
  1185. ///
  1186. /// \param K Kind of clause.
  1187. void setAtKind(OpenMPAtClauseKind K) { Kind = K; }
  1188. /// Set clause kind location.
  1189. ///
  1190. /// \param KLoc Kind location.
  1191. void setAtKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
  1192. /// Sets the location of '('.
  1193. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  1194. public:
  1195. /// Build 'at' clause with argument \a A ('compilation' or 'execution').
  1196. ///
  1197. /// \param A Argument of the clause ('compilation' or 'execution').
  1198. /// \param ALoc Starting location of the argument.
  1199. /// \param StartLoc Starting location of the clause.
  1200. /// \param LParenLoc Location of '('.
  1201. /// \param EndLoc Ending location of the clause.
  1202. OMPAtClause(OpenMPAtClauseKind A, SourceLocation ALoc,
  1203. SourceLocation StartLoc, SourceLocation LParenLoc,
  1204. SourceLocation EndLoc)
  1205. : OMPClause(llvm::omp::OMPC_at, StartLoc, EndLoc), LParenLoc(LParenLoc),
  1206. Kind(A), KindKwLoc(ALoc) {}
  1207. /// Build an empty clause.
  1208. OMPAtClause()
  1209. : OMPClause(llvm::omp::OMPC_at, SourceLocation(), SourceLocation()) {}
  1210. /// Returns the locaiton of '('.
  1211. SourceLocation getLParenLoc() const { return LParenLoc; }
  1212. /// Returns kind of the clause.
  1213. OpenMPAtClauseKind getAtKind() const { return Kind; }
  1214. /// Returns location of clause kind.
  1215. SourceLocation getAtKindKwLoc() const { return KindKwLoc; }
  1216. child_range children() {
  1217. return child_range(child_iterator(), child_iterator());
  1218. }
  1219. const_child_range children() const {
  1220. return const_child_range(const_child_iterator(), const_child_iterator());
  1221. }
  1222. child_range used_children() {
  1223. return child_range(child_iterator(), child_iterator());
  1224. }
  1225. const_child_range used_children() const {
  1226. return const_child_range(const_child_iterator(), const_child_iterator());
  1227. }
  1228. static bool classof(const OMPClause *T) {
  1229. return T->getClauseKind() == llvm::omp::OMPC_at;
  1230. }
  1231. };
  1232. /// This represents 'severity' clause in the '#pragma omp error' directive
  1233. ///
  1234. /// \code
  1235. /// #pragma omp error severity(fatal)
  1236. /// \endcode
  1237. /// In this example directive '#pragma omp error' has simple
  1238. /// 'severity' clause with kind 'fatal'.
  1239. class OMPSeverityClause final : public OMPClause {
  1240. friend class OMPClauseReader;
  1241. /// Location of '('
  1242. SourceLocation LParenLoc;
  1243. /// A kind of the 'severity' clause.
  1244. OpenMPSeverityClauseKind Kind = OMPC_SEVERITY_unknown;
  1245. /// Start location of the kind in source code.
  1246. SourceLocation KindKwLoc;
  1247. /// Set kind of the clause.
  1248. ///
  1249. /// \param K Kind of clause.
  1250. void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
  1251. /// Set clause kind location.
  1252. ///
  1253. /// \param KLoc Kind location.
  1254. void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
  1255. /// Sets the location of '('.
  1256. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  1257. public:
  1258. /// Build 'severity' clause with argument \a A ('fatal' or 'warning').
  1259. ///
  1260. /// \param A Argument of the clause ('fatal' or 'warning').
  1261. /// \param ALoc Starting location of the argument.
  1262. /// \param StartLoc Starting location of the clause.
  1263. /// \param LParenLoc Location of '('.
  1264. /// \param EndLoc Ending location of the clause.
  1265. OMPSeverityClause(OpenMPSeverityClauseKind A, SourceLocation ALoc,
  1266. SourceLocation StartLoc, SourceLocation LParenLoc,
  1267. SourceLocation EndLoc)
  1268. : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
  1269. LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
  1270. /// Build an empty clause.
  1271. OMPSeverityClause()
  1272. : OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
  1273. SourceLocation()) {}
  1274. /// Returns the locaiton of '('.
  1275. SourceLocation getLParenLoc() const { return LParenLoc; }
  1276. /// Returns kind of the clause.
  1277. OpenMPSeverityClauseKind getSeverityKind() const { return Kind; }
  1278. /// Returns location of clause kind.
  1279. SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
  1280. child_range children() {
  1281. return child_range(child_iterator(), child_iterator());
  1282. }
  1283. const_child_range children() const {
  1284. return const_child_range(const_child_iterator(), const_child_iterator());
  1285. }
  1286. child_range used_children() {
  1287. return child_range(child_iterator(), child_iterator());
  1288. }
  1289. const_child_range used_children() const {
  1290. return const_child_range(const_child_iterator(), const_child_iterator());
  1291. }
  1292. static bool classof(const OMPClause *T) {
  1293. return T->getClauseKind() == llvm::omp::OMPC_severity;
  1294. }
  1295. };
  1296. /// This represents 'message' clause in the '#pragma omp error' directive
  1297. ///
  1298. /// \code
  1299. /// #pragma omp error message("GNU compiler required.")
  1300. /// \endcode
  1301. /// In this example directive '#pragma omp error' has simple
  1302. /// 'message' clause with user error message of "GNU compiler required.".
  1303. class OMPMessageClause final : public OMPClause {
  1304. friend class OMPClauseReader;
  1305. /// Location of '('
  1306. SourceLocation LParenLoc;
  1307. // Expression of the 'message' clause.
  1308. Stmt *MessageString = nullptr;
  1309. /// Set message string of the clause.
  1310. void setMessageString(Expr *MS) { MessageString = MS; }
  1311. /// Sets the location of '('.
  1312. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  1313. public:
  1314. /// Build 'message' clause with message string argument
  1315. ///
  1316. /// \param MS Argument of the clause (message string).
  1317. /// \param StartLoc Starting location of the clause.
  1318. /// \param LParenLoc Location of '('.
  1319. /// \param EndLoc Ending location of the clause.
  1320. OMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc,
  1321. SourceLocation EndLoc)
  1322. : OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
  1323. LParenLoc(LParenLoc), MessageString(MS) {}
  1324. /// Build an empty clause.
  1325. OMPMessageClause()
  1326. : OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) {
  1327. }
  1328. /// Returns the locaiton of '('.
  1329. SourceLocation getLParenLoc() const { return LParenLoc; }
  1330. /// Returns message string of the clause.
  1331. Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); }
  1332. child_range children() {
  1333. return child_range(&MessageString, &MessageString + 1);
  1334. }
  1335. const_child_range children() const {
  1336. return const_child_range(&MessageString, &MessageString + 1);
  1337. }
  1338. child_range used_children() {
  1339. return child_range(child_iterator(), child_iterator());
  1340. }
  1341. const_child_range used_children() const {
  1342. return const_child_range(const_child_iterator(), const_child_iterator());
  1343. }
  1344. static bool classof(const OMPClause *T) {
  1345. return T->getClauseKind() == llvm::omp::OMPC_message;
  1346. }
  1347. };
  1348. /// This represents 'schedule' clause in the '#pragma omp ...' directive.
  1349. ///
  1350. /// \code
  1351. /// #pragma omp for schedule(static, 3)
  1352. /// \endcode
  1353. /// In this example directive '#pragma omp for' has 'schedule' clause with
  1354. /// arguments 'static' and '3'.
  1355. class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
  1356. friend class OMPClauseReader;
  1357. /// Location of '('.
  1358. SourceLocation LParenLoc;
  1359. /// A kind of the 'schedule' clause.
  1360. OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
  1361. /// Modifiers for 'schedule' clause.
  1362. enum {FIRST, SECOND, NUM_MODIFIERS};
  1363. OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
  1364. /// Locations of modifiers.
  1365. SourceLocation ModifiersLoc[NUM_MODIFIERS];
  1366. /// Start location of the schedule ind in source code.
  1367. SourceLocation KindLoc;
  1368. /// Location of ',' (if any).
  1369. SourceLocation CommaLoc;
  1370. /// Chunk size.
  1371. Expr *ChunkSize = nullptr;
  1372. /// Set schedule kind.
  1373. ///
  1374. /// \param K Schedule kind.
  1375. void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
  1376. /// Set the first schedule modifier.
  1377. ///
  1378. /// \param M Schedule modifier.
  1379. void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
  1380. Modifiers[FIRST] = M;
  1381. }
  1382. /// Set the second schedule modifier.
  1383. ///
  1384. /// \param M Schedule modifier.
  1385. void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
  1386. Modifiers[SECOND] = M;
  1387. }
  1388. /// Set location of the first schedule modifier.
  1389. void setFirstScheduleModifierLoc(SourceLocation Loc) {
  1390. ModifiersLoc[FIRST] = Loc;
  1391. }
  1392. /// Set location of the second schedule modifier.
  1393. void setSecondScheduleModifierLoc(SourceLocation Loc) {
  1394. ModifiersLoc[SECOND] = Loc;
  1395. }
  1396. /// Set schedule modifier location.
  1397. ///
  1398. /// \param M Schedule modifier location.
  1399. void setScheduleModifer(OpenMPScheduleClauseModifier M) {
  1400. if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
  1401. Modifiers[FIRST] = M;
  1402. else {
  1403. assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
  1404. Modifiers[SECOND] = M;
  1405. }
  1406. }
  1407. /// Sets the location of '('.
  1408. ///
  1409. /// \param Loc Location of '('.
  1410. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  1411. /// Set schedule kind start location.
  1412. ///
  1413. /// \param KLoc Schedule kind location.
  1414. void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
  1415. /// Set location of ','.
  1416. ///
  1417. /// \param Loc Location of ','.
  1418. void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
  1419. /// Set chunk size.
  1420. ///
  1421. /// \param E Chunk size.
  1422. void setChunkSize(Expr *E) { ChunkSize = E; }
  1423. public:
  1424. /// Build 'schedule' clause with schedule kind \a Kind and chunk size
  1425. /// expression \a ChunkSize.
  1426. ///
  1427. /// \param StartLoc Starting location of the clause.
  1428. /// \param LParenLoc Location of '('.
  1429. /// \param KLoc Starting location of the argument.
  1430. /// \param CommaLoc Location of ','.
  1431. /// \param EndLoc Ending location of the clause.
  1432. /// \param Kind Schedule kind.
  1433. /// \param ChunkSize Chunk size.
  1434. /// \param HelperChunkSize Helper chunk size for combined directives.
  1435. /// \param M1 The first modifier applied to 'schedule' clause.
  1436. /// \param M1Loc Location of the first modifier
  1437. /// \param M2 The second modifier applied to 'schedule' clause.
  1438. /// \param M2Loc Location of the second modifier
  1439. OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  1440. SourceLocation KLoc, SourceLocation CommaLoc,
  1441. SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
  1442. Expr *ChunkSize, Stmt *HelperChunkSize,
  1443. OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
  1444. OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
  1445. : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
  1446. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
  1447. KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
  1448. setPreInitStmt(HelperChunkSize);
  1449. Modifiers[FIRST] = M1;
  1450. Modifiers[SECOND] = M2;
  1451. ModifiersLoc[FIRST] = M1Loc;
  1452. ModifiersLoc[SECOND] = M2Loc;
  1453. }
  1454. /// Build an empty clause.
  1455. explicit OMPScheduleClause()
  1456. : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
  1457. OMPClauseWithPreInit(this) {
  1458. Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
  1459. Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
  1460. }
  1461. /// Get kind of the clause.
  1462. OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
  1463. /// Get the first modifier of the clause.
  1464. OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
  1465. return Modifiers[FIRST];
  1466. }
  1467. /// Get the second modifier of the clause.
  1468. OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
  1469. return Modifiers[SECOND];
  1470. }
  1471. /// Get location of '('.
  1472. SourceLocation getLParenLoc() { return LParenLoc; }
  1473. /// Get kind location.
  1474. SourceLocation getScheduleKindLoc() { return KindLoc; }
  1475. /// Get the first modifier location.
  1476. SourceLocation getFirstScheduleModifierLoc() const {
  1477. return ModifiersLoc[FIRST];
  1478. }
  1479. /// Get the second modifier location.
  1480. SourceLocation getSecondScheduleModifierLoc() const {
  1481. return ModifiersLoc[SECOND];
  1482. }
  1483. /// Get location of ','.
  1484. SourceLocation getCommaLoc() { return CommaLoc; }
  1485. /// Get chunk size.
  1486. Expr *getChunkSize() { return ChunkSize; }
  1487. /// Get chunk size.
  1488. const Expr *getChunkSize() const { return ChunkSize; }
  1489. child_range children() {
  1490. return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
  1491. reinterpret_cast<Stmt **>(&ChunkSize) + 1);
  1492. }
  1493. const_child_range children() const {
  1494. auto Children = const_cast<OMPScheduleClause *>(this)->children();
  1495. return const_child_range(Children.begin(), Children.end());
  1496. }
  1497. child_range used_children() {
  1498. return child_range(child_iterator(), child_iterator());
  1499. }
  1500. const_child_range used_children() const {
  1501. return const_child_range(const_child_iterator(), const_child_iterator());
  1502. }
  1503. static bool classof(const OMPClause *T) {
  1504. return T->getClauseKind() == llvm::omp::OMPC_schedule;
  1505. }
  1506. };
  1507. /// This represents 'ordered' clause in the '#pragma omp ...' directive.
  1508. ///
  1509. /// \code
  1510. /// #pragma omp for ordered (2)
  1511. /// \endcode
  1512. /// In this example directive '#pragma omp for' has 'ordered' clause with
  1513. /// parameter 2.
  1514. class OMPOrderedClause final
  1515. : public OMPClause,
  1516. private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
  1517. friend class OMPClauseReader;
  1518. friend TrailingObjects;
  1519. /// Location of '('.
  1520. SourceLocation LParenLoc;
  1521. /// Number of for-loops.
  1522. Stmt *NumForLoops = nullptr;
  1523. /// Real number of loops.
  1524. unsigned NumberOfLoops = 0;
  1525. /// Build 'ordered' clause.
  1526. ///
  1527. /// \param Num Expression, possibly associated with this clause.
  1528. /// \param NumLoops Number of loops, associated with this clause.
  1529. /// \param StartLoc Starting location of the clause.
  1530. /// \param LParenLoc Location of '('.
  1531. /// \param EndLoc Ending location of the clause.
  1532. OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
  1533. SourceLocation LParenLoc, SourceLocation EndLoc)
  1534. : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
  1535. LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
  1536. /// Build an empty clause.
  1537. explicit OMPOrderedClause(unsigned NumLoops)
  1538. : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
  1539. NumberOfLoops(NumLoops) {}
  1540. /// Set the number of associated for-loops.
  1541. void setNumForLoops(Expr *Num) { NumForLoops = Num; }
  1542. public:
  1543. /// Build 'ordered' clause.
  1544. ///
  1545. /// \param Num Expression, possibly associated with this clause.
  1546. /// \param NumLoops Number of loops, associated with this clause.
  1547. /// \param StartLoc Starting location of the clause.
  1548. /// \param LParenLoc Location of '('.
  1549. /// \param EndLoc Ending location of the clause.
  1550. static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
  1551. unsigned NumLoops, SourceLocation StartLoc,
  1552. SourceLocation LParenLoc,
  1553. SourceLocation EndLoc);
  1554. /// Build an empty clause.
  1555. static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
  1556. /// Sets the location of '('.
  1557. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  1558. /// Returns the location of '('.
  1559. SourceLocation getLParenLoc() const { return LParenLoc; }
  1560. /// Return the number of associated for-loops.
  1561. Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
  1562. /// Set number of iterations for the specified loop.
  1563. void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
  1564. /// Get number of iterations for all the loops.
  1565. ArrayRef<Expr *> getLoopNumIterations() const;
  1566. /// Set loop counter for the specified loop.
  1567. void setLoopCounter(unsigned NumLoop, Expr *Counter);
  1568. /// Get loops counter for the specified loop.
  1569. Expr *getLoopCounter(unsigned NumLoop);
  1570. const Expr *getLoopCounter(unsigned NumLoop) const;
  1571. child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
  1572. const_child_range children() const {
  1573. return const_child_range(&NumForLoops, &NumForLoops + 1);
  1574. }
  1575. child_range used_children() {
  1576. return child_range(child_iterator(), child_iterator());
  1577. }
  1578. const_child_range used_children() const {
  1579. return const_child_range(const_child_iterator(), const_child_iterator());
  1580. }
  1581. static bool classof(const OMPClause *T) {
  1582. return T->getClauseKind() == llvm::omp::OMPC_ordered;
  1583. }
  1584. };
  1585. /// This represents 'nowait' clause in the '#pragma omp ...' directive.
  1586. ///
  1587. /// \code
  1588. /// #pragma omp for nowait
  1589. /// \endcode
  1590. /// In this example directive '#pragma omp for' has 'nowait' clause.
  1591. class OMPNowaitClause final : public OMPNoChildClause<llvm::omp::OMPC_nowait> {
  1592. public:
  1593. /// Build 'nowait' clause.
  1594. ///
  1595. /// \param StartLoc Starting location of the clause.
  1596. /// \param EndLoc Ending location of the clause.
  1597. OMPNowaitClause(SourceLocation StartLoc = SourceLocation(),
  1598. SourceLocation EndLoc = SourceLocation())
  1599. : OMPNoChildClause(StartLoc, EndLoc) {}
  1600. };
  1601. /// This represents 'untied' clause in the '#pragma omp ...' directive.
  1602. ///
  1603. /// \code
  1604. /// #pragma omp task untied
  1605. /// \endcode
  1606. /// In this example directive '#pragma omp task' has 'untied' clause.
  1607. class OMPUntiedClause : public OMPClause {
  1608. public:
  1609. /// Build 'untied' clause.
  1610. ///
  1611. /// \param StartLoc Starting location of the clause.
  1612. /// \param EndLoc Ending location of the clause.
  1613. OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1614. : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
  1615. /// Build an empty clause.
  1616. OMPUntiedClause()
  1617. : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
  1618. child_range children() {
  1619. return child_range(child_iterator(), child_iterator());
  1620. }
  1621. const_child_range children() const {
  1622. return const_child_range(const_child_iterator(), const_child_iterator());
  1623. }
  1624. child_range used_children() {
  1625. return child_range(child_iterator(), child_iterator());
  1626. }
  1627. const_child_range used_children() const {
  1628. return const_child_range(const_child_iterator(), const_child_iterator());
  1629. }
  1630. static bool classof(const OMPClause *T) {
  1631. return T->getClauseKind() == llvm::omp::OMPC_untied;
  1632. }
  1633. };
  1634. /// This represents 'mergeable' clause in the '#pragma omp ...'
  1635. /// directive.
  1636. ///
  1637. /// \code
  1638. /// #pragma omp task mergeable
  1639. /// \endcode
  1640. /// In this example directive '#pragma omp task' has 'mergeable' clause.
  1641. class OMPMergeableClause : public OMPClause {
  1642. public:
  1643. /// Build 'mergeable' clause.
  1644. ///
  1645. /// \param StartLoc Starting location of the clause.
  1646. /// \param EndLoc Ending location of the clause.
  1647. OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1648. : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
  1649. /// Build an empty clause.
  1650. OMPMergeableClause()
  1651. : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
  1652. SourceLocation()) {}
  1653. child_range children() {
  1654. return child_range(child_iterator(), child_iterator());
  1655. }
  1656. const_child_range children() const {
  1657. return const_child_range(const_child_iterator(), const_child_iterator());
  1658. }
  1659. child_range used_children() {
  1660. return child_range(child_iterator(), child_iterator());
  1661. }
  1662. const_child_range used_children() const {
  1663. return const_child_range(const_child_iterator(), const_child_iterator());
  1664. }
  1665. static bool classof(const OMPClause *T) {
  1666. return T->getClauseKind() == llvm::omp::OMPC_mergeable;
  1667. }
  1668. };
  1669. /// This represents 'read' clause in the '#pragma omp atomic' directive.
  1670. ///
  1671. /// \code
  1672. /// #pragma omp atomic read
  1673. /// \endcode
  1674. /// In this example directive '#pragma omp atomic' has 'read' clause.
  1675. class OMPReadClause : public OMPClause {
  1676. public:
  1677. /// Build 'read' clause.
  1678. ///
  1679. /// \param StartLoc Starting location of the clause.
  1680. /// \param EndLoc Ending location of the clause.
  1681. OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1682. : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
  1683. /// Build an empty clause.
  1684. OMPReadClause()
  1685. : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
  1686. child_range children() {
  1687. return child_range(child_iterator(), child_iterator());
  1688. }
  1689. const_child_range children() const {
  1690. return const_child_range(const_child_iterator(), const_child_iterator());
  1691. }
  1692. child_range used_children() {
  1693. return child_range(child_iterator(), child_iterator());
  1694. }
  1695. const_child_range used_children() const {
  1696. return const_child_range(const_child_iterator(), const_child_iterator());
  1697. }
  1698. static bool classof(const OMPClause *T) {
  1699. return T->getClauseKind() == llvm::omp::OMPC_read;
  1700. }
  1701. };
  1702. /// This represents 'write' clause in the '#pragma omp atomic' directive.
  1703. ///
  1704. /// \code
  1705. /// #pragma omp atomic write
  1706. /// \endcode
  1707. /// In this example directive '#pragma omp atomic' has 'write' clause.
  1708. class OMPWriteClause : public OMPClause {
  1709. public:
  1710. /// Build 'write' clause.
  1711. ///
  1712. /// \param StartLoc Starting location of the clause.
  1713. /// \param EndLoc Ending location of the clause.
  1714. OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1715. : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
  1716. /// Build an empty clause.
  1717. OMPWriteClause()
  1718. : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
  1719. child_range children() {
  1720. return child_range(child_iterator(), child_iterator());
  1721. }
  1722. const_child_range children() const {
  1723. return const_child_range(const_child_iterator(), const_child_iterator());
  1724. }
  1725. child_range used_children() {
  1726. return child_range(child_iterator(), child_iterator());
  1727. }
  1728. const_child_range used_children() const {
  1729. return const_child_range(const_child_iterator(), const_child_iterator());
  1730. }
  1731. static bool classof(const OMPClause *T) {
  1732. return T->getClauseKind() == llvm::omp::OMPC_write;
  1733. }
  1734. };
  1735. /// This represents 'update' clause in the '#pragma omp atomic'
  1736. /// directive.
  1737. ///
  1738. /// \code
  1739. /// #pragma omp atomic update
  1740. /// \endcode
  1741. /// In this example directive '#pragma omp atomic' has 'update' clause.
  1742. /// Also, this class represents 'update' clause in '#pragma omp depobj'
  1743. /// directive.
  1744. ///
  1745. /// \code
  1746. /// #pragma omp depobj(a) update(in)
  1747. /// \endcode
  1748. /// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
  1749. /// dependence kind.
  1750. class OMPUpdateClause final
  1751. : public OMPClause,
  1752. private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
  1753. OpenMPDependClauseKind> {
  1754. friend class OMPClauseReader;
  1755. friend TrailingObjects;
  1756. /// true if extended version of the clause for 'depobj' directive.
  1757. bool IsExtended = false;
  1758. /// Define the sizes of each trailing object array except the last one. This
  1759. /// is required for TrailingObjects to work properly.
  1760. size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
  1761. // 2 locations: for '(' and argument location.
  1762. return IsExtended ? 2 : 0;
  1763. }
  1764. /// Sets the location of '(' in clause for 'depobj' directive.
  1765. void setLParenLoc(SourceLocation Loc) {
  1766. assert(IsExtended && "Expected extended clause.");
  1767. *getTrailingObjects<SourceLocation>() = Loc;
  1768. }
  1769. /// Sets the location of '(' in clause for 'depobj' directive.
  1770. void setArgumentLoc(SourceLocation Loc) {
  1771. assert(IsExtended && "Expected extended clause.");
  1772. *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
  1773. }
  1774. /// Sets the dependence kind for the clause for 'depobj' directive.
  1775. void setDependencyKind(OpenMPDependClauseKind DK) {
  1776. assert(IsExtended && "Expected extended clause.");
  1777. *getTrailingObjects<OpenMPDependClauseKind>() = DK;
  1778. }
  1779. /// Build 'update' clause.
  1780. ///
  1781. /// \param StartLoc Starting location of the clause.
  1782. /// \param EndLoc Ending location of the clause.
  1783. OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
  1784. bool IsExtended)
  1785. : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
  1786. IsExtended(IsExtended) {}
  1787. /// Build an empty clause.
  1788. OMPUpdateClause(bool IsExtended)
  1789. : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
  1790. IsExtended(IsExtended) {}
  1791. public:
  1792. /// Creates clause for 'atomic' directive.
  1793. ///
  1794. /// \param C AST context.
  1795. /// \param StartLoc Starting location of the clause.
  1796. /// \param EndLoc Ending location of the clause.
  1797. static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
  1798. SourceLocation EndLoc);
  1799. /// Creates clause for 'depobj' directive.
  1800. ///
  1801. /// \param C AST context.
  1802. /// \param StartLoc Starting location of the clause.
  1803. /// \param LParenLoc Location of '('.
  1804. /// \param ArgumentLoc Location of the argument.
  1805. /// \param DK Dependence kind.
  1806. /// \param EndLoc Ending location of the clause.
  1807. static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
  1808. SourceLocation LParenLoc,
  1809. SourceLocation ArgumentLoc,
  1810. OpenMPDependClauseKind DK,
  1811. SourceLocation EndLoc);
  1812. /// Creates an empty clause with the place for \a N variables.
  1813. ///
  1814. /// \param C AST context.
  1815. /// \param IsExtended true if extended clause for 'depobj' directive must be
  1816. /// created.
  1817. static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
  1818. /// Checks if the clause is the extended clauses for 'depobj' directive.
  1819. bool isExtended() const { return IsExtended; }
  1820. child_range children() {
  1821. return child_range(child_iterator(), child_iterator());
  1822. }
  1823. const_child_range children() const {
  1824. return const_child_range(const_child_iterator(), const_child_iterator());
  1825. }
  1826. child_range used_children() {
  1827. return child_range(child_iterator(), child_iterator());
  1828. }
  1829. const_child_range used_children() const {
  1830. return const_child_range(const_child_iterator(), const_child_iterator());
  1831. }
  1832. /// Gets the location of '(' in clause for 'depobj' directive.
  1833. SourceLocation getLParenLoc() const {
  1834. assert(IsExtended && "Expected extended clause.");
  1835. return *getTrailingObjects<SourceLocation>();
  1836. }
  1837. /// Gets the location of argument in clause for 'depobj' directive.
  1838. SourceLocation getArgumentLoc() const {
  1839. assert(IsExtended && "Expected extended clause.");
  1840. return *std::next(getTrailingObjects<SourceLocation>(), 1);
  1841. }
  1842. /// Gets the dependence kind in clause for 'depobj' directive.
  1843. OpenMPDependClauseKind getDependencyKind() const {
  1844. assert(IsExtended && "Expected extended clause.");
  1845. return *getTrailingObjects<OpenMPDependClauseKind>();
  1846. }
  1847. static bool classof(const OMPClause *T) {
  1848. return T->getClauseKind() == llvm::omp::OMPC_update;
  1849. }
  1850. };
  1851. /// This represents 'capture' clause in the '#pragma omp atomic'
  1852. /// directive.
  1853. ///
  1854. /// \code
  1855. /// #pragma omp atomic capture
  1856. /// \endcode
  1857. /// In this example directive '#pragma omp atomic' has 'capture' clause.
  1858. class OMPCaptureClause : public OMPClause {
  1859. public:
  1860. /// Build 'capture' clause.
  1861. ///
  1862. /// \param StartLoc Starting location of the clause.
  1863. /// \param EndLoc Ending location of the clause.
  1864. OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1865. : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
  1866. /// Build an empty clause.
  1867. OMPCaptureClause()
  1868. : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
  1869. }
  1870. child_range children() {
  1871. return child_range(child_iterator(), child_iterator());
  1872. }
  1873. const_child_range children() const {
  1874. return const_child_range(const_child_iterator(), const_child_iterator());
  1875. }
  1876. child_range used_children() {
  1877. return child_range(child_iterator(), child_iterator());
  1878. }
  1879. const_child_range used_children() const {
  1880. return const_child_range(const_child_iterator(), const_child_iterator());
  1881. }
  1882. static bool classof(const OMPClause *T) {
  1883. return T->getClauseKind() == llvm::omp::OMPC_capture;
  1884. }
  1885. };
  1886. /// This represents 'compare' clause in the '#pragma omp atomic'
  1887. /// directive.
  1888. ///
  1889. /// \code
  1890. /// #pragma omp atomic compare
  1891. /// \endcode
  1892. /// In this example directive '#pragma omp atomic' has 'compare' clause.
  1893. class OMPCompareClause final : public OMPClause {
  1894. public:
  1895. /// Build 'compare' clause.
  1896. ///
  1897. /// \param StartLoc Starting location of the clause.
  1898. /// \param EndLoc Ending location of the clause.
  1899. OMPCompareClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1900. : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
  1901. /// Build an empty clause.
  1902. OMPCompareClause()
  1903. : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) {
  1904. }
  1905. child_range children() {
  1906. return child_range(child_iterator(), child_iterator());
  1907. }
  1908. const_child_range children() const {
  1909. return const_child_range(const_child_iterator(), const_child_iterator());
  1910. }
  1911. child_range used_children() {
  1912. return child_range(child_iterator(), child_iterator());
  1913. }
  1914. const_child_range used_children() const {
  1915. return const_child_range(const_child_iterator(), const_child_iterator());
  1916. }
  1917. static bool classof(const OMPClause *T) {
  1918. return T->getClauseKind() == llvm::omp::OMPC_compare;
  1919. }
  1920. };
  1921. /// This represents 'seq_cst' clause in the '#pragma omp atomic'
  1922. /// directive.
  1923. ///
  1924. /// \code
  1925. /// #pragma omp atomic seq_cst
  1926. /// \endcode
  1927. /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
  1928. class OMPSeqCstClause : public OMPClause {
  1929. public:
  1930. /// Build 'seq_cst' clause.
  1931. ///
  1932. /// \param StartLoc Starting location of the clause.
  1933. /// \param EndLoc Ending location of the clause.
  1934. OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1935. : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
  1936. /// Build an empty clause.
  1937. OMPSeqCstClause()
  1938. : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
  1939. }
  1940. child_range children() {
  1941. return child_range(child_iterator(), child_iterator());
  1942. }
  1943. const_child_range children() const {
  1944. return const_child_range(const_child_iterator(), const_child_iterator());
  1945. }
  1946. child_range used_children() {
  1947. return child_range(child_iterator(), child_iterator());
  1948. }
  1949. const_child_range used_children() const {
  1950. return const_child_range(const_child_iterator(), const_child_iterator());
  1951. }
  1952. static bool classof(const OMPClause *T) {
  1953. return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
  1954. }
  1955. };
  1956. /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
  1957. /// directives.
  1958. ///
  1959. /// \code
  1960. /// #pragma omp flush acq_rel
  1961. /// \endcode
  1962. /// In this example directive '#pragma omp flush' has 'acq_rel' clause.
  1963. class OMPAcqRelClause final : public OMPClause {
  1964. public:
  1965. /// Build 'ack_rel' clause.
  1966. ///
  1967. /// \param StartLoc Starting location of the clause.
  1968. /// \param EndLoc Ending location of the clause.
  1969. OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc)
  1970. : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
  1971. /// Build an empty clause.
  1972. OMPAcqRelClause()
  1973. : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
  1974. }
  1975. child_range children() {
  1976. return child_range(child_iterator(), child_iterator());
  1977. }
  1978. const_child_range children() const {
  1979. return const_child_range(const_child_iterator(), const_child_iterator());
  1980. }
  1981. child_range used_children() {
  1982. return child_range(child_iterator(), child_iterator());
  1983. }
  1984. const_child_range used_children() const {
  1985. return const_child_range(const_child_iterator(), const_child_iterator());
  1986. }
  1987. static bool classof(const OMPClause *T) {
  1988. return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
  1989. }
  1990. };
  1991. /// This represents 'acquire' clause in the '#pragma omp atomic|flush'
  1992. /// directives.
  1993. ///
  1994. /// \code
  1995. /// #pragma omp flush acquire
  1996. /// \endcode
  1997. /// In this example directive '#pragma omp flush' has 'acquire' clause.
  1998. class OMPAcquireClause final : public OMPClause {
  1999. public:
  2000. /// Build 'acquire' clause.
  2001. ///
  2002. /// \param StartLoc Starting location of the clause.
  2003. /// \param EndLoc Ending location of the clause.
  2004. OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc)
  2005. : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
  2006. /// Build an empty clause.
  2007. OMPAcquireClause()
  2008. : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
  2009. }
  2010. child_range children() {
  2011. return child_range(child_iterator(), child_iterator());
  2012. }
  2013. const_child_range children() const {
  2014. return const_child_range(const_child_iterator(), const_child_iterator());
  2015. }
  2016. child_range used_children() {
  2017. return child_range(child_iterator(), child_iterator());
  2018. }
  2019. const_child_range used_children() const {
  2020. return const_child_range(const_child_iterator(), const_child_iterator());
  2021. }
  2022. static bool classof(const OMPClause *T) {
  2023. return T->getClauseKind() == llvm::omp::OMPC_acquire;
  2024. }
  2025. };
  2026. /// This represents 'release' clause in the '#pragma omp atomic|flush'
  2027. /// directives.
  2028. ///
  2029. /// \code
  2030. /// #pragma omp flush release
  2031. /// \endcode
  2032. /// In this example directive '#pragma omp flush' has 'release' clause.
  2033. class OMPReleaseClause final : public OMPClause {
  2034. public:
  2035. /// Build 'release' clause.
  2036. ///
  2037. /// \param StartLoc Starting location of the clause.
  2038. /// \param EndLoc Ending location of the clause.
  2039. OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc)
  2040. : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
  2041. /// Build an empty clause.
  2042. OMPReleaseClause()
  2043. : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
  2044. }
  2045. child_range children() {
  2046. return child_range(child_iterator(), child_iterator());
  2047. }
  2048. const_child_range children() const {
  2049. return const_child_range(const_child_iterator(), const_child_iterator());
  2050. }
  2051. child_range used_children() {
  2052. return child_range(child_iterator(), child_iterator());
  2053. }
  2054. const_child_range used_children() const {
  2055. return const_child_range(const_child_iterator(), const_child_iterator());
  2056. }
  2057. static bool classof(const OMPClause *T) {
  2058. return T->getClauseKind() == llvm::omp::OMPC_release;
  2059. }
  2060. };
  2061. /// This represents 'relaxed' clause in the '#pragma omp atomic'
  2062. /// directives.
  2063. ///
  2064. /// \code
  2065. /// #pragma omp atomic relaxed
  2066. /// \endcode
  2067. /// In this example directive '#pragma omp atomic' has 'relaxed' clause.
  2068. class OMPRelaxedClause final : public OMPClause {
  2069. public:
  2070. /// Build 'relaxed' clause.
  2071. ///
  2072. /// \param StartLoc Starting location of the clause.
  2073. /// \param EndLoc Ending location of the clause.
  2074. OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc)
  2075. : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
  2076. /// Build an empty clause.
  2077. OMPRelaxedClause()
  2078. : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
  2079. }
  2080. child_range children() {
  2081. return child_range(child_iterator(), child_iterator());
  2082. }
  2083. const_child_range children() const {
  2084. return const_child_range(const_child_iterator(), const_child_iterator());
  2085. }
  2086. child_range used_children() {
  2087. return child_range(child_iterator(), child_iterator());
  2088. }
  2089. const_child_range used_children() const {
  2090. return const_child_range(const_child_iterator(), const_child_iterator());
  2091. }
  2092. static bool classof(const OMPClause *T) {
  2093. return T->getClauseKind() == llvm::omp::OMPC_relaxed;
  2094. }
  2095. };
  2096. /// This represents clause 'private' in the '#pragma omp ...' directives.
  2097. ///
  2098. /// \code
  2099. /// #pragma omp parallel private(a,b)
  2100. /// \endcode
  2101. /// In this example directive '#pragma omp parallel' has clause 'private'
  2102. /// with the variables 'a' and 'b'.
  2103. class OMPPrivateClause final
  2104. : public OMPVarListClause<OMPPrivateClause>,
  2105. private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
  2106. friend class OMPClauseReader;
  2107. friend OMPVarListClause;
  2108. friend TrailingObjects;
  2109. /// Build clause with number of variables \a N.
  2110. ///
  2111. /// \param StartLoc Starting location of the clause.
  2112. /// \param LParenLoc Location of '('.
  2113. /// \param EndLoc Ending location of the clause.
  2114. /// \param N Number of the variables in the clause.
  2115. OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  2116. SourceLocation EndLoc, unsigned N)
  2117. : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
  2118. LParenLoc, EndLoc, N) {}
  2119. /// Build an empty clause.
  2120. ///
  2121. /// \param N Number of variables.
  2122. explicit OMPPrivateClause(unsigned N)
  2123. : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
  2124. SourceLocation(), SourceLocation(),
  2125. SourceLocation(), N) {}
  2126. /// Sets the list of references to private copies with initializers for
  2127. /// new private variables.
  2128. /// \param VL List of references.
  2129. void setPrivateCopies(ArrayRef<Expr *> VL);
  2130. /// Gets the list of references to private copies with initializers for
  2131. /// new private variables.
  2132. MutableArrayRef<Expr *> getPrivateCopies() {
  2133. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  2134. }
  2135. ArrayRef<const Expr *> getPrivateCopies() const {
  2136. return llvm::ArrayRef(varlist_end(), varlist_size());
  2137. }
  2138. public:
  2139. /// Creates clause with a list of variables \a VL.
  2140. ///
  2141. /// \param C AST context.
  2142. /// \param StartLoc Starting location of the clause.
  2143. /// \param LParenLoc Location of '('.
  2144. /// \param EndLoc Ending location of the clause.
  2145. /// \param VL List of references to the variables.
  2146. /// \param PrivateVL List of references to private copies with initializers.
  2147. static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
  2148. SourceLocation LParenLoc,
  2149. SourceLocation EndLoc, ArrayRef<Expr *> VL,
  2150. ArrayRef<Expr *> PrivateVL);
  2151. /// Creates an empty clause with the place for \a N variables.
  2152. ///
  2153. /// \param C AST context.
  2154. /// \param N The number of variables.
  2155. static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
  2156. using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
  2157. using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
  2158. using private_copies_range = llvm::iterator_range<private_copies_iterator>;
  2159. using private_copies_const_range =
  2160. llvm::iterator_range<private_copies_const_iterator>;
  2161. private_copies_range private_copies() {
  2162. return private_copies_range(getPrivateCopies().begin(),
  2163. getPrivateCopies().end());
  2164. }
  2165. private_copies_const_range private_copies() const {
  2166. return private_copies_const_range(getPrivateCopies().begin(),
  2167. getPrivateCopies().end());
  2168. }
  2169. child_range children() {
  2170. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  2171. reinterpret_cast<Stmt **>(varlist_end()));
  2172. }
  2173. const_child_range children() const {
  2174. auto Children = const_cast<OMPPrivateClause *>(this)->children();
  2175. return const_child_range(Children.begin(), Children.end());
  2176. }
  2177. child_range used_children() {
  2178. return child_range(child_iterator(), child_iterator());
  2179. }
  2180. const_child_range used_children() const {
  2181. return const_child_range(const_child_iterator(), const_child_iterator());
  2182. }
  2183. static bool classof(const OMPClause *T) {
  2184. return T->getClauseKind() == llvm::omp::OMPC_private;
  2185. }
  2186. };
  2187. /// This represents clause 'firstprivate' in the '#pragma omp ...'
  2188. /// directives.
  2189. ///
  2190. /// \code
  2191. /// #pragma omp parallel firstprivate(a,b)
  2192. /// \endcode
  2193. /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
  2194. /// with the variables 'a' and 'b'.
  2195. class OMPFirstprivateClause final
  2196. : public OMPVarListClause<OMPFirstprivateClause>,
  2197. public OMPClauseWithPreInit,
  2198. private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
  2199. friend class OMPClauseReader;
  2200. friend OMPVarListClause;
  2201. friend TrailingObjects;
  2202. /// Build clause with number of variables \a N.
  2203. ///
  2204. /// \param StartLoc Starting location of the clause.
  2205. /// \param LParenLoc Location of '('.
  2206. /// \param EndLoc Ending location of the clause.
  2207. /// \param N Number of the variables in the clause.
  2208. OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  2209. SourceLocation EndLoc, unsigned N)
  2210. : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
  2211. StartLoc, LParenLoc, EndLoc, N),
  2212. OMPClauseWithPreInit(this) {}
  2213. /// Build an empty clause.
  2214. ///
  2215. /// \param N Number of variables.
  2216. explicit OMPFirstprivateClause(unsigned N)
  2217. : OMPVarListClause<OMPFirstprivateClause>(
  2218. llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
  2219. SourceLocation(), N),
  2220. OMPClauseWithPreInit(this) {}
  2221. /// Sets the list of references to private copies with initializers for
  2222. /// new private variables.
  2223. /// \param VL List of references.
  2224. void setPrivateCopies(ArrayRef<Expr *> VL);
  2225. /// Gets the list of references to private copies with initializers for
  2226. /// new private variables.
  2227. MutableArrayRef<Expr *> getPrivateCopies() {
  2228. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  2229. }
  2230. ArrayRef<const Expr *> getPrivateCopies() const {
  2231. return llvm::ArrayRef(varlist_end(), varlist_size());
  2232. }
  2233. /// Sets the list of references to initializer variables for new
  2234. /// private variables.
  2235. /// \param VL List of references.
  2236. void setInits(ArrayRef<Expr *> VL);
  2237. /// Gets the list of references to initializer variables for new
  2238. /// private variables.
  2239. MutableArrayRef<Expr *> getInits() {
  2240. return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
  2241. }
  2242. ArrayRef<const Expr *> getInits() const {
  2243. return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
  2244. }
  2245. public:
  2246. /// Creates clause with a list of variables \a VL.
  2247. ///
  2248. /// \param C AST context.
  2249. /// \param StartLoc Starting location of the clause.
  2250. /// \param LParenLoc Location of '('.
  2251. /// \param EndLoc Ending location of the clause.
  2252. /// \param VL List of references to the original variables.
  2253. /// \param PrivateVL List of references to private copies with initializers.
  2254. /// \param InitVL List of references to auto generated variables used for
  2255. /// initialization of a single array element. Used if firstprivate variable is
  2256. /// of array type.
  2257. /// \param PreInit Statement that must be executed before entering the OpenMP
  2258. /// region with this clause.
  2259. static OMPFirstprivateClause *
  2260. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  2261. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
  2262. ArrayRef<Expr *> InitVL, Stmt *PreInit);
  2263. /// Creates an empty clause with the place for \a N variables.
  2264. ///
  2265. /// \param C AST context.
  2266. /// \param N The number of variables.
  2267. static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
  2268. using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
  2269. using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
  2270. using private_copies_range = llvm::iterator_range<private_copies_iterator>;
  2271. using private_copies_const_range =
  2272. llvm::iterator_range<private_copies_const_iterator>;
  2273. private_copies_range private_copies() {
  2274. return private_copies_range(getPrivateCopies().begin(),
  2275. getPrivateCopies().end());
  2276. }
  2277. private_copies_const_range private_copies() const {
  2278. return private_copies_const_range(getPrivateCopies().begin(),
  2279. getPrivateCopies().end());
  2280. }
  2281. using inits_iterator = MutableArrayRef<Expr *>::iterator;
  2282. using inits_const_iterator = ArrayRef<const Expr *>::iterator;
  2283. using inits_range = llvm::iterator_range<inits_iterator>;
  2284. using inits_const_range = llvm::iterator_range<inits_const_iterator>;
  2285. inits_range inits() {
  2286. return inits_range(getInits().begin(), getInits().end());
  2287. }
  2288. inits_const_range inits() const {
  2289. return inits_const_range(getInits().begin(), getInits().end());
  2290. }
  2291. child_range children() {
  2292. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  2293. reinterpret_cast<Stmt **>(varlist_end()));
  2294. }
  2295. const_child_range children() const {
  2296. auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
  2297. return const_child_range(Children.begin(), Children.end());
  2298. }
  2299. child_range used_children() {
  2300. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  2301. reinterpret_cast<Stmt **>(varlist_end()));
  2302. }
  2303. const_child_range used_children() const {
  2304. auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
  2305. return const_child_range(Children.begin(), Children.end());
  2306. }
  2307. static bool classof(const OMPClause *T) {
  2308. return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
  2309. }
  2310. };
  2311. /// This represents clause 'lastprivate' in the '#pragma omp ...'
  2312. /// directives.
  2313. ///
  2314. /// \code
  2315. /// #pragma omp simd lastprivate(a,b)
  2316. /// \endcode
  2317. /// In this example directive '#pragma omp simd' has clause 'lastprivate'
  2318. /// with the variables 'a' and 'b'.
  2319. class OMPLastprivateClause final
  2320. : public OMPVarListClause<OMPLastprivateClause>,
  2321. public OMPClauseWithPostUpdate,
  2322. private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
  2323. // There are 4 additional tail-allocated arrays at the end of the class:
  2324. // 1. Contains list of pseudo variables with the default initialization for
  2325. // each non-firstprivate variables. Used in codegen for initialization of
  2326. // lastprivate copies.
  2327. // 2. List of helper expressions for proper generation of assignment operation
  2328. // required for lastprivate clause. This list represents private variables
  2329. // (for arrays, single array element).
  2330. // 3. List of helper expressions for proper generation of assignment operation
  2331. // required for lastprivate clause. This list represents original variables
  2332. // (for arrays, single array element).
  2333. // 4. List of helper expressions that represents assignment operation:
  2334. // \code
  2335. // DstExprs = SrcExprs;
  2336. // \endcode
  2337. // Required for proper codegen of final assignment performed by the
  2338. // lastprivate clause.
  2339. friend class OMPClauseReader;
  2340. friend OMPVarListClause;
  2341. friend TrailingObjects;
  2342. /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
  2343. OpenMPLastprivateModifier LPKind;
  2344. /// Optional location of the lasptrivate kind, if specified by user.
  2345. SourceLocation LPKindLoc;
  2346. /// Optional colon location, if specified by user.
  2347. SourceLocation ColonLoc;
  2348. /// Build clause with number of variables \a N.
  2349. ///
  2350. /// \param StartLoc Starting location of the clause.
  2351. /// \param LParenLoc Location of '('.
  2352. /// \param EndLoc Ending location of the clause.
  2353. /// \param N Number of the variables in the clause.
  2354. OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  2355. SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
  2356. SourceLocation LPKindLoc, SourceLocation ColonLoc,
  2357. unsigned N)
  2358. : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
  2359. StartLoc, LParenLoc, EndLoc, N),
  2360. OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
  2361. ColonLoc(ColonLoc) {}
  2362. /// Build an empty clause.
  2363. ///
  2364. /// \param N Number of variables.
  2365. explicit OMPLastprivateClause(unsigned N)
  2366. : OMPVarListClause<OMPLastprivateClause>(
  2367. llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
  2368. SourceLocation(), N),
  2369. OMPClauseWithPostUpdate(this) {}
  2370. /// Get the list of helper expressions for initialization of private
  2371. /// copies for lastprivate variables.
  2372. MutableArrayRef<Expr *> getPrivateCopies() {
  2373. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  2374. }
  2375. ArrayRef<const Expr *> getPrivateCopies() const {
  2376. return llvm::ArrayRef(varlist_end(), varlist_size());
  2377. }
  2378. /// Set list of helper expressions, required for proper codegen of the
  2379. /// clause. These expressions represent private variables (for arrays, single
  2380. /// array element) in the final assignment statement performed by the
  2381. /// lastprivate clause.
  2382. void setSourceExprs(ArrayRef<Expr *> SrcExprs);
  2383. /// Get the list of helper source expressions.
  2384. MutableArrayRef<Expr *> getSourceExprs() {
  2385. return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
  2386. }
  2387. ArrayRef<const Expr *> getSourceExprs() const {
  2388. return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
  2389. }
  2390. /// Set list of helper expressions, required for proper codegen of the
  2391. /// clause. These expressions represent original variables (for arrays, single
  2392. /// array element) in the final assignment statement performed by the
  2393. /// lastprivate clause.
  2394. void setDestinationExprs(ArrayRef<Expr *> DstExprs);
  2395. /// Get the list of helper destination expressions.
  2396. MutableArrayRef<Expr *> getDestinationExprs() {
  2397. return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
  2398. }
  2399. ArrayRef<const Expr *> getDestinationExprs() const {
  2400. return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
  2401. }
  2402. /// Set list of helper assignment expressions, required for proper
  2403. /// codegen of the clause. These expressions are assignment expressions that
  2404. /// assign private copy of the variable to original variable.
  2405. void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
  2406. /// Get the list of helper assignment expressions.
  2407. MutableArrayRef<Expr *> getAssignmentOps() {
  2408. return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
  2409. }
  2410. ArrayRef<const Expr *> getAssignmentOps() const {
  2411. return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
  2412. }
  2413. /// Sets lastprivate kind.
  2414. void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
  2415. /// Sets location of the lastprivate kind.
  2416. void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
  2417. /// Sets colon symbol location.
  2418. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  2419. public:
  2420. /// Creates clause with a list of variables \a VL.
  2421. ///
  2422. /// \param C AST context.
  2423. /// \param StartLoc Starting location of the clause.
  2424. /// \param LParenLoc Location of '('.
  2425. /// \param EndLoc Ending location of the clause.
  2426. /// \param VL List of references to the variables.
  2427. /// \param SrcExprs List of helper expressions for proper generation of
  2428. /// assignment operation required for lastprivate clause. This list represents
  2429. /// private variables (for arrays, single array element).
  2430. /// \param DstExprs List of helper expressions for proper generation of
  2431. /// assignment operation required for lastprivate clause. This list represents
  2432. /// original variables (for arrays, single array element).
  2433. /// \param AssignmentOps List of helper expressions that represents assignment
  2434. /// operation:
  2435. /// \code
  2436. /// DstExprs = SrcExprs;
  2437. /// \endcode
  2438. /// Required for proper codegen of final assignment performed by the
  2439. /// lastprivate clause.
  2440. /// \param LPKind Lastprivate kind, e.g. 'conditional'.
  2441. /// \param LPKindLoc Location of the lastprivate kind.
  2442. /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
  2443. /// \param PreInit Statement that must be executed before entering the OpenMP
  2444. /// region with this clause.
  2445. /// \param PostUpdate Expression that must be executed after exit from the
  2446. /// OpenMP region with this clause.
  2447. static OMPLastprivateClause *
  2448. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  2449. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  2450. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
  2451. OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
  2452. SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
  2453. /// Creates an empty clause with the place for \a N variables.
  2454. ///
  2455. /// \param C AST context.
  2456. /// \param N The number of variables.
  2457. static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
  2458. /// Lastprivate kind.
  2459. OpenMPLastprivateModifier getKind() const { return LPKind; }
  2460. /// Returns the location of the lastprivate kind.
  2461. SourceLocation getKindLoc() const { return LPKindLoc; }
  2462. /// Returns the location of the ':' symbol, if any.
  2463. SourceLocation getColonLoc() const { return ColonLoc; }
  2464. using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
  2465. using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
  2466. using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
  2467. using helper_expr_const_range =
  2468. llvm::iterator_range<helper_expr_const_iterator>;
  2469. /// Set list of helper expressions, required for generation of private
  2470. /// copies of original lastprivate variables.
  2471. void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
  2472. helper_expr_const_range private_copies() const {
  2473. return helper_expr_const_range(getPrivateCopies().begin(),
  2474. getPrivateCopies().end());
  2475. }
  2476. helper_expr_range private_copies() {
  2477. return helper_expr_range(getPrivateCopies().begin(),
  2478. getPrivateCopies().end());
  2479. }
  2480. helper_expr_const_range source_exprs() const {
  2481. return helper_expr_const_range(getSourceExprs().begin(),
  2482. getSourceExprs().end());
  2483. }
  2484. helper_expr_range source_exprs() {
  2485. return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
  2486. }
  2487. helper_expr_const_range destination_exprs() const {
  2488. return helper_expr_const_range(getDestinationExprs().begin(),
  2489. getDestinationExprs().end());
  2490. }
  2491. helper_expr_range destination_exprs() {
  2492. return helper_expr_range(getDestinationExprs().begin(),
  2493. getDestinationExprs().end());
  2494. }
  2495. helper_expr_const_range assignment_ops() const {
  2496. return helper_expr_const_range(getAssignmentOps().begin(),
  2497. getAssignmentOps().end());
  2498. }
  2499. helper_expr_range assignment_ops() {
  2500. return helper_expr_range(getAssignmentOps().begin(),
  2501. getAssignmentOps().end());
  2502. }
  2503. child_range children() {
  2504. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  2505. reinterpret_cast<Stmt **>(varlist_end()));
  2506. }
  2507. const_child_range children() const {
  2508. auto Children = const_cast<OMPLastprivateClause *>(this)->children();
  2509. return const_child_range(Children.begin(), Children.end());
  2510. }
  2511. child_range used_children() {
  2512. return child_range(child_iterator(), child_iterator());
  2513. }
  2514. const_child_range used_children() const {
  2515. return const_child_range(const_child_iterator(), const_child_iterator());
  2516. }
  2517. static bool classof(const OMPClause *T) {
  2518. return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
  2519. }
  2520. };
  2521. /// This represents clause 'shared' in the '#pragma omp ...' directives.
  2522. ///
  2523. /// \code
  2524. /// #pragma omp parallel shared(a,b)
  2525. /// \endcode
  2526. /// In this example directive '#pragma omp parallel' has clause 'shared'
  2527. /// with the variables 'a' and 'b'.
  2528. class OMPSharedClause final
  2529. : public OMPVarListClause<OMPSharedClause>,
  2530. private llvm::TrailingObjects<OMPSharedClause, Expr *> {
  2531. friend OMPVarListClause;
  2532. friend TrailingObjects;
  2533. /// Build clause with number of variables \a N.
  2534. ///
  2535. /// \param StartLoc Starting location of the clause.
  2536. /// \param LParenLoc Location of '('.
  2537. /// \param EndLoc Ending location of the clause.
  2538. /// \param N Number of the variables in the clause.
  2539. OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  2540. SourceLocation EndLoc, unsigned N)
  2541. : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
  2542. LParenLoc, EndLoc, N) {}
  2543. /// Build an empty clause.
  2544. ///
  2545. /// \param N Number of variables.
  2546. explicit OMPSharedClause(unsigned N)
  2547. : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
  2548. SourceLocation(), SourceLocation(),
  2549. SourceLocation(), N) {}
  2550. public:
  2551. /// Creates clause with a list of variables \a VL.
  2552. ///
  2553. /// \param C AST context.
  2554. /// \param StartLoc Starting location of the clause.
  2555. /// \param LParenLoc Location of '('.
  2556. /// \param EndLoc Ending location of the clause.
  2557. /// \param VL List of references to the variables.
  2558. static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
  2559. SourceLocation LParenLoc,
  2560. SourceLocation EndLoc, ArrayRef<Expr *> VL);
  2561. /// Creates an empty clause with \a N variables.
  2562. ///
  2563. /// \param C AST context.
  2564. /// \param N The number of variables.
  2565. static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
  2566. child_range children() {
  2567. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  2568. reinterpret_cast<Stmt **>(varlist_end()));
  2569. }
  2570. const_child_range children() const {
  2571. auto Children = const_cast<OMPSharedClause *>(this)->children();
  2572. return const_child_range(Children.begin(), Children.end());
  2573. }
  2574. child_range used_children() {
  2575. return child_range(child_iterator(), child_iterator());
  2576. }
  2577. const_child_range used_children() const {
  2578. return const_child_range(const_child_iterator(), const_child_iterator());
  2579. }
  2580. static bool classof(const OMPClause *T) {
  2581. return T->getClauseKind() == llvm::omp::OMPC_shared;
  2582. }
  2583. };
  2584. /// This represents clause 'reduction' in the '#pragma omp ...'
  2585. /// directives.
  2586. ///
  2587. /// \code
  2588. /// #pragma omp parallel reduction(+:a,b)
  2589. /// \endcode
  2590. /// In this example directive '#pragma omp parallel' has clause 'reduction'
  2591. /// with operator '+' and the variables 'a' and 'b'.
  2592. class OMPReductionClause final
  2593. : public OMPVarListClause<OMPReductionClause>,
  2594. public OMPClauseWithPostUpdate,
  2595. private llvm::TrailingObjects<OMPReductionClause, Expr *> {
  2596. friend class OMPClauseReader;
  2597. friend OMPVarListClause;
  2598. friend TrailingObjects;
  2599. /// Reduction modifier.
  2600. OpenMPReductionClauseModifier Modifier = OMPC_REDUCTION_unknown;
  2601. /// Reduction modifier location.
  2602. SourceLocation ModifierLoc;
  2603. /// Location of ':'.
  2604. SourceLocation ColonLoc;
  2605. /// Nested name specifier for C++.
  2606. NestedNameSpecifierLoc QualifierLoc;
  2607. /// Name of custom operator.
  2608. DeclarationNameInfo NameInfo;
  2609. /// Build clause with number of variables \a N.
  2610. ///
  2611. /// \param StartLoc Starting location of the clause.
  2612. /// \param LParenLoc Location of '('.
  2613. /// \param ModifierLoc Modifier location.
  2614. /// \param ColonLoc Location of ':'.
  2615. /// \param EndLoc Ending location of the clause.
  2616. /// \param N Number of the variables in the clause.
  2617. /// \param QualifierLoc The nested-name qualifier with location information
  2618. /// \param NameInfo The full name info for reduction identifier.
  2619. OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  2620. SourceLocation ModifierLoc, SourceLocation ColonLoc,
  2621. SourceLocation EndLoc,
  2622. OpenMPReductionClauseModifier Modifier, unsigned N,
  2623. NestedNameSpecifierLoc QualifierLoc,
  2624. const DeclarationNameInfo &NameInfo)
  2625. : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
  2626. StartLoc, LParenLoc, EndLoc, N),
  2627. OMPClauseWithPostUpdate(this), Modifier(Modifier),
  2628. ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
  2629. QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
  2630. /// Build an empty clause.
  2631. ///
  2632. /// \param N Number of variables.
  2633. explicit OMPReductionClause(unsigned N)
  2634. : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
  2635. SourceLocation(), SourceLocation(),
  2636. SourceLocation(), N),
  2637. OMPClauseWithPostUpdate(this) {}
  2638. /// Sets reduction modifier.
  2639. void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
  2640. /// Sets location of the modifier.
  2641. void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
  2642. /// Sets location of ':' symbol in clause.
  2643. void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
  2644. /// Sets the name info for specified reduction identifier.
  2645. void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
  2646. /// Sets the nested name specifier.
  2647. void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
  2648. /// Set list of helper expressions, required for proper codegen of the
  2649. /// clause. These expressions represent private copy of the reduction
  2650. /// variable.
  2651. void setPrivates(ArrayRef<Expr *> Privates);
  2652. /// Get the list of helper privates.
  2653. MutableArrayRef<Expr *> getPrivates() {
  2654. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  2655. }
  2656. ArrayRef<const Expr *> getPrivates() const {
  2657. return llvm::ArrayRef(varlist_end(), varlist_size());
  2658. }
  2659. /// Set list of helper expressions, required for proper codegen of the
  2660. /// clause. These expressions represent LHS expression in the final
  2661. /// reduction expression performed by the reduction clause.
  2662. void setLHSExprs(ArrayRef<Expr *> LHSExprs);
  2663. /// Get the list of helper LHS expressions.
  2664. MutableArrayRef<Expr *> getLHSExprs() {
  2665. return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
  2666. }
  2667. ArrayRef<const Expr *> getLHSExprs() const {
  2668. return llvm::ArrayRef(getPrivates().end(), varlist_size());
  2669. }
  2670. /// Set list of helper expressions, required for proper codegen of the
  2671. /// clause. These expressions represent RHS expression in the final
  2672. /// reduction expression performed by the reduction clause.
  2673. /// Also, variables in these expressions are used for proper initialization of
  2674. /// reduction copies.
  2675. void setRHSExprs(ArrayRef<Expr *> RHSExprs);
  2676. /// Get the list of helper destination expressions.
  2677. MutableArrayRef<Expr *> getRHSExprs() {
  2678. return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
  2679. }
  2680. ArrayRef<const Expr *> getRHSExprs() const {
  2681. return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
  2682. }
  2683. /// Set list of helper reduction expressions, required for proper
  2684. /// codegen of the clause. These expressions are binary expressions or
  2685. /// operator/custom reduction call that calculates new value from source
  2686. /// helper expressions to destination helper expressions.
  2687. void setReductionOps(ArrayRef<Expr *> ReductionOps);
  2688. /// Get the list of helper reduction expressions.
  2689. MutableArrayRef<Expr *> getReductionOps() {
  2690. return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
  2691. }
  2692. ArrayRef<const Expr *> getReductionOps() const {
  2693. return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
  2694. }
  2695. /// Set list of helper copy operations for inscan reductions.
  2696. /// The form is: Temps[i] = LHS[i];
  2697. void setInscanCopyOps(ArrayRef<Expr *> Ops);
  2698. /// Get the list of helper inscan copy operations.
  2699. MutableArrayRef<Expr *> getInscanCopyOps() {
  2700. return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
  2701. }
  2702. ArrayRef<const Expr *> getInscanCopyOps() const {
  2703. return llvm::ArrayRef(getReductionOps().end(), varlist_size());
  2704. }
  2705. /// Set list of helper temp vars for inscan copy array operations.
  2706. void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
  2707. /// Get the list of helper inscan copy temps.
  2708. MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
  2709. return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
  2710. }
  2711. ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
  2712. return llvm::ArrayRef(getInscanCopyOps().end(), varlist_size());
  2713. }
  2714. /// Set list of helper temp elements vars for inscan copy array operations.
  2715. void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
  2716. /// Get the list of helper inscan copy temps.
  2717. MutableArrayRef<Expr *> getInscanCopyArrayElems() {
  2718. return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
  2719. varlist_size());
  2720. }
  2721. ArrayRef<const Expr *> getInscanCopyArrayElems() const {
  2722. return llvm::ArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
  2723. }
  2724. public:
  2725. /// Creates clause with a list of variables \a VL.
  2726. ///
  2727. /// \param StartLoc Starting location of the clause.
  2728. /// \param LParenLoc Location of '('.
  2729. /// \param ModifierLoc Modifier location.
  2730. /// \param ColonLoc Location of ':'.
  2731. /// \param EndLoc Ending location of the clause.
  2732. /// \param VL The variables in the clause.
  2733. /// \param QualifierLoc The nested-name qualifier with location information
  2734. /// \param NameInfo The full name info for reduction identifier.
  2735. /// \param Privates List of helper expressions for proper generation of
  2736. /// private copies.
  2737. /// \param LHSExprs List of helper expressions for proper generation of
  2738. /// assignment operation required for copyprivate clause. This list represents
  2739. /// LHSs of the reduction expressions.
  2740. /// \param RHSExprs List of helper expressions for proper generation of
  2741. /// assignment operation required for copyprivate clause. This list represents
  2742. /// RHSs of the reduction expressions.
  2743. /// Also, variables in these expressions are used for proper initialization of
  2744. /// reduction copies.
  2745. /// \param ReductionOps List of helper expressions that represents reduction
  2746. /// expressions:
  2747. /// \code
  2748. /// LHSExprs binop RHSExprs;
  2749. /// operator binop(LHSExpr, RHSExpr);
  2750. /// <CutomReduction>(LHSExpr, RHSExpr);
  2751. /// \endcode
  2752. /// Required for proper codegen of final reduction operation performed by the
  2753. /// reduction clause.
  2754. /// \param CopyOps List of copy operations for inscan reductions:
  2755. /// \code
  2756. /// TempExprs = LHSExprs;
  2757. /// \endcode
  2758. /// \param CopyArrayTemps Temp arrays for prefix sums.
  2759. /// \param CopyArrayElems Temp arrays for prefix sums.
  2760. /// \param PreInit Statement that must be executed before entering the OpenMP
  2761. /// region with this clause.
  2762. /// \param PostUpdate Expression that must be executed after exit from the
  2763. /// OpenMP region with this clause.
  2764. static OMPReductionClause *
  2765. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  2766. SourceLocation ModifierLoc, SourceLocation ColonLoc,
  2767. SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
  2768. ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
  2769. const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
  2770. ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
  2771. ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
  2772. ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
  2773. Stmt *PreInit, Expr *PostUpdate);
  2774. /// Creates an empty clause with the place for \a N variables.
  2775. ///
  2776. /// \param C AST context.
  2777. /// \param N The number of variables.
  2778. /// \param Modifier Reduction modifier.
  2779. static OMPReductionClause *
  2780. CreateEmpty(const ASTContext &C, unsigned N,
  2781. OpenMPReductionClauseModifier Modifier);
  2782. /// Returns modifier.
  2783. OpenMPReductionClauseModifier getModifier() const { return Modifier; }
  2784. /// Returns modifier location.
  2785. SourceLocation getModifierLoc() const { return ModifierLoc; }
  2786. /// Gets location of ':' symbol in clause.
  2787. SourceLocation getColonLoc() const { return ColonLoc; }
  2788. /// Gets the name info for specified reduction identifier.
  2789. const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
  2790. /// Gets the nested name specifier.
  2791. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  2792. using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
  2793. using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
  2794. using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
  2795. using helper_expr_const_range =
  2796. llvm::iterator_range<helper_expr_const_iterator>;
  2797. helper_expr_const_range privates() const {
  2798. return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
  2799. }
  2800. helper_expr_range privates() {
  2801. return helper_expr_range(getPrivates().begin(), getPrivates().end());
  2802. }
  2803. helper_expr_const_range lhs_exprs() const {
  2804. return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
  2805. }
  2806. helper_expr_range lhs_exprs() {
  2807. return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
  2808. }
  2809. helper_expr_const_range rhs_exprs() const {
  2810. return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
  2811. }
  2812. helper_expr_range rhs_exprs() {
  2813. return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
  2814. }
  2815. helper_expr_const_range reduction_ops() const {
  2816. return helper_expr_const_range(getReductionOps().begin(),
  2817. getReductionOps().end());
  2818. }
  2819. helper_expr_range reduction_ops() {
  2820. return helper_expr_range(getReductionOps().begin(),
  2821. getReductionOps().end());
  2822. }
  2823. helper_expr_const_range copy_ops() const {
  2824. return helper_expr_const_range(getInscanCopyOps().begin(),
  2825. getInscanCopyOps().end());
  2826. }
  2827. helper_expr_range copy_ops() {
  2828. return helper_expr_range(getInscanCopyOps().begin(),
  2829. getInscanCopyOps().end());
  2830. }
  2831. helper_expr_const_range copy_array_temps() const {
  2832. return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
  2833. getInscanCopyArrayTemps().end());
  2834. }
  2835. helper_expr_range copy_array_temps() {
  2836. return helper_expr_range(getInscanCopyArrayTemps().begin(),
  2837. getInscanCopyArrayTemps().end());
  2838. }
  2839. helper_expr_const_range copy_array_elems() const {
  2840. return helper_expr_const_range(getInscanCopyArrayElems().begin(),
  2841. getInscanCopyArrayElems().end());
  2842. }
  2843. helper_expr_range copy_array_elems() {
  2844. return helper_expr_range(getInscanCopyArrayElems().begin(),
  2845. getInscanCopyArrayElems().end());
  2846. }
  2847. child_range children() {
  2848. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  2849. reinterpret_cast<Stmt **>(varlist_end()));
  2850. }
  2851. const_child_range children() const {
  2852. auto Children = const_cast<OMPReductionClause *>(this)->children();
  2853. return const_child_range(Children.begin(), Children.end());
  2854. }
  2855. child_range used_children() {
  2856. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  2857. reinterpret_cast<Stmt **>(varlist_end()));
  2858. }
  2859. const_child_range used_children() const {
  2860. auto Children = const_cast<OMPReductionClause *>(this)->used_children();
  2861. return const_child_range(Children.begin(), Children.end());
  2862. }
  2863. static bool classof(const OMPClause *T) {
  2864. return T->getClauseKind() == llvm::omp::OMPC_reduction;
  2865. }
  2866. };
  2867. /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
  2868. /// directives.
  2869. ///
  2870. /// \code
  2871. /// #pragma omp taskgroup task_reduction(+:a,b)
  2872. /// \endcode
  2873. /// In this example directive '#pragma omp taskgroup' has clause
  2874. /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
  2875. class OMPTaskReductionClause final
  2876. : public OMPVarListClause<OMPTaskReductionClause>,
  2877. public OMPClauseWithPostUpdate,
  2878. private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
  2879. friend class OMPClauseReader;
  2880. friend OMPVarListClause;
  2881. friend TrailingObjects;
  2882. /// Location of ':'.
  2883. SourceLocation ColonLoc;
  2884. /// Nested name specifier for C++.
  2885. NestedNameSpecifierLoc QualifierLoc;
  2886. /// Name of custom operator.
  2887. DeclarationNameInfo NameInfo;
  2888. /// Build clause with number of variables \a N.
  2889. ///
  2890. /// \param StartLoc Starting location of the clause.
  2891. /// \param LParenLoc Location of '('.
  2892. /// \param EndLoc Ending location of the clause.
  2893. /// \param ColonLoc Location of ':'.
  2894. /// \param N Number of the variables in the clause.
  2895. /// \param QualifierLoc The nested-name qualifier with location information
  2896. /// \param NameInfo The full name info for reduction identifier.
  2897. OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  2898. SourceLocation ColonLoc, SourceLocation EndLoc,
  2899. unsigned N, NestedNameSpecifierLoc QualifierLoc,
  2900. const DeclarationNameInfo &NameInfo)
  2901. : OMPVarListClause<OMPTaskReductionClause>(
  2902. llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
  2903. OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
  2904. QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
  2905. /// Build an empty clause.
  2906. ///
  2907. /// \param N Number of variables.
  2908. explicit OMPTaskReductionClause(unsigned N)
  2909. : OMPVarListClause<OMPTaskReductionClause>(
  2910. llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
  2911. SourceLocation(), N),
  2912. OMPClauseWithPostUpdate(this) {}
  2913. /// Sets location of ':' symbol in clause.
  2914. void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
  2915. /// Sets the name info for specified reduction identifier.
  2916. void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
  2917. /// Sets the nested name specifier.
  2918. void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
  2919. /// Set list of helper expressions, required for proper codegen of the clause.
  2920. /// These expressions represent private copy of the reduction variable.
  2921. void setPrivates(ArrayRef<Expr *> Privates);
  2922. /// Get the list of helper privates.
  2923. MutableArrayRef<Expr *> getPrivates() {
  2924. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  2925. }
  2926. ArrayRef<const Expr *> getPrivates() const {
  2927. return llvm::ArrayRef(varlist_end(), varlist_size());
  2928. }
  2929. /// Set list of helper expressions, required for proper codegen of the clause.
  2930. /// These expressions represent LHS expression in the final reduction
  2931. /// expression performed by the reduction clause.
  2932. void setLHSExprs(ArrayRef<Expr *> LHSExprs);
  2933. /// Get the list of helper LHS expressions.
  2934. MutableArrayRef<Expr *> getLHSExprs() {
  2935. return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
  2936. }
  2937. ArrayRef<const Expr *> getLHSExprs() const {
  2938. return llvm::ArrayRef(getPrivates().end(), varlist_size());
  2939. }
  2940. /// Set list of helper expressions, required for proper codegen of the clause.
  2941. /// These expressions represent RHS expression in the final reduction
  2942. /// expression performed by the reduction clause. Also, variables in these
  2943. /// expressions are used for proper initialization of reduction copies.
  2944. void setRHSExprs(ArrayRef<Expr *> RHSExprs);
  2945. /// Get the list of helper destination expressions.
  2946. MutableArrayRef<Expr *> getRHSExprs() {
  2947. return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
  2948. }
  2949. ArrayRef<const Expr *> getRHSExprs() const {
  2950. return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
  2951. }
  2952. /// Set list of helper reduction expressions, required for proper
  2953. /// codegen of the clause. These expressions are binary expressions or
  2954. /// operator/custom reduction call that calculates new value from source
  2955. /// helper expressions to destination helper expressions.
  2956. void setReductionOps(ArrayRef<Expr *> ReductionOps);
  2957. /// Get the list of helper reduction expressions.
  2958. MutableArrayRef<Expr *> getReductionOps() {
  2959. return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
  2960. }
  2961. ArrayRef<const Expr *> getReductionOps() const {
  2962. return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
  2963. }
  2964. public:
  2965. /// Creates clause with a list of variables \a VL.
  2966. ///
  2967. /// \param StartLoc Starting location of the clause.
  2968. /// \param LParenLoc Location of '('.
  2969. /// \param ColonLoc Location of ':'.
  2970. /// \param EndLoc Ending location of the clause.
  2971. /// \param VL The variables in the clause.
  2972. /// \param QualifierLoc The nested-name qualifier with location information
  2973. /// \param NameInfo The full name info for reduction identifier.
  2974. /// \param Privates List of helper expressions for proper generation of
  2975. /// private copies.
  2976. /// \param LHSExprs List of helper expressions for proper generation of
  2977. /// assignment operation required for copyprivate clause. This list represents
  2978. /// LHSs of the reduction expressions.
  2979. /// \param RHSExprs List of helper expressions for proper generation of
  2980. /// assignment operation required for copyprivate clause. This list represents
  2981. /// RHSs of the reduction expressions.
  2982. /// Also, variables in these expressions are used for proper initialization of
  2983. /// reduction copies.
  2984. /// \param ReductionOps List of helper expressions that represents reduction
  2985. /// expressions:
  2986. /// \code
  2987. /// LHSExprs binop RHSExprs;
  2988. /// operator binop(LHSExpr, RHSExpr);
  2989. /// <CutomReduction>(LHSExpr, RHSExpr);
  2990. /// \endcode
  2991. /// Required for proper codegen of final reduction operation performed by the
  2992. /// reduction clause.
  2993. /// \param PreInit Statement that must be executed before entering the OpenMP
  2994. /// region with this clause.
  2995. /// \param PostUpdate Expression that must be executed after exit from the
  2996. /// OpenMP region with this clause.
  2997. static OMPTaskReductionClause *
  2998. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  2999. SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
  3000. NestedNameSpecifierLoc QualifierLoc,
  3001. const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
  3002. ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
  3003. ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
  3004. /// Creates an empty clause with the place for \a N variables.
  3005. ///
  3006. /// \param C AST context.
  3007. /// \param N The number of variables.
  3008. static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
  3009. /// Gets location of ':' symbol in clause.
  3010. SourceLocation getColonLoc() const { return ColonLoc; }
  3011. /// Gets the name info for specified reduction identifier.
  3012. const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
  3013. /// Gets the nested name specifier.
  3014. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  3015. using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
  3016. using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
  3017. using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
  3018. using helper_expr_const_range =
  3019. llvm::iterator_range<helper_expr_const_iterator>;
  3020. helper_expr_const_range privates() const {
  3021. return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
  3022. }
  3023. helper_expr_range privates() {
  3024. return helper_expr_range(getPrivates().begin(), getPrivates().end());
  3025. }
  3026. helper_expr_const_range lhs_exprs() const {
  3027. return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
  3028. }
  3029. helper_expr_range lhs_exprs() {
  3030. return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
  3031. }
  3032. helper_expr_const_range rhs_exprs() const {
  3033. return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
  3034. }
  3035. helper_expr_range rhs_exprs() {
  3036. return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
  3037. }
  3038. helper_expr_const_range reduction_ops() const {
  3039. return helper_expr_const_range(getReductionOps().begin(),
  3040. getReductionOps().end());
  3041. }
  3042. helper_expr_range reduction_ops() {
  3043. return helper_expr_range(getReductionOps().begin(),
  3044. getReductionOps().end());
  3045. }
  3046. child_range children() {
  3047. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  3048. reinterpret_cast<Stmt **>(varlist_end()));
  3049. }
  3050. const_child_range children() const {
  3051. auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
  3052. return const_child_range(Children.begin(), Children.end());
  3053. }
  3054. child_range used_children() {
  3055. return child_range(child_iterator(), child_iterator());
  3056. }
  3057. const_child_range used_children() const {
  3058. return const_child_range(const_child_iterator(), const_child_iterator());
  3059. }
  3060. static bool classof(const OMPClause *T) {
  3061. return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
  3062. }
  3063. };
  3064. /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
  3065. ///
  3066. /// \code
  3067. /// #pragma omp task in_reduction(+:a,b)
  3068. /// \endcode
  3069. /// In this example directive '#pragma omp task' has clause 'in_reduction' with
  3070. /// operator '+' and the variables 'a' and 'b'.
  3071. class OMPInReductionClause final
  3072. : public OMPVarListClause<OMPInReductionClause>,
  3073. public OMPClauseWithPostUpdate,
  3074. private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
  3075. friend class OMPClauseReader;
  3076. friend OMPVarListClause;
  3077. friend TrailingObjects;
  3078. /// Location of ':'.
  3079. SourceLocation ColonLoc;
  3080. /// Nested name specifier for C++.
  3081. NestedNameSpecifierLoc QualifierLoc;
  3082. /// Name of custom operator.
  3083. DeclarationNameInfo NameInfo;
  3084. /// Build clause with number of variables \a N.
  3085. ///
  3086. /// \param StartLoc Starting location of the clause.
  3087. /// \param LParenLoc Location of '('.
  3088. /// \param EndLoc Ending location of the clause.
  3089. /// \param ColonLoc Location of ':'.
  3090. /// \param N Number of the variables in the clause.
  3091. /// \param QualifierLoc The nested-name qualifier with location information
  3092. /// \param NameInfo The full name info for reduction identifier.
  3093. OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  3094. SourceLocation ColonLoc, SourceLocation EndLoc,
  3095. unsigned N, NestedNameSpecifierLoc QualifierLoc,
  3096. const DeclarationNameInfo &NameInfo)
  3097. : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
  3098. StartLoc, LParenLoc, EndLoc, N),
  3099. OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
  3100. QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
  3101. /// Build an empty clause.
  3102. ///
  3103. /// \param N Number of variables.
  3104. explicit OMPInReductionClause(unsigned N)
  3105. : OMPVarListClause<OMPInReductionClause>(
  3106. llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
  3107. SourceLocation(), N),
  3108. OMPClauseWithPostUpdate(this) {}
  3109. /// Sets location of ':' symbol in clause.
  3110. void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
  3111. /// Sets the name info for specified reduction identifier.
  3112. void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
  3113. /// Sets the nested name specifier.
  3114. void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
  3115. /// Set list of helper expressions, required for proper codegen of the clause.
  3116. /// These expressions represent private copy of the reduction variable.
  3117. void setPrivates(ArrayRef<Expr *> Privates);
  3118. /// Get the list of helper privates.
  3119. MutableArrayRef<Expr *> getPrivates() {
  3120. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  3121. }
  3122. ArrayRef<const Expr *> getPrivates() const {
  3123. return llvm::ArrayRef(varlist_end(), varlist_size());
  3124. }
  3125. /// Set list of helper expressions, required for proper codegen of the clause.
  3126. /// These expressions represent LHS expression in the final reduction
  3127. /// expression performed by the reduction clause.
  3128. void setLHSExprs(ArrayRef<Expr *> LHSExprs);
  3129. /// Get the list of helper LHS expressions.
  3130. MutableArrayRef<Expr *> getLHSExprs() {
  3131. return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
  3132. }
  3133. ArrayRef<const Expr *> getLHSExprs() const {
  3134. return llvm::ArrayRef(getPrivates().end(), varlist_size());
  3135. }
  3136. /// Set list of helper expressions, required for proper codegen of the clause.
  3137. /// These expressions represent RHS expression in the final reduction
  3138. /// expression performed by the reduction clause. Also, variables in these
  3139. /// expressions are used for proper initialization of reduction copies.
  3140. void setRHSExprs(ArrayRef<Expr *> RHSExprs);
  3141. /// Get the list of helper destination expressions.
  3142. MutableArrayRef<Expr *> getRHSExprs() {
  3143. return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
  3144. }
  3145. ArrayRef<const Expr *> getRHSExprs() const {
  3146. return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
  3147. }
  3148. /// Set list of helper reduction expressions, required for proper
  3149. /// codegen of the clause. These expressions are binary expressions or
  3150. /// operator/custom reduction call that calculates new value from source
  3151. /// helper expressions to destination helper expressions.
  3152. void setReductionOps(ArrayRef<Expr *> ReductionOps);
  3153. /// Get the list of helper reduction expressions.
  3154. MutableArrayRef<Expr *> getReductionOps() {
  3155. return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
  3156. }
  3157. ArrayRef<const Expr *> getReductionOps() const {
  3158. return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
  3159. }
  3160. /// Set list of helper reduction taskgroup descriptors.
  3161. void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
  3162. /// Get the list of helper reduction taskgroup descriptors.
  3163. MutableArrayRef<Expr *> getTaskgroupDescriptors() {
  3164. return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
  3165. }
  3166. ArrayRef<const Expr *> getTaskgroupDescriptors() const {
  3167. return llvm::ArrayRef(getReductionOps().end(), varlist_size());
  3168. }
  3169. public:
  3170. /// Creates clause with a list of variables \a VL.
  3171. ///
  3172. /// \param StartLoc Starting location of the clause.
  3173. /// \param LParenLoc Location of '('.
  3174. /// \param ColonLoc Location of ':'.
  3175. /// \param EndLoc Ending location of the clause.
  3176. /// \param VL The variables in the clause.
  3177. /// \param QualifierLoc The nested-name qualifier with location information
  3178. /// \param NameInfo The full name info for reduction identifier.
  3179. /// \param Privates List of helper expressions for proper generation of
  3180. /// private copies.
  3181. /// \param LHSExprs List of helper expressions for proper generation of
  3182. /// assignment operation required for copyprivate clause. This list represents
  3183. /// LHSs of the reduction expressions.
  3184. /// \param RHSExprs List of helper expressions for proper generation of
  3185. /// assignment operation required for copyprivate clause. This list represents
  3186. /// RHSs of the reduction expressions.
  3187. /// Also, variables in these expressions are used for proper initialization of
  3188. /// reduction copies.
  3189. /// \param ReductionOps List of helper expressions that represents reduction
  3190. /// expressions:
  3191. /// \code
  3192. /// LHSExprs binop RHSExprs;
  3193. /// operator binop(LHSExpr, RHSExpr);
  3194. /// <CutomReduction>(LHSExpr, RHSExpr);
  3195. /// \endcode
  3196. /// Required for proper codegen of final reduction operation performed by the
  3197. /// reduction clause.
  3198. /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
  3199. /// corresponding items in parent taskgroup task_reduction clause.
  3200. /// \param PreInit Statement that must be executed before entering the OpenMP
  3201. /// region with this clause.
  3202. /// \param PostUpdate Expression that must be executed after exit from the
  3203. /// OpenMP region with this clause.
  3204. static OMPInReductionClause *
  3205. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  3206. SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
  3207. NestedNameSpecifierLoc QualifierLoc,
  3208. const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
  3209. ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
  3210. ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
  3211. Stmt *PreInit, Expr *PostUpdate);
  3212. /// Creates an empty clause with the place for \a N variables.
  3213. ///
  3214. /// \param C AST context.
  3215. /// \param N The number of variables.
  3216. static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
  3217. /// Gets location of ':' symbol in clause.
  3218. SourceLocation getColonLoc() const { return ColonLoc; }
  3219. /// Gets the name info for specified reduction identifier.
  3220. const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
  3221. /// Gets the nested name specifier.
  3222. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  3223. using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
  3224. using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
  3225. using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
  3226. using helper_expr_const_range =
  3227. llvm::iterator_range<helper_expr_const_iterator>;
  3228. helper_expr_const_range privates() const {
  3229. return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
  3230. }
  3231. helper_expr_range privates() {
  3232. return helper_expr_range(getPrivates().begin(), getPrivates().end());
  3233. }
  3234. helper_expr_const_range lhs_exprs() const {
  3235. return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
  3236. }
  3237. helper_expr_range lhs_exprs() {
  3238. return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
  3239. }
  3240. helper_expr_const_range rhs_exprs() const {
  3241. return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
  3242. }
  3243. helper_expr_range rhs_exprs() {
  3244. return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
  3245. }
  3246. helper_expr_const_range reduction_ops() const {
  3247. return helper_expr_const_range(getReductionOps().begin(),
  3248. getReductionOps().end());
  3249. }
  3250. helper_expr_range reduction_ops() {
  3251. return helper_expr_range(getReductionOps().begin(),
  3252. getReductionOps().end());
  3253. }
  3254. helper_expr_const_range taskgroup_descriptors() const {
  3255. return helper_expr_const_range(getTaskgroupDescriptors().begin(),
  3256. getTaskgroupDescriptors().end());
  3257. }
  3258. helper_expr_range taskgroup_descriptors() {
  3259. return helper_expr_range(getTaskgroupDescriptors().begin(),
  3260. getTaskgroupDescriptors().end());
  3261. }
  3262. child_range children() {
  3263. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  3264. reinterpret_cast<Stmt **>(varlist_end()));
  3265. }
  3266. const_child_range children() const {
  3267. auto Children = const_cast<OMPInReductionClause *>(this)->children();
  3268. return const_child_range(Children.begin(), Children.end());
  3269. }
  3270. child_range used_children() {
  3271. return child_range(child_iterator(), child_iterator());
  3272. }
  3273. const_child_range used_children() const {
  3274. return const_child_range(const_child_iterator(), const_child_iterator());
  3275. }
  3276. static bool classof(const OMPClause *T) {
  3277. return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
  3278. }
  3279. };
  3280. /// This represents clause 'linear' in the '#pragma omp ...'
  3281. /// directives.
  3282. ///
  3283. /// \code
  3284. /// #pragma omp simd linear(a,b : 2)
  3285. /// \endcode
  3286. /// In this example directive '#pragma omp simd' has clause 'linear'
  3287. /// with variables 'a', 'b' and linear step '2'.
  3288. class OMPLinearClause final
  3289. : public OMPVarListClause<OMPLinearClause>,
  3290. public OMPClauseWithPostUpdate,
  3291. private llvm::TrailingObjects<OMPLinearClause, Expr *> {
  3292. friend class OMPClauseReader;
  3293. friend OMPVarListClause;
  3294. friend TrailingObjects;
  3295. /// Modifier of 'linear' clause.
  3296. OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
  3297. /// Location of linear modifier if any.
  3298. SourceLocation ModifierLoc;
  3299. /// Location of ':'.
  3300. SourceLocation ColonLoc;
  3301. /// Sets the linear step for clause.
  3302. void setStep(Expr *Step) { *(getFinals().end()) = Step; }
  3303. /// Sets the expression to calculate linear step for clause.
  3304. void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
  3305. /// Build 'linear' clause with given number of variables \a NumVars.
  3306. ///
  3307. /// \param StartLoc Starting location of the clause.
  3308. /// \param LParenLoc Location of '('.
  3309. /// \param ColonLoc Location of ':'.
  3310. /// \param EndLoc Ending location of the clause.
  3311. /// \param NumVars Number of variables.
  3312. OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  3313. OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
  3314. SourceLocation ColonLoc, SourceLocation EndLoc,
  3315. unsigned NumVars)
  3316. : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
  3317. LParenLoc, EndLoc, NumVars),
  3318. OMPClauseWithPostUpdate(this), Modifier(Modifier),
  3319. ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
  3320. /// Build an empty clause.
  3321. ///
  3322. /// \param NumVars Number of variables.
  3323. explicit OMPLinearClause(unsigned NumVars)
  3324. : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
  3325. SourceLocation(), SourceLocation(),
  3326. SourceLocation(), NumVars),
  3327. OMPClauseWithPostUpdate(this) {}
  3328. /// Gets the list of initial values for linear variables.
  3329. ///
  3330. /// There are NumVars expressions with initial values allocated after the
  3331. /// varlist, they are followed by NumVars update expressions (used to update
  3332. /// the linear variable's value on current iteration) and they are followed by
  3333. /// NumVars final expressions (used to calculate the linear variable's
  3334. /// value after the loop body). After these lists, there are 2 helper
  3335. /// expressions - linear step and a helper to calculate it before the
  3336. /// loop body (used when the linear step is not constant):
  3337. ///
  3338. /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
  3339. /// Finals[]; Step; CalcStep; }
  3340. MutableArrayRef<Expr *> getPrivates() {
  3341. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  3342. }
  3343. ArrayRef<const Expr *> getPrivates() const {
  3344. return llvm::ArrayRef(varlist_end(), varlist_size());
  3345. }
  3346. MutableArrayRef<Expr *> getInits() {
  3347. return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
  3348. }
  3349. ArrayRef<const Expr *> getInits() const {
  3350. return llvm::ArrayRef(getPrivates().end(), varlist_size());
  3351. }
  3352. /// Sets the list of update expressions for linear variables.
  3353. MutableArrayRef<Expr *> getUpdates() {
  3354. return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
  3355. }
  3356. ArrayRef<const Expr *> getUpdates() const {
  3357. return llvm::ArrayRef(getInits().end(), varlist_size());
  3358. }
  3359. /// Sets the list of final update expressions for linear variables.
  3360. MutableArrayRef<Expr *> getFinals() {
  3361. return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
  3362. }
  3363. ArrayRef<const Expr *> getFinals() const {
  3364. return llvm::ArrayRef(getUpdates().end(), varlist_size());
  3365. }
  3366. /// Gets the list of used expressions for linear variables.
  3367. MutableArrayRef<Expr *> getUsedExprs() {
  3368. return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
  3369. }
  3370. ArrayRef<const Expr *> getUsedExprs() const {
  3371. return llvm::ArrayRef(getFinals().end() + 2, varlist_size() + 1);
  3372. }
  3373. /// Sets the list of the copies of original linear variables.
  3374. /// \param PL List of expressions.
  3375. void setPrivates(ArrayRef<Expr *> PL);
  3376. /// Sets the list of the initial values for linear variables.
  3377. /// \param IL List of expressions.
  3378. void setInits(ArrayRef<Expr *> IL);
  3379. public:
  3380. /// Creates clause with a list of variables \a VL and a linear step
  3381. /// \a Step.
  3382. ///
  3383. /// \param C AST Context.
  3384. /// \param StartLoc Starting location of the clause.
  3385. /// \param LParenLoc Location of '('.
  3386. /// \param Modifier Modifier of 'linear' clause.
  3387. /// \param ModifierLoc Modifier location.
  3388. /// \param ColonLoc Location of ':'.
  3389. /// \param EndLoc Ending location of the clause.
  3390. /// \param VL List of references to the variables.
  3391. /// \param PL List of private copies of original variables.
  3392. /// \param IL List of initial values for the variables.
  3393. /// \param Step Linear step.
  3394. /// \param CalcStep Calculation of the linear step.
  3395. /// \param PreInit Statement that must be executed before entering the OpenMP
  3396. /// region with this clause.
  3397. /// \param PostUpdate Expression that must be executed after exit from the
  3398. /// OpenMP region with this clause.
  3399. static OMPLinearClause *
  3400. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  3401. OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
  3402. SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
  3403. ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
  3404. Stmt *PreInit, Expr *PostUpdate);
  3405. /// Creates an empty clause with the place for \a NumVars variables.
  3406. ///
  3407. /// \param C AST context.
  3408. /// \param NumVars Number of variables.
  3409. static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
  3410. /// Set modifier.
  3411. void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
  3412. /// Return modifier.
  3413. OpenMPLinearClauseKind getModifier() const { return Modifier; }
  3414. /// Set modifier location.
  3415. void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
  3416. /// Return modifier location.
  3417. SourceLocation getModifierLoc() const { return ModifierLoc; }
  3418. /// Sets the location of ':'.
  3419. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  3420. /// Returns the location of ':'.
  3421. SourceLocation getColonLoc() const { return ColonLoc; }
  3422. /// Returns linear step.
  3423. Expr *getStep() { return *(getFinals().end()); }
  3424. /// Returns linear step.
  3425. const Expr *getStep() const { return *(getFinals().end()); }
  3426. /// Returns expression to calculate linear step.
  3427. Expr *getCalcStep() { return *(getFinals().end() + 1); }
  3428. /// Returns expression to calculate linear step.
  3429. const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
  3430. /// Sets the list of update expressions for linear variables.
  3431. /// \param UL List of expressions.
  3432. void setUpdates(ArrayRef<Expr *> UL);
  3433. /// Sets the list of final update expressions for linear variables.
  3434. /// \param FL List of expressions.
  3435. void setFinals(ArrayRef<Expr *> FL);
  3436. /// Sets the list of used expressions for the linear clause.
  3437. void setUsedExprs(ArrayRef<Expr *> UE);
  3438. using privates_iterator = MutableArrayRef<Expr *>::iterator;
  3439. using privates_const_iterator = ArrayRef<const Expr *>::iterator;
  3440. using privates_range = llvm::iterator_range<privates_iterator>;
  3441. using privates_const_range = llvm::iterator_range<privates_const_iterator>;
  3442. privates_range privates() {
  3443. return privates_range(getPrivates().begin(), getPrivates().end());
  3444. }
  3445. privates_const_range privates() const {
  3446. return privates_const_range(getPrivates().begin(), getPrivates().end());
  3447. }
  3448. using inits_iterator = MutableArrayRef<Expr *>::iterator;
  3449. using inits_const_iterator = ArrayRef<const Expr *>::iterator;
  3450. using inits_range = llvm::iterator_range<inits_iterator>;
  3451. using inits_const_range = llvm::iterator_range<inits_const_iterator>;
  3452. inits_range inits() {
  3453. return inits_range(getInits().begin(), getInits().end());
  3454. }
  3455. inits_const_range inits() const {
  3456. return inits_const_range(getInits().begin(), getInits().end());
  3457. }
  3458. using updates_iterator = MutableArrayRef<Expr *>::iterator;
  3459. using updates_const_iterator = ArrayRef<const Expr *>::iterator;
  3460. using updates_range = llvm::iterator_range<updates_iterator>;
  3461. using updates_const_range = llvm::iterator_range<updates_const_iterator>;
  3462. updates_range updates() {
  3463. return updates_range(getUpdates().begin(), getUpdates().end());
  3464. }
  3465. updates_const_range updates() const {
  3466. return updates_const_range(getUpdates().begin(), getUpdates().end());
  3467. }
  3468. using finals_iterator = MutableArrayRef<Expr *>::iterator;
  3469. using finals_const_iterator = ArrayRef<const Expr *>::iterator;
  3470. using finals_range = llvm::iterator_range<finals_iterator>;
  3471. using finals_const_range = llvm::iterator_range<finals_const_iterator>;
  3472. finals_range finals() {
  3473. return finals_range(getFinals().begin(), getFinals().end());
  3474. }
  3475. finals_const_range finals() const {
  3476. return finals_const_range(getFinals().begin(), getFinals().end());
  3477. }
  3478. using used_expressions_iterator = MutableArrayRef<Expr *>::iterator;
  3479. using used_expressions_const_iterator = ArrayRef<const Expr *>::iterator;
  3480. using used_expressions_range =
  3481. llvm::iterator_range<used_expressions_iterator>;
  3482. using used_expressions_const_range =
  3483. llvm::iterator_range<used_expressions_const_iterator>;
  3484. used_expressions_range used_expressions() {
  3485. return finals_range(getUsedExprs().begin(), getUsedExprs().end());
  3486. }
  3487. used_expressions_const_range used_expressions() const {
  3488. return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
  3489. }
  3490. child_range children() {
  3491. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  3492. reinterpret_cast<Stmt **>(varlist_end()));
  3493. }
  3494. const_child_range children() const {
  3495. auto Children = const_cast<OMPLinearClause *>(this)->children();
  3496. return const_child_range(Children.begin(), Children.end());
  3497. }
  3498. child_range used_children();
  3499. const_child_range used_children() const {
  3500. auto Children = const_cast<OMPLinearClause *>(this)->used_children();
  3501. return const_child_range(Children.begin(), Children.end());
  3502. }
  3503. static bool classof(const OMPClause *T) {
  3504. return T->getClauseKind() == llvm::omp::OMPC_linear;
  3505. }
  3506. };
  3507. /// This represents clause 'aligned' in the '#pragma omp ...'
  3508. /// directives.
  3509. ///
  3510. /// \code
  3511. /// #pragma omp simd aligned(a,b : 8)
  3512. /// \endcode
  3513. /// In this example directive '#pragma omp simd' has clause 'aligned'
  3514. /// with variables 'a', 'b' and alignment '8'.
  3515. class OMPAlignedClause final
  3516. : public OMPVarListClause<OMPAlignedClause>,
  3517. private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
  3518. friend class OMPClauseReader;
  3519. friend OMPVarListClause;
  3520. friend TrailingObjects;
  3521. /// Location of ':'.
  3522. SourceLocation ColonLoc;
  3523. /// Sets the alignment for clause.
  3524. void setAlignment(Expr *A) { *varlist_end() = A; }
  3525. /// Build 'aligned' clause with given number of variables \a NumVars.
  3526. ///
  3527. /// \param StartLoc Starting location of the clause.
  3528. /// \param LParenLoc Location of '('.
  3529. /// \param ColonLoc Location of ':'.
  3530. /// \param EndLoc Ending location of the clause.
  3531. /// \param NumVars Number of variables.
  3532. OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  3533. SourceLocation ColonLoc, SourceLocation EndLoc,
  3534. unsigned NumVars)
  3535. : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
  3536. LParenLoc, EndLoc, NumVars),
  3537. ColonLoc(ColonLoc) {}
  3538. /// Build an empty clause.
  3539. ///
  3540. /// \param NumVars Number of variables.
  3541. explicit OMPAlignedClause(unsigned NumVars)
  3542. : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
  3543. SourceLocation(), SourceLocation(),
  3544. SourceLocation(), NumVars) {}
  3545. public:
  3546. /// Creates clause with a list of variables \a VL and alignment \a A.
  3547. ///
  3548. /// \param C AST Context.
  3549. /// \param StartLoc Starting location of the clause.
  3550. /// \param LParenLoc Location of '('.
  3551. /// \param ColonLoc Location of ':'.
  3552. /// \param EndLoc Ending location of the clause.
  3553. /// \param VL List of references to the variables.
  3554. /// \param A Alignment.
  3555. static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
  3556. SourceLocation LParenLoc,
  3557. SourceLocation ColonLoc,
  3558. SourceLocation EndLoc, ArrayRef<Expr *> VL,
  3559. Expr *A);
  3560. /// Creates an empty clause with the place for \a NumVars variables.
  3561. ///
  3562. /// \param C AST context.
  3563. /// \param NumVars Number of variables.
  3564. static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
  3565. /// Sets the location of ':'.
  3566. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  3567. /// Returns the location of ':'.
  3568. SourceLocation getColonLoc() const { return ColonLoc; }
  3569. /// Returns alignment.
  3570. Expr *getAlignment() { return *varlist_end(); }
  3571. /// Returns alignment.
  3572. const Expr *getAlignment() const { return *varlist_end(); }
  3573. child_range children() {
  3574. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  3575. reinterpret_cast<Stmt **>(varlist_end()));
  3576. }
  3577. const_child_range children() const {
  3578. auto Children = const_cast<OMPAlignedClause *>(this)->children();
  3579. return const_child_range(Children.begin(), Children.end());
  3580. }
  3581. child_range used_children() {
  3582. return child_range(child_iterator(), child_iterator());
  3583. }
  3584. const_child_range used_children() const {
  3585. return const_child_range(const_child_iterator(), const_child_iterator());
  3586. }
  3587. static bool classof(const OMPClause *T) {
  3588. return T->getClauseKind() == llvm::omp::OMPC_aligned;
  3589. }
  3590. };
  3591. /// This represents clause 'copyin' in the '#pragma omp ...' directives.
  3592. ///
  3593. /// \code
  3594. /// #pragma omp parallel copyin(a,b)
  3595. /// \endcode
  3596. /// In this example directive '#pragma omp parallel' has clause 'copyin'
  3597. /// with the variables 'a' and 'b'.
  3598. class OMPCopyinClause final
  3599. : public OMPVarListClause<OMPCopyinClause>,
  3600. private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
  3601. // Class has 3 additional tail allocated arrays:
  3602. // 1. List of helper expressions for proper generation of assignment operation
  3603. // required for copyin clause. This list represents sources.
  3604. // 2. List of helper expressions for proper generation of assignment operation
  3605. // required for copyin clause. This list represents destinations.
  3606. // 3. List of helper expressions that represents assignment operation:
  3607. // \code
  3608. // DstExprs = SrcExprs;
  3609. // \endcode
  3610. // Required for proper codegen of propagation of master's thread values of
  3611. // threadprivate variables to local instances of that variables in other
  3612. // implicit threads.
  3613. friend class OMPClauseReader;
  3614. friend OMPVarListClause;
  3615. friend TrailingObjects;
  3616. /// Build clause with number of variables \a N.
  3617. ///
  3618. /// \param StartLoc Starting location of the clause.
  3619. /// \param LParenLoc Location of '('.
  3620. /// \param EndLoc Ending location of the clause.
  3621. /// \param N Number of the variables in the clause.
  3622. OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  3623. SourceLocation EndLoc, unsigned N)
  3624. : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
  3625. LParenLoc, EndLoc, N) {}
  3626. /// Build an empty clause.
  3627. ///
  3628. /// \param N Number of variables.
  3629. explicit OMPCopyinClause(unsigned N)
  3630. : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
  3631. SourceLocation(), SourceLocation(),
  3632. SourceLocation(), N) {}
  3633. /// Set list of helper expressions, required for proper codegen of the
  3634. /// clause. These expressions represent source expression in the final
  3635. /// assignment statement performed by the copyin clause.
  3636. void setSourceExprs(ArrayRef<Expr *> SrcExprs);
  3637. /// Get the list of helper source expressions.
  3638. MutableArrayRef<Expr *> getSourceExprs() {
  3639. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  3640. }
  3641. ArrayRef<const Expr *> getSourceExprs() const {
  3642. return llvm::ArrayRef(varlist_end(), varlist_size());
  3643. }
  3644. /// Set list of helper expressions, required for proper codegen of the
  3645. /// clause. These expressions represent destination expression in the final
  3646. /// assignment statement performed by the copyin clause.
  3647. void setDestinationExprs(ArrayRef<Expr *> DstExprs);
  3648. /// Get the list of helper destination expressions.
  3649. MutableArrayRef<Expr *> getDestinationExprs() {
  3650. return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
  3651. }
  3652. ArrayRef<const Expr *> getDestinationExprs() const {
  3653. return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
  3654. }
  3655. /// Set list of helper assignment expressions, required for proper
  3656. /// codegen of the clause. These expressions are assignment expressions that
  3657. /// assign source helper expressions to destination helper expressions
  3658. /// correspondingly.
  3659. void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
  3660. /// Get the list of helper assignment expressions.
  3661. MutableArrayRef<Expr *> getAssignmentOps() {
  3662. return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
  3663. }
  3664. ArrayRef<const Expr *> getAssignmentOps() const {
  3665. return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
  3666. }
  3667. public:
  3668. /// Creates clause with a list of variables \a VL.
  3669. ///
  3670. /// \param C AST context.
  3671. /// \param StartLoc Starting location of the clause.
  3672. /// \param LParenLoc Location of '('.
  3673. /// \param EndLoc Ending location of the clause.
  3674. /// \param VL List of references to the variables.
  3675. /// \param SrcExprs List of helper expressions for proper generation of
  3676. /// assignment operation required for copyin clause. This list represents
  3677. /// sources.
  3678. /// \param DstExprs List of helper expressions for proper generation of
  3679. /// assignment operation required for copyin clause. This list represents
  3680. /// destinations.
  3681. /// \param AssignmentOps List of helper expressions that represents assignment
  3682. /// operation:
  3683. /// \code
  3684. /// DstExprs = SrcExprs;
  3685. /// \endcode
  3686. /// Required for proper codegen of propagation of master's thread values of
  3687. /// threadprivate variables to local instances of that variables in other
  3688. /// implicit threads.
  3689. static OMPCopyinClause *
  3690. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  3691. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  3692. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
  3693. /// Creates an empty clause with \a N variables.
  3694. ///
  3695. /// \param C AST context.
  3696. /// \param N The number of variables.
  3697. static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
  3698. using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
  3699. using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
  3700. using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
  3701. using helper_expr_const_range =
  3702. llvm::iterator_range<helper_expr_const_iterator>;
  3703. helper_expr_const_range source_exprs() const {
  3704. return helper_expr_const_range(getSourceExprs().begin(),
  3705. getSourceExprs().end());
  3706. }
  3707. helper_expr_range source_exprs() {
  3708. return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
  3709. }
  3710. helper_expr_const_range destination_exprs() const {
  3711. return helper_expr_const_range(getDestinationExprs().begin(),
  3712. getDestinationExprs().end());
  3713. }
  3714. helper_expr_range destination_exprs() {
  3715. return helper_expr_range(getDestinationExprs().begin(),
  3716. getDestinationExprs().end());
  3717. }
  3718. helper_expr_const_range assignment_ops() const {
  3719. return helper_expr_const_range(getAssignmentOps().begin(),
  3720. getAssignmentOps().end());
  3721. }
  3722. helper_expr_range assignment_ops() {
  3723. return helper_expr_range(getAssignmentOps().begin(),
  3724. getAssignmentOps().end());
  3725. }
  3726. child_range children() {
  3727. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  3728. reinterpret_cast<Stmt **>(varlist_end()));
  3729. }
  3730. const_child_range children() const {
  3731. auto Children = const_cast<OMPCopyinClause *>(this)->children();
  3732. return const_child_range(Children.begin(), Children.end());
  3733. }
  3734. child_range used_children() {
  3735. return child_range(child_iterator(), child_iterator());
  3736. }
  3737. const_child_range used_children() const {
  3738. return const_child_range(const_child_iterator(), const_child_iterator());
  3739. }
  3740. static bool classof(const OMPClause *T) {
  3741. return T->getClauseKind() == llvm::omp::OMPC_copyin;
  3742. }
  3743. };
  3744. /// This represents clause 'copyprivate' in the '#pragma omp ...'
  3745. /// directives.
  3746. ///
  3747. /// \code
  3748. /// #pragma omp single copyprivate(a,b)
  3749. /// \endcode
  3750. /// In this example directive '#pragma omp single' has clause 'copyprivate'
  3751. /// with the variables 'a' and 'b'.
  3752. class OMPCopyprivateClause final
  3753. : public OMPVarListClause<OMPCopyprivateClause>,
  3754. private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
  3755. friend class OMPClauseReader;
  3756. friend OMPVarListClause;
  3757. friend TrailingObjects;
  3758. /// Build clause with number of variables \a N.
  3759. ///
  3760. /// \param StartLoc Starting location of the clause.
  3761. /// \param LParenLoc Location of '('.
  3762. /// \param EndLoc Ending location of the clause.
  3763. /// \param N Number of the variables in the clause.
  3764. OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  3765. SourceLocation EndLoc, unsigned N)
  3766. : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
  3767. StartLoc, LParenLoc, EndLoc, N) {
  3768. }
  3769. /// Build an empty clause.
  3770. ///
  3771. /// \param N Number of variables.
  3772. explicit OMPCopyprivateClause(unsigned N)
  3773. : OMPVarListClause<OMPCopyprivateClause>(
  3774. llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
  3775. SourceLocation(), N) {}
  3776. /// Set list of helper expressions, required for proper codegen of the
  3777. /// clause. These expressions represent source expression in the final
  3778. /// assignment statement performed by the copyprivate clause.
  3779. void setSourceExprs(ArrayRef<Expr *> SrcExprs);
  3780. /// Get the list of helper source expressions.
  3781. MutableArrayRef<Expr *> getSourceExprs() {
  3782. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  3783. }
  3784. ArrayRef<const Expr *> getSourceExprs() const {
  3785. return llvm::ArrayRef(varlist_end(), varlist_size());
  3786. }
  3787. /// Set list of helper expressions, required for proper codegen of the
  3788. /// clause. These expressions represent destination expression in the final
  3789. /// assignment statement performed by the copyprivate clause.
  3790. void setDestinationExprs(ArrayRef<Expr *> DstExprs);
  3791. /// Get the list of helper destination expressions.
  3792. MutableArrayRef<Expr *> getDestinationExprs() {
  3793. return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
  3794. }
  3795. ArrayRef<const Expr *> getDestinationExprs() const {
  3796. return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
  3797. }
  3798. /// Set list of helper assignment expressions, required for proper
  3799. /// codegen of the clause. These expressions are assignment expressions that
  3800. /// assign source helper expressions to destination helper expressions
  3801. /// correspondingly.
  3802. void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
  3803. /// Get the list of helper assignment expressions.
  3804. MutableArrayRef<Expr *> getAssignmentOps() {
  3805. return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
  3806. }
  3807. ArrayRef<const Expr *> getAssignmentOps() const {
  3808. return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
  3809. }
  3810. public:
  3811. /// Creates clause with a list of variables \a VL.
  3812. ///
  3813. /// \param C AST context.
  3814. /// \param StartLoc Starting location of the clause.
  3815. /// \param LParenLoc Location of '('.
  3816. /// \param EndLoc Ending location of the clause.
  3817. /// \param VL List of references to the variables.
  3818. /// \param SrcExprs List of helper expressions for proper generation of
  3819. /// assignment operation required for copyprivate clause. This list represents
  3820. /// sources.
  3821. /// \param DstExprs List of helper expressions for proper generation of
  3822. /// assignment operation required for copyprivate clause. This list represents
  3823. /// destinations.
  3824. /// \param AssignmentOps List of helper expressions that represents assignment
  3825. /// operation:
  3826. /// \code
  3827. /// DstExprs = SrcExprs;
  3828. /// \endcode
  3829. /// Required for proper codegen of final assignment performed by the
  3830. /// copyprivate clause.
  3831. static OMPCopyprivateClause *
  3832. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  3833. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  3834. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
  3835. /// Creates an empty clause with \a N variables.
  3836. ///
  3837. /// \param C AST context.
  3838. /// \param N The number of variables.
  3839. static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
  3840. using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
  3841. using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
  3842. using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
  3843. using helper_expr_const_range =
  3844. llvm::iterator_range<helper_expr_const_iterator>;
  3845. helper_expr_const_range source_exprs() const {
  3846. return helper_expr_const_range(getSourceExprs().begin(),
  3847. getSourceExprs().end());
  3848. }
  3849. helper_expr_range source_exprs() {
  3850. return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
  3851. }
  3852. helper_expr_const_range destination_exprs() const {
  3853. return helper_expr_const_range(getDestinationExprs().begin(),
  3854. getDestinationExprs().end());
  3855. }
  3856. helper_expr_range destination_exprs() {
  3857. return helper_expr_range(getDestinationExprs().begin(),
  3858. getDestinationExprs().end());
  3859. }
  3860. helper_expr_const_range assignment_ops() const {
  3861. return helper_expr_const_range(getAssignmentOps().begin(),
  3862. getAssignmentOps().end());
  3863. }
  3864. helper_expr_range assignment_ops() {
  3865. return helper_expr_range(getAssignmentOps().begin(),
  3866. getAssignmentOps().end());
  3867. }
  3868. child_range children() {
  3869. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  3870. reinterpret_cast<Stmt **>(varlist_end()));
  3871. }
  3872. const_child_range children() const {
  3873. auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
  3874. return const_child_range(Children.begin(), Children.end());
  3875. }
  3876. child_range used_children() {
  3877. return child_range(child_iterator(), child_iterator());
  3878. }
  3879. const_child_range used_children() const {
  3880. return const_child_range(const_child_iterator(), const_child_iterator());
  3881. }
  3882. static bool classof(const OMPClause *T) {
  3883. return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
  3884. }
  3885. };
  3886. /// This represents implicit clause 'flush' for the '#pragma omp flush'
  3887. /// directive.
  3888. /// This clause does not exist by itself, it can be only as a part of 'omp
  3889. /// flush' directive. This clause is introduced to keep the original structure
  3890. /// of \a OMPExecutableDirective class and its derivatives and to use the
  3891. /// existing infrastructure of clauses with the list of variables.
  3892. ///
  3893. /// \code
  3894. /// #pragma omp flush(a,b)
  3895. /// \endcode
  3896. /// In this example directive '#pragma omp flush' has implicit clause 'flush'
  3897. /// with the variables 'a' and 'b'.
  3898. class OMPFlushClause final
  3899. : public OMPVarListClause<OMPFlushClause>,
  3900. private llvm::TrailingObjects<OMPFlushClause, Expr *> {
  3901. friend OMPVarListClause;
  3902. friend TrailingObjects;
  3903. /// Build clause with number of variables \a N.
  3904. ///
  3905. /// \param StartLoc Starting location of the clause.
  3906. /// \param LParenLoc Location of '('.
  3907. /// \param EndLoc Ending location of the clause.
  3908. /// \param N Number of the variables in the clause.
  3909. OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  3910. SourceLocation EndLoc, unsigned N)
  3911. : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
  3912. LParenLoc, EndLoc, N) {}
  3913. /// Build an empty clause.
  3914. ///
  3915. /// \param N Number of variables.
  3916. explicit OMPFlushClause(unsigned N)
  3917. : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
  3918. SourceLocation(), SourceLocation(),
  3919. SourceLocation(), N) {}
  3920. public:
  3921. /// Creates clause with a list of variables \a VL.
  3922. ///
  3923. /// \param C AST context.
  3924. /// \param StartLoc Starting location of the clause.
  3925. /// \param LParenLoc Location of '('.
  3926. /// \param EndLoc Ending location of the clause.
  3927. /// \param VL List of references to the variables.
  3928. static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
  3929. SourceLocation LParenLoc, SourceLocation EndLoc,
  3930. ArrayRef<Expr *> VL);
  3931. /// Creates an empty clause with \a N variables.
  3932. ///
  3933. /// \param C AST context.
  3934. /// \param N The number of variables.
  3935. static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
  3936. child_range children() {
  3937. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  3938. reinterpret_cast<Stmt **>(varlist_end()));
  3939. }
  3940. const_child_range children() const {
  3941. auto Children = const_cast<OMPFlushClause *>(this)->children();
  3942. return const_child_range(Children.begin(), Children.end());
  3943. }
  3944. child_range used_children() {
  3945. return child_range(child_iterator(), child_iterator());
  3946. }
  3947. const_child_range used_children() const {
  3948. return const_child_range(const_child_iterator(), const_child_iterator());
  3949. }
  3950. static bool classof(const OMPClause *T) {
  3951. return T->getClauseKind() == llvm::omp::OMPC_flush;
  3952. }
  3953. };
  3954. /// This represents implicit clause 'depobj' for the '#pragma omp depobj'
  3955. /// directive.
  3956. /// This clause does not exist by itself, it can be only as a part of 'omp
  3957. /// depobj' directive. This clause is introduced to keep the original structure
  3958. /// of \a OMPExecutableDirective class and its derivatives and to use the
  3959. /// existing infrastructure of clauses with the list of variables.
  3960. ///
  3961. /// \code
  3962. /// #pragma omp depobj(a) destroy
  3963. /// \endcode
  3964. /// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
  3965. /// with the depobj 'a'.
  3966. class OMPDepobjClause final : public OMPClause {
  3967. friend class OMPClauseReader;
  3968. /// Location of '('.
  3969. SourceLocation LParenLoc;
  3970. /// Chunk size.
  3971. Expr *Depobj = nullptr;
  3972. /// Build clause with number of variables \a N.
  3973. ///
  3974. /// \param StartLoc Starting location of the clause.
  3975. /// \param LParenLoc Location of '('.
  3976. /// \param EndLoc Ending location of the clause.
  3977. OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  3978. SourceLocation EndLoc)
  3979. : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
  3980. LParenLoc(LParenLoc) {}
  3981. /// Build an empty clause.
  3982. ///
  3983. explicit OMPDepobjClause()
  3984. : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
  3985. void setDepobj(Expr *E) { Depobj = E; }
  3986. /// Sets the location of '('.
  3987. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  3988. public:
  3989. /// Creates clause.
  3990. ///
  3991. /// \param C AST context.
  3992. /// \param StartLoc Starting location of the clause.
  3993. /// \param LParenLoc Location of '('.
  3994. /// \param EndLoc Ending location of the clause.
  3995. /// \param Depobj depobj expression associated with the 'depobj' directive.
  3996. static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
  3997. SourceLocation LParenLoc,
  3998. SourceLocation EndLoc, Expr *Depobj);
  3999. /// Creates an empty clause.
  4000. ///
  4001. /// \param C AST context.
  4002. static OMPDepobjClause *CreateEmpty(const ASTContext &C);
  4003. /// Returns depobj expression associated with the clause.
  4004. Expr *getDepobj() { return Depobj; }
  4005. const Expr *getDepobj() const { return Depobj; }
  4006. /// Returns the location of '('.
  4007. SourceLocation getLParenLoc() const { return LParenLoc; }
  4008. child_range children() {
  4009. return child_range(reinterpret_cast<Stmt **>(&Depobj),
  4010. reinterpret_cast<Stmt **>(&Depobj) + 1);
  4011. }
  4012. const_child_range children() const {
  4013. auto Children = const_cast<OMPDepobjClause *>(this)->children();
  4014. return const_child_range(Children.begin(), Children.end());
  4015. }
  4016. child_range used_children() {
  4017. return child_range(child_iterator(), child_iterator());
  4018. }
  4019. const_child_range used_children() const {
  4020. return const_child_range(const_child_iterator(), const_child_iterator());
  4021. }
  4022. static bool classof(const OMPClause *T) {
  4023. return T->getClauseKind() == llvm::omp::OMPC_depobj;
  4024. }
  4025. };
  4026. /// This represents implicit clause 'depend' for the '#pragma omp task'
  4027. /// directive.
  4028. ///
  4029. /// \code
  4030. /// #pragma omp task depend(in:a,b)
  4031. /// \endcode
  4032. /// In this example directive '#pragma omp task' with clause 'depend' with the
  4033. /// variables 'a' and 'b' with dependency 'in'.
  4034. class OMPDependClause final
  4035. : public OMPVarListClause<OMPDependClause>,
  4036. private llvm::TrailingObjects<OMPDependClause, Expr *> {
  4037. friend class OMPClauseReader;
  4038. friend OMPVarListClause;
  4039. friend TrailingObjects;
  4040. public:
  4041. struct DependDataTy final {
  4042. /// Dependency type (one of in, out, inout).
  4043. OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
  4044. /// Dependency type location.
  4045. SourceLocation DepLoc;
  4046. /// Colon location.
  4047. SourceLocation ColonLoc;
  4048. /// Location of 'omp_all_memory'.
  4049. SourceLocation OmpAllMemoryLoc;
  4050. };
  4051. private:
  4052. /// Dependency type and source locations.
  4053. DependDataTy Data;
  4054. /// Number of loops, associated with the depend clause.
  4055. unsigned NumLoops = 0;
  4056. /// Build clause with number of variables \a N.
  4057. ///
  4058. /// \param StartLoc Starting location of the clause.
  4059. /// \param LParenLoc Location of '('.
  4060. /// \param EndLoc Ending location of the clause.
  4061. /// \param N Number of the variables in the clause.
  4062. /// \param NumLoops Number of loops that is associated with this depend
  4063. /// clause.
  4064. OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  4065. SourceLocation EndLoc, unsigned N, unsigned NumLoops)
  4066. : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc,
  4067. LParenLoc, EndLoc, N),
  4068. NumLoops(NumLoops) {}
  4069. /// Build an empty clause.
  4070. ///
  4071. /// \param N Number of variables.
  4072. /// \param NumLoops Number of loops that is associated with this depend
  4073. /// clause.
  4074. explicit OMPDependClause(unsigned N, unsigned NumLoops)
  4075. : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend,
  4076. SourceLocation(), SourceLocation(),
  4077. SourceLocation(), N),
  4078. NumLoops(NumLoops) {}
  4079. /// Set dependency kind.
  4080. void setDependencyKind(OpenMPDependClauseKind K) { Data.DepKind = K; }
  4081. /// Set dependency kind and its location.
  4082. void setDependencyLoc(SourceLocation Loc) { Data.DepLoc = Loc; }
  4083. /// Set colon location.
  4084. void setColonLoc(SourceLocation Loc) { Data.ColonLoc = Loc; }
  4085. /// Set the 'omp_all_memory' location.
  4086. void setOmpAllMemoryLoc(SourceLocation Loc) { Data.OmpAllMemoryLoc = Loc; }
  4087. /// Sets optional dependency modifier.
  4088. void setModifier(Expr *DepModifier);
  4089. public:
  4090. /// Creates clause with a list of variables \a VL.
  4091. ///
  4092. /// \param C AST context.
  4093. /// \param StartLoc Starting location of the clause.
  4094. /// \param LParenLoc Location of '('.
  4095. /// \param EndLoc Ending location of the clause.
  4096. /// \param Data Dependency type and source locations.
  4097. /// \param VL List of references to the variables.
  4098. /// \param NumLoops Number of loops that is associated with this depend
  4099. /// clause.
  4100. static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
  4101. SourceLocation LParenLoc,
  4102. SourceLocation EndLoc, DependDataTy Data,
  4103. Expr *DepModifier, ArrayRef<Expr *> VL,
  4104. unsigned NumLoops);
  4105. /// Creates an empty clause with \a N variables.
  4106. ///
  4107. /// \param C AST context.
  4108. /// \param N The number of variables.
  4109. /// \param NumLoops Number of loops that is associated with this depend
  4110. /// clause.
  4111. static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
  4112. unsigned NumLoops);
  4113. /// Get dependency type.
  4114. OpenMPDependClauseKind getDependencyKind() const { return Data.DepKind; }
  4115. /// Get dependency type location.
  4116. SourceLocation getDependencyLoc() const { return Data.DepLoc; }
  4117. /// Get colon location.
  4118. SourceLocation getColonLoc() const { return Data.ColonLoc; }
  4119. /// Get 'omp_all_memory' location.
  4120. SourceLocation getOmpAllMemoryLoc() const { return Data.OmpAllMemoryLoc; }
  4121. /// Return optional depend modifier.
  4122. Expr *getModifier();
  4123. const Expr *getModifier() const {
  4124. return const_cast<OMPDependClause *>(this)->getModifier();
  4125. }
  4126. /// Get number of loops associated with the clause.
  4127. unsigned getNumLoops() const { return NumLoops; }
  4128. /// Set the loop data for the depend clauses with 'sink|source' kind of
  4129. /// dependency.
  4130. void setLoopData(unsigned NumLoop, Expr *Cnt);
  4131. /// Get the loop data.
  4132. Expr *getLoopData(unsigned NumLoop);
  4133. const Expr *getLoopData(unsigned NumLoop) const;
  4134. child_range children() {
  4135. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  4136. reinterpret_cast<Stmt **>(varlist_end()));
  4137. }
  4138. const_child_range children() const {
  4139. auto Children = const_cast<OMPDependClause *>(this)->children();
  4140. return const_child_range(Children.begin(), Children.end());
  4141. }
  4142. child_range used_children() {
  4143. return child_range(child_iterator(), child_iterator());
  4144. }
  4145. const_child_range used_children() const {
  4146. return const_child_range(const_child_iterator(), const_child_iterator());
  4147. }
  4148. static bool classof(const OMPClause *T) {
  4149. return T->getClauseKind() == llvm::omp::OMPC_depend;
  4150. }
  4151. };
  4152. /// This represents 'device' clause in the '#pragma omp ...'
  4153. /// directive.
  4154. ///
  4155. /// \code
  4156. /// #pragma omp target device(a)
  4157. /// \endcode
  4158. /// In this example directive '#pragma omp target' has clause 'device'
  4159. /// with single expression 'a'.
  4160. class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
  4161. friend class OMPClauseReader;
  4162. /// Location of '('.
  4163. SourceLocation LParenLoc;
  4164. /// Device clause modifier.
  4165. OpenMPDeviceClauseModifier Modifier = OMPC_DEVICE_unknown;
  4166. /// Location of the modifier.
  4167. SourceLocation ModifierLoc;
  4168. /// Device number.
  4169. Stmt *Device = nullptr;
  4170. /// Set the device number.
  4171. ///
  4172. /// \param E Device number.
  4173. void setDevice(Expr *E) { Device = E; }
  4174. /// Sets modifier.
  4175. void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; }
  4176. /// Setst modifier location.
  4177. void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
  4178. public:
  4179. /// Build 'device' clause.
  4180. ///
  4181. /// \param Modifier Clause modifier.
  4182. /// \param E Expression associated with this clause.
  4183. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  4184. /// clause must be captured.
  4185. /// \param StartLoc Starting location of the clause.
  4186. /// \param ModifierLoc Modifier location.
  4187. /// \param LParenLoc Location of '('.
  4188. /// \param EndLoc Ending location of the clause.
  4189. OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE,
  4190. OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
  4191. SourceLocation LParenLoc, SourceLocation ModifierLoc,
  4192. SourceLocation EndLoc)
  4193. : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc),
  4194. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
  4195. ModifierLoc(ModifierLoc), Device(E) {
  4196. setPreInitStmt(HelperE, CaptureRegion);
  4197. }
  4198. /// Build an empty clause.
  4199. OMPDeviceClause()
  4200. : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()),
  4201. OMPClauseWithPreInit(this) {}
  4202. /// Sets the location of '('.
  4203. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  4204. /// Returns the location of '('.
  4205. SourceLocation getLParenLoc() const { return LParenLoc; }
  4206. /// Return device number.
  4207. Expr *getDevice() { return cast<Expr>(Device); }
  4208. /// Return device number.
  4209. Expr *getDevice() const { return cast<Expr>(Device); }
  4210. /// Gets modifier.
  4211. OpenMPDeviceClauseModifier getModifier() const { return Modifier; }
  4212. /// Gets modifier location.
  4213. SourceLocation getModifierLoc() const { return ModifierLoc; }
  4214. child_range children() { return child_range(&Device, &Device + 1); }
  4215. const_child_range children() const {
  4216. return const_child_range(&Device, &Device + 1);
  4217. }
  4218. child_range used_children() {
  4219. return child_range(child_iterator(), child_iterator());
  4220. }
  4221. const_child_range used_children() const {
  4222. return const_child_range(const_child_iterator(), const_child_iterator());
  4223. }
  4224. static bool classof(const OMPClause *T) {
  4225. return T->getClauseKind() == llvm::omp::OMPC_device;
  4226. }
  4227. };
  4228. /// This represents 'threads' clause in the '#pragma omp ...' directive.
  4229. ///
  4230. /// \code
  4231. /// #pragma omp ordered threads
  4232. /// \endcode
  4233. /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
  4234. class OMPThreadsClause final
  4235. : public OMPNoChildClause<llvm::omp::OMPC_threads> {
  4236. public:
  4237. /// Build 'threads' clause.
  4238. ///
  4239. /// \param StartLoc Starting location of the clause.
  4240. /// \param EndLoc Ending location of the clause.
  4241. OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
  4242. : OMPNoChildClause(StartLoc, EndLoc) {}
  4243. /// Build an empty clause.
  4244. OMPThreadsClause() : OMPNoChildClause() {}
  4245. };
  4246. /// This represents 'simd' clause in the '#pragma omp ...' directive.
  4247. ///
  4248. /// \code
  4249. /// #pragma omp ordered simd
  4250. /// \endcode
  4251. /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
  4252. class OMPSIMDClause : public OMPClause {
  4253. public:
  4254. /// Build 'simd' clause.
  4255. ///
  4256. /// \param StartLoc Starting location of the clause.
  4257. /// \param EndLoc Ending location of the clause.
  4258. OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
  4259. : OMPClause(llvm::omp::OMPC_simd, StartLoc, EndLoc) {}
  4260. /// Build an empty clause.
  4261. OMPSIMDClause()
  4262. : OMPClause(llvm::omp::OMPC_simd, SourceLocation(), SourceLocation()) {}
  4263. child_range children() {
  4264. return child_range(child_iterator(), child_iterator());
  4265. }
  4266. const_child_range children() const {
  4267. return const_child_range(const_child_iterator(), const_child_iterator());
  4268. }
  4269. child_range used_children() {
  4270. return child_range(child_iterator(), child_iterator());
  4271. }
  4272. const_child_range used_children() const {
  4273. return const_child_range(const_child_iterator(), const_child_iterator());
  4274. }
  4275. static bool classof(const OMPClause *T) {
  4276. return T->getClauseKind() == llvm::omp::OMPC_simd;
  4277. }
  4278. };
  4279. /// Struct that defines common infrastructure to handle mappable
  4280. /// expressions used in OpenMP clauses.
  4281. class OMPClauseMappableExprCommon {
  4282. public:
  4283. /// Class that represents a component of a mappable expression. E.g.
  4284. /// for an expression S.a, the first component is a declaration reference
  4285. /// expression associated with 'S' and the second is a member expression
  4286. /// associated with the field declaration 'a'. If the expression is an array
  4287. /// subscript it may not have any associated declaration. In that case the
  4288. /// associated declaration is set to nullptr.
  4289. class MappableComponent {
  4290. /// Pair of Expression and Non-contiguous pair associated with the
  4291. /// component.
  4292. llvm::PointerIntPair<Expr *, 1, bool> AssociatedExpressionNonContiguousPr;
  4293. /// Declaration associated with the declaration. If the component does
  4294. /// not have a declaration (e.g. array subscripts or section), this is set
  4295. /// to nullptr.
  4296. ValueDecl *AssociatedDeclaration = nullptr;
  4297. public:
  4298. explicit MappableComponent() = default;
  4299. explicit MappableComponent(Expr *AssociatedExpression,
  4300. ValueDecl *AssociatedDeclaration,
  4301. bool IsNonContiguous)
  4302. : AssociatedExpressionNonContiguousPr(AssociatedExpression,
  4303. IsNonContiguous),
  4304. AssociatedDeclaration(
  4305. AssociatedDeclaration
  4306. ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
  4307. : nullptr) {}
  4308. Expr *getAssociatedExpression() const {
  4309. return AssociatedExpressionNonContiguousPr.getPointer();
  4310. }
  4311. bool isNonContiguous() const {
  4312. return AssociatedExpressionNonContiguousPr.getInt();
  4313. }
  4314. ValueDecl *getAssociatedDeclaration() const {
  4315. return AssociatedDeclaration;
  4316. }
  4317. };
  4318. // List of components of an expression. This first one is the whole
  4319. // expression and the last one is the base expression.
  4320. using MappableExprComponentList = SmallVector<MappableComponent, 8>;
  4321. using MappableExprComponentListRef = ArrayRef<MappableComponent>;
  4322. // List of all component lists associated to the same base declaration.
  4323. // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
  4324. // their component list but the same base declaration 'S'.
  4325. using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
  4326. using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
  4327. protected:
  4328. // Return the total number of elements in a list of component lists.
  4329. static unsigned
  4330. getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
  4331. // Return the total number of elements in a list of declarations. All
  4332. // declarations are expected to be canonical.
  4333. static unsigned
  4334. getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
  4335. };
  4336. /// This structure contains all sizes needed for by an
  4337. /// OMPMappableExprListClause.
  4338. struct OMPMappableExprListSizeTy {
  4339. /// Number of expressions listed.
  4340. unsigned NumVars;
  4341. /// Number of unique base declarations.
  4342. unsigned NumUniqueDeclarations;
  4343. /// Number of component lists.
  4344. unsigned NumComponentLists;
  4345. /// Total number of expression components.
  4346. unsigned NumComponents;
  4347. OMPMappableExprListSizeTy() = default;
  4348. OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations,
  4349. unsigned NumComponentLists, unsigned NumComponents)
  4350. : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations),
  4351. NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
  4352. };
  4353. /// This represents clauses with a list of expressions that are mappable.
  4354. /// Examples of these clauses are 'map' in
  4355. /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
  4356. /// in '#pragma omp target update...' directives.
  4357. template <class T>
  4358. class OMPMappableExprListClause : public OMPVarListClause<T>,
  4359. public OMPClauseMappableExprCommon {
  4360. friend class OMPClauseReader;
  4361. /// Number of unique declarations in this clause.
  4362. unsigned NumUniqueDeclarations;
  4363. /// Number of component lists in this clause.
  4364. unsigned NumComponentLists;
  4365. /// Total number of components in this clause.
  4366. unsigned NumComponents;
  4367. /// Whether this clause is possible to have user-defined mappers associated.
  4368. /// It should be true for map, to, and from clauses, and false for
  4369. /// use_device_ptr and is_device_ptr.
  4370. const bool SupportsMapper;
  4371. /// C++ nested name specifier for the associated user-defined mapper.
  4372. NestedNameSpecifierLoc MapperQualifierLoc;
  4373. /// The associated user-defined mapper identifier information.
  4374. DeclarationNameInfo MapperIdInfo;
  4375. protected:
  4376. /// Build a clause for \a NumUniqueDeclarations declarations, \a
  4377. /// NumComponentLists total component lists, and \a NumComponents total
  4378. /// components.
  4379. ///
  4380. /// \param K Kind of the clause.
  4381. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  4382. /// StartLoc: starting location of the clause (the clause keyword); 2)
  4383. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  4384. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  4385. /// NumVars: number of expressions listed in this clause; 2)
  4386. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  4387. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  4388. /// NumComponents: total number of expression components in the clause.
  4389. /// \param SupportsMapper Indicates whether this clause is possible to have
  4390. /// user-defined mappers associated.
  4391. /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
  4392. /// user-defined mapper.
  4393. /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
  4394. OMPMappableExprListClause(
  4395. OpenMPClauseKind K, const OMPVarListLocTy &Locs,
  4396. const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper = false,
  4397. NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
  4398. DeclarationNameInfo *MapperIdInfoPtr = nullptr)
  4399. : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
  4400. Sizes.NumVars),
  4401. NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
  4402. NumComponentLists(Sizes.NumComponentLists),
  4403. NumComponents(Sizes.NumComponents), SupportsMapper(SupportsMapper) {
  4404. if (MapperQualifierLocPtr)
  4405. MapperQualifierLoc = *MapperQualifierLocPtr;
  4406. if (MapperIdInfoPtr)
  4407. MapperIdInfo = *MapperIdInfoPtr;
  4408. }
  4409. /// Get the unique declarations that are in the trailing objects of the
  4410. /// class.
  4411. MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
  4412. return MutableArrayRef<ValueDecl *>(
  4413. static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
  4414. NumUniqueDeclarations);
  4415. }
  4416. /// Get the unique declarations that are in the trailing objects of the
  4417. /// class.
  4418. ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
  4419. return ArrayRef<ValueDecl *>(
  4420. static_cast<const T *>(this)
  4421. ->template getTrailingObjects<ValueDecl *>(),
  4422. NumUniqueDeclarations);
  4423. }
  4424. /// Set the unique declarations that are in the trailing objects of the
  4425. /// class.
  4426. void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
  4427. assert(UDs.size() == NumUniqueDeclarations &&
  4428. "Unexpected amount of unique declarations.");
  4429. std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
  4430. }
  4431. /// Get the number of lists per declaration that are in the trailing
  4432. /// objects of the class.
  4433. MutableArrayRef<unsigned> getDeclNumListsRef() {
  4434. return MutableArrayRef<unsigned>(
  4435. static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
  4436. NumUniqueDeclarations);
  4437. }
  4438. /// Get the number of lists per declaration that are in the trailing
  4439. /// objects of the class.
  4440. ArrayRef<unsigned> getDeclNumListsRef() const {
  4441. return ArrayRef<unsigned>(
  4442. static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
  4443. NumUniqueDeclarations);
  4444. }
  4445. /// Set the number of lists per declaration that are in the trailing
  4446. /// objects of the class.
  4447. void setDeclNumLists(ArrayRef<unsigned> DNLs) {
  4448. assert(DNLs.size() == NumUniqueDeclarations &&
  4449. "Unexpected amount of list numbers.");
  4450. std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
  4451. }
  4452. /// Get the cumulative component lists sizes that are in the trailing
  4453. /// objects of the class. They are appended after the number of lists.
  4454. MutableArrayRef<unsigned> getComponentListSizesRef() {
  4455. return MutableArrayRef<unsigned>(
  4456. static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
  4457. NumUniqueDeclarations,
  4458. NumComponentLists);
  4459. }
  4460. /// Get the cumulative component lists sizes that are in the trailing
  4461. /// objects of the class. They are appended after the number of lists.
  4462. ArrayRef<unsigned> getComponentListSizesRef() const {
  4463. return ArrayRef<unsigned>(
  4464. static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
  4465. NumUniqueDeclarations,
  4466. NumComponentLists);
  4467. }
  4468. /// Set the cumulative component lists sizes that are in the trailing
  4469. /// objects of the class.
  4470. void setComponentListSizes(ArrayRef<unsigned> CLSs) {
  4471. assert(CLSs.size() == NumComponentLists &&
  4472. "Unexpected amount of component lists.");
  4473. std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
  4474. }
  4475. /// Get the components that are in the trailing objects of the class.
  4476. MutableArrayRef<MappableComponent> getComponentsRef() {
  4477. return MutableArrayRef<MappableComponent>(
  4478. static_cast<T *>(this)
  4479. ->template getTrailingObjects<MappableComponent>(),
  4480. NumComponents);
  4481. }
  4482. /// Get the components that are in the trailing objects of the class.
  4483. ArrayRef<MappableComponent> getComponentsRef() const {
  4484. return ArrayRef<MappableComponent>(
  4485. static_cast<const T *>(this)
  4486. ->template getTrailingObjects<MappableComponent>(),
  4487. NumComponents);
  4488. }
  4489. /// Set the components that are in the trailing objects of the class.
  4490. /// This requires the list sizes so that it can also fill the original
  4491. /// expressions, which are the first component of each list.
  4492. void setComponents(ArrayRef<MappableComponent> Components,
  4493. ArrayRef<unsigned> CLSs) {
  4494. assert(Components.size() == NumComponents &&
  4495. "Unexpected amount of component lists.");
  4496. assert(CLSs.size() == NumComponentLists &&
  4497. "Unexpected amount of list sizes.");
  4498. std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
  4499. }
  4500. /// Fill the clause information from the list of declarations and
  4501. /// associated component lists.
  4502. void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
  4503. MappableExprComponentListsRef ComponentLists) {
  4504. // Perform some checks to make sure the data sizes are consistent with the
  4505. // information available when the clause was created.
  4506. assert(getUniqueDeclarationsTotalNumber(Declarations) ==
  4507. NumUniqueDeclarations &&
  4508. "Unexpected number of mappable expression info entries!");
  4509. assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
  4510. "Unexpected total number of components!");
  4511. assert(Declarations.size() == ComponentLists.size() &&
  4512. "Declaration and component lists size is not consistent!");
  4513. assert(Declarations.size() == NumComponentLists &&
  4514. "Unexpected declaration and component lists size!");
  4515. // Organize the components by declaration and retrieve the original
  4516. // expression. Original expressions are always the first component of the
  4517. // mappable component list.
  4518. llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
  4519. ComponentListMap;
  4520. {
  4521. auto CI = ComponentLists.begin();
  4522. for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
  4523. ++DI, ++CI) {
  4524. assert(!CI->empty() && "Invalid component list!");
  4525. ComponentListMap[*DI].push_back(*CI);
  4526. }
  4527. }
  4528. // Iterators of the target storage.
  4529. auto UniqueDeclarations = getUniqueDeclsRef();
  4530. auto UDI = UniqueDeclarations.begin();
  4531. auto DeclNumLists = getDeclNumListsRef();
  4532. auto DNLI = DeclNumLists.begin();
  4533. auto ComponentListSizes = getComponentListSizesRef();
  4534. auto CLSI = ComponentListSizes.begin();
  4535. auto Components = getComponentsRef();
  4536. auto CI = Components.begin();
  4537. // Variable to compute the accumulation of the number of components.
  4538. unsigned PrevSize = 0u;
  4539. // Scan all the declarations and associated component lists.
  4540. for (auto &M : ComponentListMap) {
  4541. // The declaration.
  4542. auto *D = M.first;
  4543. // The component lists.
  4544. auto CL = M.second;
  4545. // Initialize the entry.
  4546. *UDI = D;
  4547. ++UDI;
  4548. *DNLI = CL.size();
  4549. ++DNLI;
  4550. // Obtain the cumulative sizes and concatenate all the components in the
  4551. // reserved storage.
  4552. for (auto C : CL) {
  4553. // Accumulate with the previous size.
  4554. PrevSize += C.size();
  4555. // Save the size.
  4556. *CLSI = PrevSize;
  4557. ++CLSI;
  4558. // Append components after the current components iterator.
  4559. CI = std::copy(C.begin(), C.end(), CI);
  4560. }
  4561. }
  4562. }
  4563. /// Set the nested name specifier of associated user-defined mapper.
  4564. void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
  4565. MapperQualifierLoc = NNSL;
  4566. }
  4567. /// Set the name of associated user-defined mapper.
  4568. void setMapperIdInfo(DeclarationNameInfo MapperId) {
  4569. MapperIdInfo = MapperId;
  4570. }
  4571. /// Get the user-defined mapper references that are in the trailing objects of
  4572. /// the class.
  4573. MutableArrayRef<Expr *> getUDMapperRefs() {
  4574. assert(SupportsMapper &&
  4575. "Must be a clause that is possible to have user-defined mappers");
  4576. return llvm::MutableArrayRef<Expr *>(
  4577. static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
  4578. OMPVarListClause<T>::varlist_size(),
  4579. OMPVarListClause<T>::varlist_size());
  4580. }
  4581. /// Get the user-defined mappers references that are in the trailing objects
  4582. /// of the class.
  4583. ArrayRef<Expr *> getUDMapperRefs() const {
  4584. assert(SupportsMapper &&
  4585. "Must be a clause that is possible to have user-defined mappers");
  4586. return llvm::ArrayRef<Expr *>(
  4587. static_cast<const T *>(this)->template getTrailingObjects<Expr *>() +
  4588. OMPVarListClause<T>::varlist_size(),
  4589. OMPVarListClause<T>::varlist_size());
  4590. }
  4591. /// Set the user-defined mappers that are in the trailing objects of the
  4592. /// class.
  4593. void setUDMapperRefs(ArrayRef<Expr *> DMDs) {
  4594. assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
  4595. "Unexpected number of user-defined mappers.");
  4596. assert(SupportsMapper &&
  4597. "Must be a clause that is possible to have user-defined mappers");
  4598. std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin());
  4599. }
  4600. public:
  4601. /// Return the number of unique base declarations in this clause.
  4602. unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
  4603. /// Return the number of lists derived from the clause expressions.
  4604. unsigned getTotalComponentListNum() const { return NumComponentLists; }
  4605. /// Return the total number of components in all lists derived from the
  4606. /// clause.
  4607. unsigned getTotalComponentsNum() const { return NumComponents; }
  4608. /// Gets the nested name specifier for associated user-defined mapper.
  4609. NestedNameSpecifierLoc getMapperQualifierLoc() const {
  4610. return MapperQualifierLoc;
  4611. }
  4612. /// Gets the name info for associated user-defined mapper.
  4613. const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
  4614. /// Iterator that browse the components by lists. It also allows
  4615. /// browsing components of a single declaration.
  4616. class const_component_lists_iterator
  4617. : public llvm::iterator_adaptor_base<
  4618. const_component_lists_iterator,
  4619. MappableExprComponentListRef::const_iterator,
  4620. std::forward_iterator_tag, MappableComponent, ptrdiff_t,
  4621. MappableComponent, MappableComponent> {
  4622. // The declaration the iterator currently refers to.
  4623. ArrayRef<ValueDecl *>::iterator DeclCur;
  4624. // The list number associated with the current declaration.
  4625. ArrayRef<unsigned>::iterator NumListsCur;
  4626. // Whether this clause is possible to have user-defined mappers associated.
  4627. const bool SupportsMapper;
  4628. // The user-defined mapper associated with the current declaration.
  4629. ArrayRef<Expr *>::iterator MapperCur;
  4630. // Remaining lists for the current declaration.
  4631. unsigned RemainingLists = 0;
  4632. // The cumulative size of the previous list, or zero if there is no previous
  4633. // list.
  4634. unsigned PrevListSize = 0;
  4635. // The cumulative sizes of the current list - it will delimit the remaining
  4636. // range of interest.
  4637. ArrayRef<unsigned>::const_iterator ListSizeCur;
  4638. ArrayRef<unsigned>::const_iterator ListSizeEnd;
  4639. // Iterator to the end of the components storage.
  4640. MappableExprComponentListRef::const_iterator End;
  4641. public:
  4642. /// Construct an iterator that scans all lists.
  4643. explicit const_component_lists_iterator(
  4644. ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
  4645. ArrayRef<unsigned> CumulativeListSizes,
  4646. MappableExprComponentListRef Components, bool SupportsMapper,
  4647. ArrayRef<Expr *> Mappers)
  4648. : const_component_lists_iterator::iterator_adaptor_base(
  4649. Components.begin()),
  4650. DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
  4651. SupportsMapper(SupportsMapper),
  4652. ListSizeCur(CumulativeListSizes.begin()),
  4653. ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
  4654. assert(UniqueDecls.size() == DeclsListNum.size() &&
  4655. "Inconsistent number of declarations and list sizes!");
  4656. if (!DeclsListNum.empty())
  4657. RemainingLists = *NumListsCur;
  4658. if (SupportsMapper)
  4659. MapperCur = Mappers.begin();
  4660. }
  4661. /// Construct an iterator that scan lists for a given declaration \a
  4662. /// Declaration.
  4663. explicit const_component_lists_iterator(
  4664. const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
  4665. ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
  4666. MappableExprComponentListRef Components, bool SupportsMapper,
  4667. ArrayRef<Expr *> Mappers)
  4668. : const_component_lists_iterator(UniqueDecls, DeclsListNum,
  4669. CumulativeListSizes, Components,
  4670. SupportsMapper, Mappers) {
  4671. // Look for the desired declaration. While we are looking for it, we
  4672. // update the state so that we know the component where a given list
  4673. // starts.
  4674. for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
  4675. if (*DeclCur == Declaration)
  4676. break;
  4677. assert(*NumListsCur > 0 && "No lists associated with declaration??");
  4678. // Skip the lists associated with the current declaration, but save the
  4679. // last list size that was skipped.
  4680. std::advance(ListSizeCur, *NumListsCur - 1);
  4681. PrevListSize = *ListSizeCur;
  4682. ++ListSizeCur;
  4683. if (SupportsMapper)
  4684. ++MapperCur;
  4685. }
  4686. // If we didn't find any declaration, advance the iterator to after the
  4687. // last component and set remaining lists to zero.
  4688. if (ListSizeCur == CumulativeListSizes.end()) {
  4689. this->I = End;
  4690. RemainingLists = 0u;
  4691. return;
  4692. }
  4693. // Set the remaining lists with the total number of lists of the current
  4694. // declaration.
  4695. RemainingLists = *NumListsCur;
  4696. // Adjust the list size end iterator to the end of the relevant range.
  4697. ListSizeEnd = ListSizeCur;
  4698. std::advance(ListSizeEnd, RemainingLists);
  4699. // Given that the list sizes are cumulative, the index of the component
  4700. // that start the list is the size of the previous list.
  4701. std::advance(this->I, PrevListSize);
  4702. }
  4703. // Return the array with the current list. The sizes are cumulative, so the
  4704. // array size is the difference between the current size and previous one.
  4705. std::tuple<const ValueDecl *, MappableExprComponentListRef,
  4706. const ValueDecl *>
  4707. operator*() const {
  4708. assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
  4709. const ValueDecl *Mapper = nullptr;
  4710. if (SupportsMapper && *MapperCur)
  4711. Mapper = cast<ValueDecl>(cast<DeclRefExpr>(*MapperCur)->getDecl());
  4712. return std::make_tuple(
  4713. *DeclCur,
  4714. MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize),
  4715. Mapper);
  4716. }
  4717. std::tuple<const ValueDecl *, MappableExprComponentListRef,
  4718. const ValueDecl *>
  4719. operator->() const {
  4720. return **this;
  4721. }
  4722. // Skip the components of the current list.
  4723. const_component_lists_iterator &operator++() {
  4724. assert(ListSizeCur != ListSizeEnd && RemainingLists &&
  4725. "Invalid iterator!");
  4726. // If we don't have more lists just skip all the components. Otherwise,
  4727. // advance the iterator by the number of components in the current list.
  4728. if (std::next(ListSizeCur) == ListSizeEnd) {
  4729. this->I = End;
  4730. RemainingLists = 0;
  4731. } else {
  4732. std::advance(this->I, *ListSizeCur - PrevListSize);
  4733. PrevListSize = *ListSizeCur;
  4734. // We are done with a declaration, move to the next one.
  4735. if (!(--RemainingLists)) {
  4736. ++DeclCur;
  4737. ++NumListsCur;
  4738. RemainingLists = *NumListsCur;
  4739. assert(RemainingLists && "No lists in the following declaration??");
  4740. }
  4741. }
  4742. ++ListSizeCur;
  4743. if (SupportsMapper)
  4744. ++MapperCur;
  4745. return *this;
  4746. }
  4747. };
  4748. using const_component_lists_range =
  4749. llvm::iterator_range<const_component_lists_iterator>;
  4750. /// Iterators for all component lists.
  4751. const_component_lists_iterator component_lists_begin() const {
  4752. return const_component_lists_iterator(
  4753. getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
  4754. getComponentsRef(), SupportsMapper,
  4755. SupportsMapper ? getUDMapperRefs() : std::nullopt);
  4756. }
  4757. const_component_lists_iterator component_lists_end() const {
  4758. return const_component_lists_iterator(
  4759. ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
  4760. MappableExprComponentListRef(getComponentsRef().end(),
  4761. getComponentsRef().end()),
  4762. SupportsMapper, std::nullopt);
  4763. }
  4764. const_component_lists_range component_lists() const {
  4765. return {component_lists_begin(), component_lists_end()};
  4766. }
  4767. /// Iterators for component lists associated with the provided
  4768. /// declaration.
  4769. const_component_lists_iterator
  4770. decl_component_lists_begin(const ValueDecl *VD) const {
  4771. return const_component_lists_iterator(
  4772. VD, getUniqueDeclsRef(), getDeclNumListsRef(),
  4773. getComponentListSizesRef(), getComponentsRef(), SupportsMapper,
  4774. SupportsMapper ? getUDMapperRefs() : std::nullopt);
  4775. }
  4776. const_component_lists_iterator decl_component_lists_end() const {
  4777. return component_lists_end();
  4778. }
  4779. const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
  4780. return {decl_component_lists_begin(VD), decl_component_lists_end()};
  4781. }
  4782. /// Iterators to access all the declarations, number of lists, list sizes, and
  4783. /// components.
  4784. using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
  4785. using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
  4786. const_all_decls_range all_decls() const {
  4787. auto A = getUniqueDeclsRef();
  4788. return const_all_decls_range(A.begin(), A.end());
  4789. }
  4790. using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
  4791. using const_all_num_lists_range =
  4792. llvm::iterator_range<const_all_num_lists_iterator>;
  4793. const_all_num_lists_range all_num_lists() const {
  4794. auto A = getDeclNumListsRef();
  4795. return const_all_num_lists_range(A.begin(), A.end());
  4796. }
  4797. using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
  4798. using const_all_lists_sizes_range =
  4799. llvm::iterator_range<const_all_lists_sizes_iterator>;
  4800. const_all_lists_sizes_range all_lists_sizes() const {
  4801. auto A = getComponentListSizesRef();
  4802. return const_all_lists_sizes_range(A.begin(), A.end());
  4803. }
  4804. using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
  4805. using const_all_components_range =
  4806. llvm::iterator_range<const_all_components_iterator>;
  4807. const_all_components_range all_components() const {
  4808. auto A = getComponentsRef();
  4809. return const_all_components_range(A.begin(), A.end());
  4810. }
  4811. using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
  4812. using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator;
  4813. using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
  4814. using mapperlist_const_range =
  4815. llvm::iterator_range<mapperlist_const_iterator>;
  4816. mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); }
  4817. mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); }
  4818. mapperlist_const_iterator mapperlist_begin() const {
  4819. return getUDMapperRefs().begin();
  4820. }
  4821. mapperlist_const_iterator mapperlist_end() const {
  4822. return getUDMapperRefs().end();
  4823. }
  4824. mapperlist_range mapperlists() {
  4825. return mapperlist_range(mapperlist_begin(), mapperlist_end());
  4826. }
  4827. mapperlist_const_range mapperlists() const {
  4828. return mapperlist_const_range(mapperlist_begin(), mapperlist_end());
  4829. }
  4830. };
  4831. /// This represents clause 'map' in the '#pragma omp ...'
  4832. /// directives.
  4833. ///
  4834. /// \code
  4835. /// #pragma omp target map(a,b)
  4836. /// \endcode
  4837. /// In this example directive '#pragma omp target' has clause 'map'
  4838. /// with the variables 'a' and 'b'.
  4839. class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
  4840. private llvm::TrailingObjects<
  4841. OMPMapClause, Expr *, ValueDecl *, unsigned,
  4842. OMPClauseMappableExprCommon::MappableComponent> {
  4843. friend class OMPClauseReader;
  4844. friend OMPMappableExprListClause;
  4845. friend OMPVarListClause;
  4846. friend TrailingObjects;
  4847. /// Define the sizes of each trailing object array except the last one. This
  4848. /// is required for TrailingObjects to work properly.
  4849. size_t numTrailingObjects(OverloadToken<Expr *>) const {
  4850. // There are varlist_size() of expressions, and varlist_size() of
  4851. // user-defined mappers.
  4852. return 2 * varlist_size() + 1;
  4853. }
  4854. size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
  4855. return getUniqueDeclarationsNum();
  4856. }
  4857. size_t numTrailingObjects(OverloadToken<unsigned>) const {
  4858. return getUniqueDeclarationsNum() + getTotalComponentListNum();
  4859. }
  4860. private:
  4861. /// Map-type-modifiers for the 'map' clause.
  4862. OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
  4863. OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
  4864. OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
  4865. OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown};
  4866. /// Location of map-type-modifiers for the 'map' clause.
  4867. SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];
  4868. /// Map type for the 'map' clause.
  4869. OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
  4870. /// Is this an implicit map type or not.
  4871. bool MapTypeIsImplicit = false;
  4872. /// Location of the map type.
  4873. SourceLocation MapLoc;
  4874. /// Colon location.
  4875. SourceLocation ColonLoc;
  4876. /// Build a clause for \a NumVars listed expressions, \a
  4877. /// NumUniqueDeclarations declarations, \a NumComponentLists total component
  4878. /// lists, and \a NumComponents total expression components.
  4879. ///
  4880. /// \param MapModifiers Map-type-modifiers.
  4881. /// \param MapModifiersLoc Locations of map-type-modifiers.
  4882. /// \param MapperQualifierLoc C++ nested name specifier for the associated
  4883. /// user-defined mapper.
  4884. /// \param MapperIdInfo The identifier of associated user-defined mapper.
  4885. /// \param MapType Map type.
  4886. /// \param MapTypeIsImplicit Map type is inferred implicitly.
  4887. /// \param MapLoc Location of the map type.
  4888. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  4889. /// StartLoc: starting location of the clause (the clause keyword); 2)
  4890. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  4891. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  4892. /// NumVars: number of expressions listed in this clause; 2)
  4893. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  4894. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  4895. /// NumComponents: total number of expression components in the clause.
  4896. explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
  4897. ArrayRef<SourceLocation> MapModifiersLoc,
  4898. NestedNameSpecifierLoc MapperQualifierLoc,
  4899. DeclarationNameInfo MapperIdInfo,
  4900. OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
  4901. SourceLocation MapLoc, const OMPVarListLocTy &Locs,
  4902. const OMPMappableExprListSizeTy &Sizes)
  4903. : OMPMappableExprListClause(llvm::omp::OMPC_map, Locs, Sizes,
  4904. /*SupportsMapper=*/true, &MapperQualifierLoc,
  4905. &MapperIdInfo),
  4906. MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
  4907. assert(std::size(MapTypeModifiers) == MapModifiers.size() &&
  4908. "Unexpected number of map type modifiers.");
  4909. llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
  4910. assert(std::size(MapTypeModifiersLoc) == MapModifiersLoc.size() &&
  4911. "Unexpected number of map type modifier locations.");
  4912. llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
  4913. }
  4914. /// Build an empty clause.
  4915. ///
  4916. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  4917. /// NumVars: number of expressions listed in this clause; 2)
  4918. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  4919. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  4920. /// NumComponents: total number of expression components in the clause.
  4921. explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
  4922. : OMPMappableExprListClause(llvm::omp::OMPC_map, OMPVarListLocTy(), Sizes,
  4923. /*SupportsMapper=*/true) {}
  4924. /// Set map-type-modifier for the clause.
  4925. ///
  4926. /// \param I index for map-type-modifier.
  4927. /// \param T map-type-modifier for the clause.
  4928. void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
  4929. assert(I < NumberOfOMPMapClauseModifiers &&
  4930. "Unexpected index to store map type modifier, exceeds array size.");
  4931. MapTypeModifiers[I] = T;
  4932. }
  4933. /// Set location for the map-type-modifier.
  4934. ///
  4935. /// \param I index for map-type-modifier location.
  4936. /// \param TLoc map-type-modifier location.
  4937. void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
  4938. assert(I < NumberOfOMPMapClauseModifiers &&
  4939. "Index to store map type modifier location exceeds array size.");
  4940. MapTypeModifiersLoc[I] = TLoc;
  4941. }
  4942. /// Set type for the clause.
  4943. ///
  4944. /// \param T Type for the clause.
  4945. void setMapType(OpenMPMapClauseKind T) { MapType = T; }
  4946. /// Set type location.
  4947. ///
  4948. /// \param TLoc Type location.
  4949. void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
  4950. /// Set colon location.
  4951. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  4952. /// Set iterator modifier.
  4953. void setIteratorModifier(Expr *IteratorModifier) {
  4954. getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
  4955. }
  4956. public:
  4957. /// Creates clause with a list of variables \a VL.
  4958. ///
  4959. /// \param C AST context.
  4960. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  4961. /// StartLoc: starting location of the clause (the clause keyword); 2)
  4962. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  4963. /// \param Vars The original expression used in the clause.
  4964. /// \param Declarations Declarations used in the clause.
  4965. /// \param ComponentLists Component lists used in the clause.
  4966. /// \param UDMapperRefs References to user-defined mappers associated with
  4967. /// expressions used in the clause.
  4968. /// \param IteratorModifier Iterator modifier.
  4969. /// \param MapModifiers Map-type-modifiers.
  4970. /// \param MapModifiersLoc Location of map-type-modifiers.
  4971. /// \param UDMQualifierLoc C++ nested name specifier for the associated
  4972. /// user-defined mapper.
  4973. /// \param MapperId The identifier of associated user-defined mapper.
  4974. /// \param Type Map type.
  4975. /// \param TypeIsImplicit Map type is inferred implicitly.
  4976. /// \param TypeLoc Location of the map type.
  4977. static OMPMapClause *
  4978. Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  4979. ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
  4980. MappableExprComponentListsRef ComponentLists,
  4981. ArrayRef<Expr *> UDMapperRefs, Expr *IteratorModifier,
  4982. ArrayRef<OpenMPMapModifierKind> MapModifiers,
  4983. ArrayRef<SourceLocation> MapModifiersLoc,
  4984. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
  4985. OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
  4986. /// Creates an empty clause with the place for \a NumVars original
  4987. /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
  4988. /// lists, and \a NumComponents expression components.
  4989. ///
  4990. /// \param C AST context.
  4991. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  4992. /// NumVars: number of expressions listed in this clause; 2)
  4993. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  4994. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  4995. /// NumComponents: total number of expression components in the clause.
  4996. static OMPMapClause *CreateEmpty(const ASTContext &C,
  4997. const OMPMappableExprListSizeTy &Sizes);
  4998. /// Fetches Expr * of iterator modifier.
  4999. Expr *getIteratorModifier() {
  5000. return getTrailingObjects<Expr *>()[2 * varlist_size()];
  5001. }
  5002. /// Fetches mapping kind for the clause.
  5003. OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
  5004. /// Is this an implicit map type?
  5005. /// We have to capture 'IsMapTypeImplicit' from the parser for more
  5006. /// informative error messages. It helps distinguish map(r) from
  5007. /// map(tofrom: r), which is important to print more helpful error
  5008. /// messages for some target directives.
  5009. bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
  5010. /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
  5011. ///
  5012. /// \param Cnt index for map-type-modifier.
  5013. OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
  5014. assert(Cnt < NumberOfOMPMapClauseModifiers &&
  5015. "Requested modifier exceeds the total number of modifiers.");
  5016. return MapTypeModifiers[Cnt];
  5017. }
  5018. /// Fetches the map-type-modifier location at 'Cnt' index of array of
  5019. /// modifiers' locations.
  5020. ///
  5021. /// \param Cnt index for map-type-modifier location.
  5022. SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
  5023. assert(Cnt < NumberOfOMPMapClauseModifiers &&
  5024. "Requested modifier location exceeds total number of modifiers.");
  5025. return MapTypeModifiersLoc[Cnt];
  5026. }
  5027. /// Fetches ArrayRef of map-type-modifiers.
  5028. ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY {
  5029. return llvm::ArrayRef(MapTypeModifiers);
  5030. }
  5031. /// Fetches ArrayRef of location of map-type-modifiers.
  5032. ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY {
  5033. return llvm::ArrayRef(MapTypeModifiersLoc);
  5034. }
  5035. /// Fetches location of clause mapping kind.
  5036. SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
  5037. /// Get colon location.
  5038. SourceLocation getColonLoc() const { return ColonLoc; }
  5039. child_range children() {
  5040. return child_range(
  5041. reinterpret_cast<Stmt **>(varlist_begin()),
  5042. reinterpret_cast<Stmt **>(varlist_end()));
  5043. }
  5044. const_child_range children() const {
  5045. auto Children = const_cast<OMPMapClause *>(this)->children();
  5046. return const_child_range(Children.begin(), Children.end());
  5047. }
  5048. child_range used_children() {
  5049. if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom)
  5050. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  5051. reinterpret_cast<Stmt **>(varlist_end()));
  5052. return child_range(child_iterator(), child_iterator());
  5053. }
  5054. const_child_range used_children() const {
  5055. auto Children = const_cast<OMPMapClause *>(this)->used_children();
  5056. return const_child_range(Children.begin(), Children.end());
  5057. }
  5058. static bool classof(const OMPClause *T) {
  5059. return T->getClauseKind() == llvm::omp::OMPC_map;
  5060. }
  5061. };
  5062. /// This represents 'num_teams' clause in the '#pragma omp ...'
  5063. /// directive.
  5064. ///
  5065. /// \code
  5066. /// #pragma omp teams num_teams(n)
  5067. /// \endcode
  5068. /// In this example directive '#pragma omp teams' has clause 'num_teams'
  5069. /// with single expression 'n'.
  5070. class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
  5071. friend class OMPClauseReader;
  5072. /// Location of '('.
  5073. SourceLocation LParenLoc;
  5074. /// NumTeams number.
  5075. Stmt *NumTeams = nullptr;
  5076. /// Set the NumTeams number.
  5077. ///
  5078. /// \param E NumTeams number.
  5079. void setNumTeams(Expr *E) { NumTeams = E; }
  5080. public:
  5081. /// Build 'num_teams' clause.
  5082. ///
  5083. /// \param E Expression associated with this clause.
  5084. /// \param HelperE Helper Expression associated with this clause.
  5085. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  5086. /// clause must be captured.
  5087. /// \param StartLoc Starting location of the clause.
  5088. /// \param LParenLoc Location of '('.
  5089. /// \param EndLoc Ending location of the clause.
  5090. OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
  5091. SourceLocation StartLoc, SourceLocation LParenLoc,
  5092. SourceLocation EndLoc)
  5093. : OMPClause(llvm::omp::OMPC_num_teams, StartLoc, EndLoc),
  5094. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), NumTeams(E) {
  5095. setPreInitStmt(HelperE, CaptureRegion);
  5096. }
  5097. /// Build an empty clause.
  5098. OMPNumTeamsClause()
  5099. : OMPClause(llvm::omp::OMPC_num_teams, SourceLocation(),
  5100. SourceLocation()),
  5101. OMPClauseWithPreInit(this) {}
  5102. /// Sets the location of '('.
  5103. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5104. /// Returns the location of '('.
  5105. SourceLocation getLParenLoc() const { return LParenLoc; }
  5106. /// Return NumTeams number.
  5107. Expr *getNumTeams() { return cast<Expr>(NumTeams); }
  5108. /// Return NumTeams number.
  5109. Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
  5110. child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
  5111. const_child_range children() const {
  5112. return const_child_range(&NumTeams, &NumTeams + 1);
  5113. }
  5114. child_range used_children() {
  5115. return child_range(child_iterator(), child_iterator());
  5116. }
  5117. const_child_range used_children() const {
  5118. return const_child_range(const_child_iterator(), const_child_iterator());
  5119. }
  5120. static bool classof(const OMPClause *T) {
  5121. return T->getClauseKind() == llvm::omp::OMPC_num_teams;
  5122. }
  5123. };
  5124. /// This represents 'thread_limit' clause in the '#pragma omp ...'
  5125. /// directive.
  5126. ///
  5127. /// \code
  5128. /// #pragma omp teams thread_limit(n)
  5129. /// \endcode
  5130. /// In this example directive '#pragma omp teams' has clause 'thread_limit'
  5131. /// with single expression 'n'.
  5132. class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
  5133. friend class OMPClauseReader;
  5134. /// Location of '('.
  5135. SourceLocation LParenLoc;
  5136. /// ThreadLimit number.
  5137. Stmt *ThreadLimit = nullptr;
  5138. /// Set the ThreadLimit number.
  5139. ///
  5140. /// \param E ThreadLimit number.
  5141. void setThreadLimit(Expr *E) { ThreadLimit = E; }
  5142. public:
  5143. /// Build 'thread_limit' clause.
  5144. ///
  5145. /// \param E Expression associated with this clause.
  5146. /// \param HelperE Helper Expression associated with this clause.
  5147. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  5148. /// clause must be captured.
  5149. /// \param StartLoc Starting location of the clause.
  5150. /// \param LParenLoc Location of '('.
  5151. /// \param EndLoc Ending location of the clause.
  5152. OMPThreadLimitClause(Expr *E, Stmt *HelperE,
  5153. OpenMPDirectiveKind CaptureRegion,
  5154. SourceLocation StartLoc, SourceLocation LParenLoc,
  5155. SourceLocation EndLoc)
  5156. : OMPClause(llvm::omp::OMPC_thread_limit, StartLoc, EndLoc),
  5157. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
  5158. setPreInitStmt(HelperE, CaptureRegion);
  5159. }
  5160. /// Build an empty clause.
  5161. OMPThreadLimitClause()
  5162. : OMPClause(llvm::omp::OMPC_thread_limit, SourceLocation(),
  5163. SourceLocation()),
  5164. OMPClauseWithPreInit(this) {}
  5165. /// Sets the location of '('.
  5166. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5167. /// Returns the location of '('.
  5168. SourceLocation getLParenLoc() const { return LParenLoc; }
  5169. /// Return ThreadLimit number.
  5170. Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
  5171. /// Return ThreadLimit number.
  5172. Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
  5173. child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
  5174. const_child_range children() const {
  5175. return const_child_range(&ThreadLimit, &ThreadLimit + 1);
  5176. }
  5177. child_range used_children() {
  5178. return child_range(child_iterator(), child_iterator());
  5179. }
  5180. const_child_range used_children() const {
  5181. return const_child_range(const_child_iterator(), const_child_iterator());
  5182. }
  5183. static bool classof(const OMPClause *T) {
  5184. return T->getClauseKind() == llvm::omp::OMPC_thread_limit;
  5185. }
  5186. };
  5187. /// This represents 'priority' clause in the '#pragma omp ...'
  5188. /// directive.
  5189. ///
  5190. /// \code
  5191. /// #pragma omp task priority(n)
  5192. /// \endcode
  5193. /// In this example directive '#pragma omp teams' has clause 'priority' with
  5194. /// single expression 'n'.
  5195. class OMPPriorityClause : public OMPClause, public OMPClauseWithPreInit {
  5196. friend class OMPClauseReader;
  5197. /// Location of '('.
  5198. SourceLocation LParenLoc;
  5199. /// Priority number.
  5200. Stmt *Priority = nullptr;
  5201. /// Set the Priority number.
  5202. ///
  5203. /// \param E Priority number.
  5204. void setPriority(Expr *E) { Priority = E; }
  5205. public:
  5206. /// Build 'priority' clause.
  5207. ///
  5208. /// \param Priority Expression associated with this clause.
  5209. /// \param HelperPriority Helper priority for the construct.
  5210. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  5211. /// clause must be captured.
  5212. /// \param StartLoc Starting location of the clause.
  5213. /// \param LParenLoc Location of '('.
  5214. /// \param EndLoc Ending location of the clause.
  5215. OMPPriorityClause(Expr *Priority, Stmt *HelperPriority,
  5216. OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
  5217. SourceLocation LParenLoc, SourceLocation EndLoc)
  5218. : OMPClause(llvm::omp::OMPC_priority, StartLoc, EndLoc),
  5219. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Priority(Priority) {
  5220. setPreInitStmt(HelperPriority, CaptureRegion);
  5221. }
  5222. /// Build an empty clause.
  5223. OMPPriorityClause()
  5224. : OMPClause(llvm::omp::OMPC_priority, SourceLocation(), SourceLocation()),
  5225. OMPClauseWithPreInit(this) {}
  5226. /// Sets the location of '('.
  5227. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5228. /// Returns the location of '('.
  5229. SourceLocation getLParenLoc() const { return LParenLoc; }
  5230. /// Return Priority number.
  5231. Expr *getPriority() { return cast<Expr>(Priority); }
  5232. /// Return Priority number.
  5233. Expr *getPriority() const { return cast<Expr>(Priority); }
  5234. child_range children() { return child_range(&Priority, &Priority + 1); }
  5235. const_child_range children() const {
  5236. return const_child_range(&Priority, &Priority + 1);
  5237. }
  5238. child_range used_children();
  5239. const_child_range used_children() const {
  5240. auto Children = const_cast<OMPPriorityClause *>(this)->used_children();
  5241. return const_child_range(Children.begin(), Children.end());
  5242. }
  5243. static bool classof(const OMPClause *T) {
  5244. return T->getClauseKind() == llvm::omp::OMPC_priority;
  5245. }
  5246. };
  5247. /// This represents 'grainsize' clause in the '#pragma omp ...'
  5248. /// directive.
  5249. ///
  5250. /// \code
  5251. /// #pragma omp taskloop grainsize(4)
  5252. /// \endcode
  5253. /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
  5254. /// with single expression '4'.
  5255. class OMPGrainsizeClause : public OMPClause, public OMPClauseWithPreInit {
  5256. friend class OMPClauseReader;
  5257. /// Location of '('.
  5258. SourceLocation LParenLoc;
  5259. /// Modifiers for 'grainsize' clause.
  5260. OpenMPGrainsizeClauseModifier Modifier = OMPC_GRAINSIZE_unknown;
  5261. /// Location of the modifier.
  5262. SourceLocation ModifierLoc;
  5263. /// Safe iteration space distance.
  5264. Stmt *Grainsize = nullptr;
  5265. /// Set safelen.
  5266. void setGrainsize(Expr *Size) { Grainsize = Size; }
  5267. /// Sets modifier.
  5268. void setModifier(OpenMPGrainsizeClauseModifier M) { Modifier = M; }
  5269. /// Sets modifier location.
  5270. void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
  5271. public:
  5272. /// Build 'grainsize' clause.
  5273. ///
  5274. /// \param Modifier Clause modifier.
  5275. /// \param Size Expression associated with this clause.
  5276. /// \param HelperSize Helper grainsize for the construct.
  5277. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  5278. /// clause must be captured.
  5279. /// \param StartLoc Starting location of the clause.
  5280. /// \param ModifierLoc Modifier location.
  5281. /// \param LParenLoc Location of '('.
  5282. /// \param EndLoc Ending location of the clause.
  5283. OMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size,
  5284. Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
  5285. SourceLocation StartLoc, SourceLocation LParenLoc,
  5286. SourceLocation ModifierLoc, SourceLocation EndLoc)
  5287. : OMPClause(llvm::omp::OMPC_grainsize, StartLoc, EndLoc),
  5288. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
  5289. ModifierLoc(ModifierLoc), Grainsize(Size) {
  5290. setPreInitStmt(HelperSize, CaptureRegion);
  5291. }
  5292. /// Build an empty clause.
  5293. explicit OMPGrainsizeClause()
  5294. : OMPClause(llvm::omp::OMPC_grainsize, SourceLocation(),
  5295. SourceLocation()),
  5296. OMPClauseWithPreInit(this) {}
  5297. /// Sets the location of '('.
  5298. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5299. /// Returns the location of '('.
  5300. SourceLocation getLParenLoc() const { return LParenLoc; }
  5301. /// Return safe iteration space distance.
  5302. Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
  5303. /// Gets modifier.
  5304. OpenMPGrainsizeClauseModifier getModifier() const { return Modifier; }
  5305. /// Gets modifier location.
  5306. SourceLocation getModifierLoc() const { return ModifierLoc; }
  5307. child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
  5308. const_child_range children() const {
  5309. return const_child_range(&Grainsize, &Grainsize + 1);
  5310. }
  5311. child_range used_children();
  5312. const_child_range used_children() const {
  5313. auto Children = const_cast<OMPGrainsizeClause *>(this)->used_children();
  5314. return const_child_range(Children.begin(), Children.end());
  5315. }
  5316. static bool classof(const OMPClause *T) {
  5317. return T->getClauseKind() == llvm::omp::OMPC_grainsize;
  5318. }
  5319. };
  5320. /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
  5321. ///
  5322. /// \code
  5323. /// #pragma omp taskloop nogroup
  5324. /// \endcode
  5325. /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
  5326. class OMPNogroupClause : public OMPClause {
  5327. public:
  5328. /// Build 'nogroup' clause.
  5329. ///
  5330. /// \param StartLoc Starting location of the clause.
  5331. /// \param EndLoc Ending location of the clause.
  5332. OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
  5333. : OMPClause(llvm::omp::OMPC_nogroup, StartLoc, EndLoc) {}
  5334. /// Build an empty clause.
  5335. OMPNogroupClause()
  5336. : OMPClause(llvm::omp::OMPC_nogroup, SourceLocation(), SourceLocation()) {
  5337. }
  5338. child_range children() {
  5339. return child_range(child_iterator(), child_iterator());
  5340. }
  5341. const_child_range children() const {
  5342. return const_child_range(const_child_iterator(), const_child_iterator());
  5343. }
  5344. child_range used_children() {
  5345. return child_range(child_iterator(), child_iterator());
  5346. }
  5347. const_child_range used_children() const {
  5348. return const_child_range(const_child_iterator(), const_child_iterator());
  5349. }
  5350. static bool classof(const OMPClause *T) {
  5351. return T->getClauseKind() == llvm::omp::OMPC_nogroup;
  5352. }
  5353. };
  5354. /// This represents 'num_tasks' clause in the '#pragma omp ...'
  5355. /// directive.
  5356. ///
  5357. /// \code
  5358. /// #pragma omp taskloop num_tasks(4)
  5359. /// \endcode
  5360. /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
  5361. /// with single expression '4'.
  5362. class OMPNumTasksClause : public OMPClause, public OMPClauseWithPreInit {
  5363. friend class OMPClauseReader;
  5364. /// Location of '('.
  5365. SourceLocation LParenLoc;
  5366. /// Modifiers for 'num_tasks' clause.
  5367. OpenMPNumTasksClauseModifier Modifier = OMPC_NUMTASKS_unknown;
  5368. /// Location of the modifier.
  5369. SourceLocation ModifierLoc;
  5370. /// Safe iteration space distance.
  5371. Stmt *NumTasks = nullptr;
  5372. /// Set safelen.
  5373. void setNumTasks(Expr *Size) { NumTasks = Size; }
  5374. /// Sets modifier.
  5375. void setModifier(OpenMPNumTasksClauseModifier M) { Modifier = M; }
  5376. /// Sets modifier location.
  5377. void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
  5378. public:
  5379. /// Build 'num_tasks' clause.
  5380. ///
  5381. /// \param Modifier Clause modifier.
  5382. /// \param Size Expression associated with this clause.
  5383. /// \param HelperSize Helper grainsize for the construct.
  5384. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  5385. /// clause must be captured.
  5386. /// \param StartLoc Starting location of the clause.
  5387. /// \param EndLoc Ending location of the clause.
  5388. /// \param ModifierLoc Modifier location.
  5389. /// \param LParenLoc Location of '('.
  5390. OMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *Size,
  5391. Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
  5392. SourceLocation StartLoc, SourceLocation LParenLoc,
  5393. SourceLocation ModifierLoc, SourceLocation EndLoc)
  5394. : OMPClause(llvm::omp::OMPC_num_tasks, StartLoc, EndLoc),
  5395. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
  5396. ModifierLoc(ModifierLoc), NumTasks(Size) {
  5397. setPreInitStmt(HelperSize, CaptureRegion);
  5398. }
  5399. /// Build an empty clause.
  5400. explicit OMPNumTasksClause()
  5401. : OMPClause(llvm::omp::OMPC_num_tasks, SourceLocation(),
  5402. SourceLocation()),
  5403. OMPClauseWithPreInit(this) {}
  5404. /// Sets the location of '('.
  5405. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5406. /// Returns the location of '('.
  5407. SourceLocation getLParenLoc() const { return LParenLoc; }
  5408. /// Return safe iteration space distance.
  5409. Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
  5410. /// Gets modifier.
  5411. OpenMPNumTasksClauseModifier getModifier() const { return Modifier; }
  5412. /// Gets modifier location.
  5413. SourceLocation getModifierLoc() const { return ModifierLoc; }
  5414. child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
  5415. const_child_range children() const {
  5416. return const_child_range(&NumTasks, &NumTasks + 1);
  5417. }
  5418. child_range used_children();
  5419. const_child_range used_children() const {
  5420. auto Children = const_cast<OMPNumTasksClause *>(this)->used_children();
  5421. return const_child_range(Children.begin(), Children.end());
  5422. }
  5423. static bool classof(const OMPClause *T) {
  5424. return T->getClauseKind() == llvm::omp::OMPC_num_tasks;
  5425. }
  5426. };
  5427. /// This represents 'hint' clause in the '#pragma omp ...' directive.
  5428. ///
  5429. /// \code
  5430. /// #pragma omp critical (name) hint(6)
  5431. /// \endcode
  5432. /// In this example directive '#pragma omp critical' has name 'name' and clause
  5433. /// 'hint' with argument '6'.
  5434. class OMPHintClause : public OMPClause {
  5435. friend class OMPClauseReader;
  5436. /// Location of '('.
  5437. SourceLocation LParenLoc;
  5438. /// Hint expression of the 'hint' clause.
  5439. Stmt *Hint = nullptr;
  5440. /// Set hint expression.
  5441. void setHint(Expr *H) { Hint = H; }
  5442. public:
  5443. /// Build 'hint' clause with expression \a Hint.
  5444. ///
  5445. /// \param Hint Hint expression.
  5446. /// \param StartLoc Starting location of the clause.
  5447. /// \param LParenLoc Location of '('.
  5448. /// \param EndLoc Ending location of the clause.
  5449. OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
  5450. SourceLocation EndLoc)
  5451. : OMPClause(llvm::omp::OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
  5452. Hint(Hint) {}
  5453. /// Build an empty clause.
  5454. OMPHintClause()
  5455. : OMPClause(llvm::omp::OMPC_hint, SourceLocation(), SourceLocation()) {}
  5456. /// Sets the location of '('.
  5457. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5458. /// Returns the location of '('.
  5459. SourceLocation getLParenLoc() const { return LParenLoc; }
  5460. /// Returns number of threads.
  5461. Expr *getHint() const { return cast_or_null<Expr>(Hint); }
  5462. child_range children() { return child_range(&Hint, &Hint + 1); }
  5463. const_child_range children() const {
  5464. return const_child_range(&Hint, &Hint + 1);
  5465. }
  5466. child_range used_children() {
  5467. return child_range(child_iterator(), child_iterator());
  5468. }
  5469. const_child_range used_children() const {
  5470. return const_child_range(const_child_iterator(), const_child_iterator());
  5471. }
  5472. static bool classof(const OMPClause *T) {
  5473. return T->getClauseKind() == llvm::omp::OMPC_hint;
  5474. }
  5475. };
  5476. /// This represents 'dist_schedule' clause in the '#pragma omp ...'
  5477. /// directive.
  5478. ///
  5479. /// \code
  5480. /// #pragma omp distribute dist_schedule(static, 3)
  5481. /// \endcode
  5482. /// In this example directive '#pragma omp distribute' has 'dist_schedule'
  5483. /// clause with arguments 'static' and '3'.
  5484. class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
  5485. friend class OMPClauseReader;
  5486. /// Location of '('.
  5487. SourceLocation LParenLoc;
  5488. /// A kind of the 'schedule' clause.
  5489. OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
  5490. /// Start location of the schedule kind in source code.
  5491. SourceLocation KindLoc;
  5492. /// Location of ',' (if any).
  5493. SourceLocation CommaLoc;
  5494. /// Chunk size.
  5495. Expr *ChunkSize = nullptr;
  5496. /// Set schedule kind.
  5497. ///
  5498. /// \param K Schedule kind.
  5499. void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
  5500. /// Sets the location of '('.
  5501. ///
  5502. /// \param Loc Location of '('.
  5503. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5504. /// Set schedule kind start location.
  5505. ///
  5506. /// \param KLoc Schedule kind location.
  5507. void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
  5508. /// Set location of ','.
  5509. ///
  5510. /// \param Loc Location of ','.
  5511. void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
  5512. /// Set chunk size.
  5513. ///
  5514. /// \param E Chunk size.
  5515. void setChunkSize(Expr *E) { ChunkSize = E; }
  5516. public:
  5517. /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
  5518. /// size expression \a ChunkSize.
  5519. ///
  5520. /// \param StartLoc Starting location of the clause.
  5521. /// \param LParenLoc Location of '('.
  5522. /// \param KLoc Starting location of the argument.
  5523. /// \param CommaLoc Location of ','.
  5524. /// \param EndLoc Ending location of the clause.
  5525. /// \param Kind DistSchedule kind.
  5526. /// \param ChunkSize Chunk size.
  5527. /// \param HelperChunkSize Helper chunk size for combined directives.
  5528. OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  5529. SourceLocation KLoc, SourceLocation CommaLoc,
  5530. SourceLocation EndLoc,
  5531. OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
  5532. Stmt *HelperChunkSize)
  5533. : OMPClause(llvm::omp::OMPC_dist_schedule, StartLoc, EndLoc),
  5534. OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
  5535. KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
  5536. setPreInitStmt(HelperChunkSize);
  5537. }
  5538. /// Build an empty clause.
  5539. explicit OMPDistScheduleClause()
  5540. : OMPClause(llvm::omp::OMPC_dist_schedule, SourceLocation(),
  5541. SourceLocation()),
  5542. OMPClauseWithPreInit(this) {}
  5543. /// Get kind of the clause.
  5544. OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
  5545. /// Get location of '('.
  5546. SourceLocation getLParenLoc() { return LParenLoc; }
  5547. /// Get kind location.
  5548. SourceLocation getDistScheduleKindLoc() { return KindLoc; }
  5549. /// Get location of ','.
  5550. SourceLocation getCommaLoc() { return CommaLoc; }
  5551. /// Get chunk size.
  5552. Expr *getChunkSize() { return ChunkSize; }
  5553. /// Get chunk size.
  5554. const Expr *getChunkSize() const { return ChunkSize; }
  5555. child_range children() {
  5556. return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
  5557. reinterpret_cast<Stmt **>(&ChunkSize) + 1);
  5558. }
  5559. const_child_range children() const {
  5560. auto Children = const_cast<OMPDistScheduleClause *>(this)->children();
  5561. return const_child_range(Children.begin(), Children.end());
  5562. }
  5563. child_range used_children() {
  5564. return child_range(child_iterator(), child_iterator());
  5565. }
  5566. const_child_range used_children() const {
  5567. return const_child_range(const_child_iterator(), const_child_iterator());
  5568. }
  5569. static bool classof(const OMPClause *T) {
  5570. return T->getClauseKind() == llvm::omp::OMPC_dist_schedule;
  5571. }
  5572. };
  5573. /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
  5574. ///
  5575. /// \code
  5576. /// #pragma omp target defaultmap(tofrom: scalar)
  5577. /// \endcode
  5578. /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
  5579. /// 'scalar' with modifier 'tofrom'.
  5580. class OMPDefaultmapClause : public OMPClause {
  5581. friend class OMPClauseReader;
  5582. /// Location of '('.
  5583. SourceLocation LParenLoc;
  5584. /// Modifiers for 'defaultmap' clause.
  5585. OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
  5586. /// Locations of modifiers.
  5587. SourceLocation ModifierLoc;
  5588. /// A kind of the 'defaultmap' clause.
  5589. OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
  5590. /// Start location of the defaultmap kind in source code.
  5591. SourceLocation KindLoc;
  5592. /// Set defaultmap kind.
  5593. ///
  5594. /// \param K Defaultmap kind.
  5595. void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
  5596. /// Set the defaultmap modifier.
  5597. ///
  5598. /// \param M Defaultmap modifier.
  5599. void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
  5600. Modifier = M;
  5601. }
  5602. /// Set location of the defaultmap modifier.
  5603. void setDefaultmapModifierLoc(SourceLocation Loc) {
  5604. ModifierLoc = Loc;
  5605. }
  5606. /// Sets the location of '('.
  5607. ///
  5608. /// \param Loc Location of '('.
  5609. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  5610. /// Set defaultmap kind start location.
  5611. ///
  5612. /// \param KLoc Defaultmap kind location.
  5613. void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
  5614. public:
  5615. /// Build 'defaultmap' clause with defaultmap kind \a Kind
  5616. ///
  5617. /// \param StartLoc Starting location of the clause.
  5618. /// \param LParenLoc Location of '('.
  5619. /// \param KLoc Starting location of the argument.
  5620. /// \param EndLoc Ending location of the clause.
  5621. /// \param Kind Defaultmap kind.
  5622. /// \param M The modifier applied to 'defaultmap' clause.
  5623. /// \param MLoc Location of the modifier
  5624. OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  5625. SourceLocation MLoc, SourceLocation KLoc,
  5626. SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
  5627. OpenMPDefaultmapClauseModifier M)
  5628. : OMPClause(llvm::omp::OMPC_defaultmap, StartLoc, EndLoc),
  5629. LParenLoc(LParenLoc), Modifier(M), ModifierLoc(MLoc), Kind(Kind),
  5630. KindLoc(KLoc) {}
  5631. /// Build an empty clause.
  5632. explicit OMPDefaultmapClause()
  5633. : OMPClause(llvm::omp::OMPC_defaultmap, SourceLocation(),
  5634. SourceLocation()) {}
  5635. /// Get kind of the clause.
  5636. OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
  5637. /// Get the modifier of the clause.
  5638. OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
  5639. return Modifier;
  5640. }
  5641. /// Get location of '('.
  5642. SourceLocation getLParenLoc() { return LParenLoc; }
  5643. /// Get kind location.
  5644. SourceLocation getDefaultmapKindLoc() { return KindLoc; }
  5645. /// Get the modifier location.
  5646. SourceLocation getDefaultmapModifierLoc() const {
  5647. return ModifierLoc;
  5648. }
  5649. child_range children() {
  5650. return child_range(child_iterator(), child_iterator());
  5651. }
  5652. const_child_range children() const {
  5653. return const_child_range(const_child_iterator(), const_child_iterator());
  5654. }
  5655. child_range used_children() {
  5656. return child_range(child_iterator(), child_iterator());
  5657. }
  5658. const_child_range used_children() const {
  5659. return const_child_range(const_child_iterator(), const_child_iterator());
  5660. }
  5661. static bool classof(const OMPClause *T) {
  5662. return T->getClauseKind() == llvm::omp::OMPC_defaultmap;
  5663. }
  5664. };
  5665. /// This represents clause 'to' in the '#pragma omp ...'
  5666. /// directives.
  5667. ///
  5668. /// \code
  5669. /// #pragma omp target update to(a,b)
  5670. /// \endcode
  5671. /// In this example directive '#pragma omp target update' has clause 'to'
  5672. /// with the variables 'a' and 'b'.
  5673. class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
  5674. private llvm::TrailingObjects<
  5675. OMPToClause, Expr *, ValueDecl *, unsigned,
  5676. OMPClauseMappableExprCommon::MappableComponent> {
  5677. friend class OMPClauseReader;
  5678. friend OMPMappableExprListClause;
  5679. friend OMPVarListClause;
  5680. friend TrailingObjects;
  5681. /// Motion-modifiers for the 'to' clause.
  5682. OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
  5683. OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
  5684. /// Location of motion-modifiers for the 'to' clause.
  5685. SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
  5686. /// Colon location.
  5687. SourceLocation ColonLoc;
  5688. /// Build clause with number of variables \a NumVars.
  5689. ///
  5690. /// \param TheMotionModifiers Motion-modifiers.
  5691. /// \param TheMotionModifiersLoc Locations of motion-modifiers.
  5692. /// \param MapperQualifierLoc C++ nested name specifier for the associated
  5693. /// user-defined mapper.
  5694. /// \param MapperIdInfo The identifier of associated user-defined mapper.
  5695. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  5696. /// StartLoc: starting location of the clause (the clause keyword); 2)
  5697. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  5698. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  5699. /// NumVars: number of expressions listed in this clause; 2)
  5700. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  5701. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  5702. /// NumComponents: total number of expression components in the clause.
  5703. explicit OMPToClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
  5704. ArrayRef<SourceLocation> TheMotionModifiersLoc,
  5705. NestedNameSpecifierLoc MapperQualifierLoc,
  5706. DeclarationNameInfo MapperIdInfo,
  5707. const OMPVarListLocTy &Locs,
  5708. const OMPMappableExprListSizeTy &Sizes)
  5709. : OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes,
  5710. /*SupportsMapper=*/true, &MapperQualifierLoc,
  5711. &MapperIdInfo) {
  5712. assert(std::size(MotionModifiers) == TheMotionModifiers.size() &&
  5713. "Unexpected number of motion modifiers.");
  5714. llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
  5715. assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() &&
  5716. "Unexpected number of motion modifier locations.");
  5717. llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
  5718. }
  5719. /// Build an empty clause.
  5720. ///
  5721. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  5722. /// NumVars: number of expressions listed in this clause; 2)
  5723. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  5724. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  5725. /// NumComponents: total number of expression components in the clause.
  5726. explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes)
  5727. : OMPMappableExprListClause(llvm::omp::OMPC_to, OMPVarListLocTy(), Sizes,
  5728. /*SupportsMapper=*/true) {}
  5729. /// Set motion-modifier for the clause.
  5730. ///
  5731. /// \param I index for motion-modifier.
  5732. /// \param T motion-modifier for the clause.
  5733. void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
  5734. assert(I < NumberOfOMPMotionModifiers &&
  5735. "Unexpected index to store motion modifier, exceeds array size.");
  5736. MotionModifiers[I] = T;
  5737. }
  5738. /// Set location for the motion-modifier.
  5739. ///
  5740. /// \param I index for motion-modifier location.
  5741. /// \param TLoc motion-modifier location.
  5742. void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
  5743. assert(I < NumberOfOMPMotionModifiers &&
  5744. "Index to store motion modifier location exceeds array size.");
  5745. MotionModifiersLoc[I] = TLoc;
  5746. }
  5747. /// Set colon location.
  5748. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  5749. /// Define the sizes of each trailing object array except the last one. This
  5750. /// is required for TrailingObjects to work properly.
  5751. size_t numTrailingObjects(OverloadToken<Expr *>) const {
  5752. // There are varlist_size() of expressions, and varlist_size() of
  5753. // user-defined mappers.
  5754. return 2 * varlist_size();
  5755. }
  5756. size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
  5757. return getUniqueDeclarationsNum();
  5758. }
  5759. size_t numTrailingObjects(OverloadToken<unsigned>) const {
  5760. return getUniqueDeclarationsNum() + getTotalComponentListNum();
  5761. }
  5762. public:
  5763. /// Creates clause with a list of variables \a Vars.
  5764. ///
  5765. /// \param C AST context.
  5766. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  5767. /// StartLoc: starting location of the clause (the clause keyword); 2)
  5768. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  5769. /// \param Vars The original expression used in the clause.
  5770. /// \param Declarations Declarations used in the clause.
  5771. /// \param ComponentLists Component lists used in the clause.
  5772. /// \param MotionModifiers Motion-modifiers.
  5773. /// \param MotionModifiersLoc Location of motion-modifiers.
  5774. /// \param UDMapperRefs References to user-defined mappers associated with
  5775. /// expressions used in the clause.
  5776. /// \param UDMQualifierLoc C++ nested name specifier for the associated
  5777. /// user-defined mapper.
  5778. /// \param MapperId The identifier of associated user-defined mapper.
  5779. static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  5780. ArrayRef<Expr *> Vars,
  5781. ArrayRef<ValueDecl *> Declarations,
  5782. MappableExprComponentListsRef ComponentLists,
  5783. ArrayRef<Expr *> UDMapperRefs,
  5784. ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
  5785. ArrayRef<SourceLocation> MotionModifiersLoc,
  5786. NestedNameSpecifierLoc UDMQualifierLoc,
  5787. DeclarationNameInfo MapperId);
  5788. /// Creates an empty clause with the place for \a NumVars variables.
  5789. ///
  5790. /// \param C AST context.
  5791. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  5792. /// NumVars: number of expressions listed in this clause; 2)
  5793. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  5794. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  5795. /// NumComponents: total number of expression components in the clause.
  5796. static OMPToClause *CreateEmpty(const ASTContext &C,
  5797. const OMPMappableExprListSizeTy &Sizes);
  5798. /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
  5799. ///
  5800. /// \param Cnt index for motion-modifier.
  5801. OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
  5802. assert(Cnt < NumberOfOMPMotionModifiers &&
  5803. "Requested modifier exceeds the total number of modifiers.");
  5804. return MotionModifiers[Cnt];
  5805. }
  5806. /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
  5807. /// locations.
  5808. ///
  5809. /// \param Cnt index for motion-modifier location.
  5810. SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
  5811. assert(Cnt < NumberOfOMPMotionModifiers &&
  5812. "Requested modifier location exceeds total number of modifiers.");
  5813. return MotionModifiersLoc[Cnt];
  5814. }
  5815. /// Fetches ArrayRef of motion-modifiers.
  5816. ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY {
  5817. return llvm::ArrayRef(MotionModifiers);
  5818. }
  5819. /// Fetches ArrayRef of location of motion-modifiers.
  5820. ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY {
  5821. return llvm::ArrayRef(MotionModifiersLoc);
  5822. }
  5823. /// Get colon location.
  5824. SourceLocation getColonLoc() const { return ColonLoc; }
  5825. child_range children() {
  5826. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  5827. reinterpret_cast<Stmt **>(varlist_end()));
  5828. }
  5829. const_child_range children() const {
  5830. auto Children = const_cast<OMPToClause *>(this)->children();
  5831. return const_child_range(Children.begin(), Children.end());
  5832. }
  5833. child_range used_children() {
  5834. return child_range(child_iterator(), child_iterator());
  5835. }
  5836. const_child_range used_children() const {
  5837. return const_child_range(const_child_iterator(), const_child_iterator());
  5838. }
  5839. static bool classof(const OMPClause *T) {
  5840. return T->getClauseKind() == llvm::omp::OMPC_to;
  5841. }
  5842. };
  5843. /// This represents clause 'from' in the '#pragma omp ...'
  5844. /// directives.
  5845. ///
  5846. /// \code
  5847. /// #pragma omp target update from(a,b)
  5848. /// \endcode
  5849. /// In this example directive '#pragma omp target update' has clause 'from'
  5850. /// with the variables 'a' and 'b'.
  5851. class OMPFromClause final
  5852. : public OMPMappableExprListClause<OMPFromClause>,
  5853. private llvm::TrailingObjects<
  5854. OMPFromClause, Expr *, ValueDecl *, unsigned,
  5855. OMPClauseMappableExprCommon::MappableComponent> {
  5856. friend class OMPClauseReader;
  5857. friend OMPMappableExprListClause;
  5858. friend OMPVarListClause;
  5859. friend TrailingObjects;
  5860. /// Motion-modifiers for the 'from' clause.
  5861. OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
  5862. OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
  5863. /// Location of motion-modifiers for the 'from' clause.
  5864. SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
  5865. /// Colon location.
  5866. SourceLocation ColonLoc;
  5867. /// Build clause with number of variables \a NumVars.
  5868. ///
  5869. /// \param TheMotionModifiers Motion-modifiers.
  5870. /// \param TheMotionModifiersLoc Locations of motion-modifiers.
  5871. /// \param MapperQualifierLoc C++ nested name specifier for the associated
  5872. /// user-defined mapper.
  5873. /// \param MapperIdInfo The identifier of associated user-defined mapper.
  5874. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  5875. /// StartLoc: starting location of the clause (the clause keyword); 2)
  5876. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  5877. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  5878. /// NumVars: number of expressions listed in this clause; 2)
  5879. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  5880. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  5881. /// NumComponents: total number of expression components in the clause.
  5882. explicit OMPFromClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
  5883. ArrayRef<SourceLocation> TheMotionModifiersLoc,
  5884. NestedNameSpecifierLoc MapperQualifierLoc,
  5885. DeclarationNameInfo MapperIdInfo,
  5886. const OMPVarListLocTy &Locs,
  5887. const OMPMappableExprListSizeTy &Sizes)
  5888. : OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes,
  5889. /*SupportsMapper=*/true, &MapperQualifierLoc,
  5890. &MapperIdInfo) {
  5891. assert(std::size(MotionModifiers) == TheMotionModifiers.size() &&
  5892. "Unexpected number of motion modifiers.");
  5893. llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
  5894. assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() &&
  5895. "Unexpected number of motion modifier locations.");
  5896. llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
  5897. }
  5898. /// Build an empty clause.
  5899. ///
  5900. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  5901. /// NumVars: number of expressions listed in this clause; 2)
  5902. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  5903. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  5904. /// NumComponents: total number of expression components in the clause.
  5905. explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes)
  5906. : OMPMappableExprListClause(llvm::omp::OMPC_from, OMPVarListLocTy(),
  5907. Sizes, /*SupportsMapper=*/true) {}
  5908. /// Set motion-modifier for the clause.
  5909. ///
  5910. /// \param I index for motion-modifier.
  5911. /// \param T motion-modifier for the clause.
  5912. void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
  5913. assert(I < NumberOfOMPMotionModifiers &&
  5914. "Unexpected index to store motion modifier, exceeds array size.");
  5915. MotionModifiers[I] = T;
  5916. }
  5917. /// Set location for the motion-modifier.
  5918. ///
  5919. /// \param I index for motion-modifier location.
  5920. /// \param TLoc motion-modifier location.
  5921. void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
  5922. assert(I < NumberOfOMPMotionModifiers &&
  5923. "Index to store motion modifier location exceeds array size.");
  5924. MotionModifiersLoc[I] = TLoc;
  5925. }
  5926. /// Set colon location.
  5927. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  5928. /// Define the sizes of each trailing object array except the last one. This
  5929. /// is required for TrailingObjects to work properly.
  5930. size_t numTrailingObjects(OverloadToken<Expr *>) const {
  5931. // There are varlist_size() of expressions, and varlist_size() of
  5932. // user-defined mappers.
  5933. return 2 * varlist_size();
  5934. }
  5935. size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
  5936. return getUniqueDeclarationsNum();
  5937. }
  5938. size_t numTrailingObjects(OverloadToken<unsigned>) const {
  5939. return getUniqueDeclarationsNum() + getTotalComponentListNum();
  5940. }
  5941. public:
  5942. /// Creates clause with a list of variables \a Vars.
  5943. ///
  5944. /// \param C AST context.
  5945. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  5946. /// StartLoc: starting location of the clause (the clause keyword); 2)
  5947. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  5948. /// \param Vars The original expression used in the clause.
  5949. /// \param Declarations Declarations used in the clause.
  5950. /// \param ComponentLists Component lists used in the clause.
  5951. /// \param MotionModifiers Motion-modifiers.
  5952. /// \param MotionModifiersLoc Location of motion-modifiers.
  5953. /// \param UDMapperRefs References to user-defined mappers associated with
  5954. /// expressions used in the clause.
  5955. /// \param UDMQualifierLoc C++ nested name specifier for the associated
  5956. /// user-defined mapper.
  5957. /// \param MapperId The identifier of associated user-defined mapper.
  5958. static OMPFromClause *
  5959. Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  5960. ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
  5961. MappableExprComponentListsRef ComponentLists,
  5962. ArrayRef<Expr *> UDMapperRefs,
  5963. ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
  5964. ArrayRef<SourceLocation> MotionModifiersLoc,
  5965. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
  5966. /// Creates an empty clause with the place for \a NumVars variables.
  5967. ///
  5968. /// \param C AST context.
  5969. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  5970. /// NumVars: number of expressions listed in this clause; 2)
  5971. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  5972. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  5973. /// NumComponents: total number of expression components in the clause.
  5974. static OMPFromClause *CreateEmpty(const ASTContext &C,
  5975. const OMPMappableExprListSizeTy &Sizes);
  5976. /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
  5977. ///
  5978. /// \param Cnt index for motion-modifier.
  5979. OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
  5980. assert(Cnt < NumberOfOMPMotionModifiers &&
  5981. "Requested modifier exceeds the total number of modifiers.");
  5982. return MotionModifiers[Cnt];
  5983. }
  5984. /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
  5985. /// locations.
  5986. ///
  5987. /// \param Cnt index for motion-modifier location.
  5988. SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
  5989. assert(Cnt < NumberOfOMPMotionModifiers &&
  5990. "Requested modifier location exceeds total number of modifiers.");
  5991. return MotionModifiersLoc[Cnt];
  5992. }
  5993. /// Fetches ArrayRef of motion-modifiers.
  5994. ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY {
  5995. return llvm::ArrayRef(MotionModifiers);
  5996. }
  5997. /// Fetches ArrayRef of location of motion-modifiers.
  5998. ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY {
  5999. return llvm::ArrayRef(MotionModifiersLoc);
  6000. }
  6001. /// Get colon location.
  6002. SourceLocation getColonLoc() const { return ColonLoc; }
  6003. child_range children() {
  6004. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6005. reinterpret_cast<Stmt **>(varlist_end()));
  6006. }
  6007. const_child_range children() const {
  6008. auto Children = const_cast<OMPFromClause *>(this)->children();
  6009. return const_child_range(Children.begin(), Children.end());
  6010. }
  6011. child_range used_children() {
  6012. return child_range(child_iterator(), child_iterator());
  6013. }
  6014. const_child_range used_children() const {
  6015. return const_child_range(const_child_iterator(), const_child_iterator());
  6016. }
  6017. static bool classof(const OMPClause *T) {
  6018. return T->getClauseKind() == llvm::omp::OMPC_from;
  6019. }
  6020. };
  6021. /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
  6022. /// directives.
  6023. ///
  6024. /// \code
  6025. /// #pragma omp target data use_device_ptr(a,b)
  6026. /// \endcode
  6027. /// In this example directive '#pragma omp target data' has clause
  6028. /// 'use_device_ptr' with the variables 'a' and 'b'.
  6029. class OMPUseDevicePtrClause final
  6030. : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
  6031. private llvm::TrailingObjects<
  6032. OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
  6033. OMPClauseMappableExprCommon::MappableComponent> {
  6034. friend class OMPClauseReader;
  6035. friend OMPMappableExprListClause;
  6036. friend OMPVarListClause;
  6037. friend TrailingObjects;
  6038. /// Build clause with number of variables \a NumVars.
  6039. ///
  6040. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6041. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6042. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6043. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6044. /// NumVars: number of expressions listed in this clause; 2)
  6045. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6046. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6047. /// NumComponents: total number of expression components in the clause.
  6048. explicit OMPUseDevicePtrClause(const OMPVarListLocTy &Locs,
  6049. const OMPMappableExprListSizeTy &Sizes)
  6050. : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr, Locs, Sizes) {
  6051. }
  6052. /// Build an empty clause.
  6053. ///
  6054. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6055. /// NumVars: number of expressions listed in this clause; 2)
  6056. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6057. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6058. /// NumComponents: total number of expression components in the clause.
  6059. explicit OMPUseDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
  6060. : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr,
  6061. OMPVarListLocTy(), Sizes) {}
  6062. /// Define the sizes of each trailing object array except the last one. This
  6063. /// is required for TrailingObjects to work properly.
  6064. size_t numTrailingObjects(OverloadToken<Expr *>) const {
  6065. return 3 * varlist_size();
  6066. }
  6067. size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
  6068. return getUniqueDeclarationsNum();
  6069. }
  6070. size_t numTrailingObjects(OverloadToken<unsigned>) const {
  6071. return getUniqueDeclarationsNum() + getTotalComponentListNum();
  6072. }
  6073. /// Sets the list of references to private copies with initializers for new
  6074. /// private variables.
  6075. /// \param VL List of references.
  6076. void setPrivateCopies(ArrayRef<Expr *> VL);
  6077. /// Gets the list of references to private copies with initializers for new
  6078. /// private variables.
  6079. MutableArrayRef<Expr *> getPrivateCopies() {
  6080. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  6081. }
  6082. ArrayRef<const Expr *> getPrivateCopies() const {
  6083. return llvm::ArrayRef(varlist_end(), varlist_size());
  6084. }
  6085. /// Sets the list of references to initializer variables for new private
  6086. /// variables.
  6087. /// \param VL List of references.
  6088. void setInits(ArrayRef<Expr *> VL);
  6089. /// Gets the list of references to initializer variables for new private
  6090. /// variables.
  6091. MutableArrayRef<Expr *> getInits() {
  6092. return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
  6093. }
  6094. ArrayRef<const Expr *> getInits() const {
  6095. return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
  6096. }
  6097. public:
  6098. /// Creates clause with a list of variables \a Vars.
  6099. ///
  6100. /// \param C AST context.
  6101. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6102. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6103. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6104. /// \param Vars The original expression used in the clause.
  6105. /// \param PrivateVars Expressions referring to private copies.
  6106. /// \param Inits Expressions referring to private copy initializers.
  6107. /// \param Declarations Declarations used in the clause.
  6108. /// \param ComponentLists Component lists used in the clause.
  6109. static OMPUseDevicePtrClause *
  6110. Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  6111. ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
  6112. ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
  6113. MappableExprComponentListsRef ComponentLists);
  6114. /// Creates an empty clause with the place for \a NumVars variables.
  6115. ///
  6116. /// \param C AST context.
  6117. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6118. /// NumVars: number of expressions listed in this clause; 2)
  6119. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6120. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6121. /// NumComponents: total number of expression components in the clause.
  6122. static OMPUseDevicePtrClause *
  6123. CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
  6124. using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
  6125. using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
  6126. using private_copies_range = llvm::iterator_range<private_copies_iterator>;
  6127. using private_copies_const_range =
  6128. llvm::iterator_range<private_copies_const_iterator>;
  6129. private_copies_range private_copies() {
  6130. return private_copies_range(getPrivateCopies().begin(),
  6131. getPrivateCopies().end());
  6132. }
  6133. private_copies_const_range private_copies() const {
  6134. return private_copies_const_range(getPrivateCopies().begin(),
  6135. getPrivateCopies().end());
  6136. }
  6137. using inits_iterator = MutableArrayRef<Expr *>::iterator;
  6138. using inits_const_iterator = ArrayRef<const Expr *>::iterator;
  6139. using inits_range = llvm::iterator_range<inits_iterator>;
  6140. using inits_const_range = llvm::iterator_range<inits_const_iterator>;
  6141. inits_range inits() {
  6142. return inits_range(getInits().begin(), getInits().end());
  6143. }
  6144. inits_const_range inits() const {
  6145. return inits_const_range(getInits().begin(), getInits().end());
  6146. }
  6147. child_range children() {
  6148. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6149. reinterpret_cast<Stmt **>(varlist_end()));
  6150. }
  6151. const_child_range children() const {
  6152. auto Children = const_cast<OMPUseDevicePtrClause *>(this)->children();
  6153. return const_child_range(Children.begin(), Children.end());
  6154. }
  6155. child_range used_children() {
  6156. return child_range(child_iterator(), child_iterator());
  6157. }
  6158. const_child_range used_children() const {
  6159. return const_child_range(const_child_iterator(), const_child_iterator());
  6160. }
  6161. static bool classof(const OMPClause *T) {
  6162. return T->getClauseKind() == llvm::omp::OMPC_use_device_ptr;
  6163. }
  6164. };
  6165. /// This represents clause 'use_device_addr' in the '#pragma omp ...'
  6166. /// directives.
  6167. ///
  6168. /// \code
  6169. /// #pragma omp target data use_device_addr(a,b)
  6170. /// \endcode
  6171. /// In this example directive '#pragma omp target data' has clause
  6172. /// 'use_device_addr' with the variables 'a' and 'b'.
  6173. class OMPUseDeviceAddrClause final
  6174. : public OMPMappableExprListClause<OMPUseDeviceAddrClause>,
  6175. private llvm::TrailingObjects<
  6176. OMPUseDeviceAddrClause, Expr *, ValueDecl *, unsigned,
  6177. OMPClauseMappableExprCommon::MappableComponent> {
  6178. friend class OMPClauseReader;
  6179. friend OMPMappableExprListClause;
  6180. friend OMPVarListClause;
  6181. friend TrailingObjects;
  6182. /// Build clause with number of variables \a NumVars.
  6183. ///
  6184. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6185. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6186. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6187. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6188. /// NumVars: number of expressions listed in this clause; 2)
  6189. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6190. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6191. /// NumComponents: total number of expression components in the clause.
  6192. explicit OMPUseDeviceAddrClause(const OMPVarListLocTy &Locs,
  6193. const OMPMappableExprListSizeTy &Sizes)
  6194. : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr, Locs,
  6195. Sizes) {}
  6196. /// Build an empty clause.
  6197. ///
  6198. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6199. /// NumVars: number of expressions listed in this clause; 2)
  6200. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6201. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6202. /// NumComponents: total number of expression components in the clause.
  6203. explicit OMPUseDeviceAddrClause(const OMPMappableExprListSizeTy &Sizes)
  6204. : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr,
  6205. OMPVarListLocTy(), Sizes) {}
  6206. /// Define the sizes of each trailing object array except the last one. This
  6207. /// is required for TrailingObjects to work properly.
  6208. size_t numTrailingObjects(OverloadToken<Expr *>) const {
  6209. return varlist_size();
  6210. }
  6211. size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
  6212. return getUniqueDeclarationsNum();
  6213. }
  6214. size_t numTrailingObjects(OverloadToken<unsigned>) const {
  6215. return getUniqueDeclarationsNum() + getTotalComponentListNum();
  6216. }
  6217. public:
  6218. /// Creates clause with a list of variables \a Vars.
  6219. ///
  6220. /// \param C AST context.
  6221. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6222. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6223. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6224. /// \param Vars The original expression used in the clause.
  6225. /// \param Declarations Declarations used in the clause.
  6226. /// \param ComponentLists Component lists used in the clause.
  6227. static OMPUseDeviceAddrClause *
  6228. Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  6229. ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
  6230. MappableExprComponentListsRef ComponentLists);
  6231. /// Creates an empty clause with the place for \a NumVars variables.
  6232. ///
  6233. /// \param C AST context.
  6234. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6235. /// NumVars: number of expressions listed in this clause; 2)
  6236. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6237. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6238. /// NumComponents: total number of expression components in the clause.
  6239. static OMPUseDeviceAddrClause *
  6240. CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
  6241. child_range children() {
  6242. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6243. reinterpret_cast<Stmt **>(varlist_end()));
  6244. }
  6245. const_child_range children() const {
  6246. auto Children = const_cast<OMPUseDeviceAddrClause *>(this)->children();
  6247. return const_child_range(Children.begin(), Children.end());
  6248. }
  6249. child_range used_children() {
  6250. return child_range(child_iterator(), child_iterator());
  6251. }
  6252. const_child_range used_children() const {
  6253. return const_child_range(const_child_iterator(), const_child_iterator());
  6254. }
  6255. static bool classof(const OMPClause *T) {
  6256. return T->getClauseKind() == llvm::omp::OMPC_use_device_addr;
  6257. }
  6258. };
  6259. /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
  6260. /// directives.
  6261. ///
  6262. /// \code
  6263. /// #pragma omp target is_device_ptr(a,b)
  6264. /// \endcode
  6265. /// In this example directive '#pragma omp target' has clause
  6266. /// 'is_device_ptr' with the variables 'a' and 'b'.
  6267. class OMPIsDevicePtrClause final
  6268. : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
  6269. private llvm::TrailingObjects<
  6270. OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
  6271. OMPClauseMappableExprCommon::MappableComponent> {
  6272. friend class OMPClauseReader;
  6273. friend OMPMappableExprListClause;
  6274. friend OMPVarListClause;
  6275. friend TrailingObjects;
  6276. /// Build clause with number of variables \a NumVars.
  6277. ///
  6278. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6279. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6280. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6281. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6282. /// NumVars: number of expressions listed in this clause; 2)
  6283. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6284. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6285. /// NumComponents: total number of expression components in the clause.
  6286. explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs,
  6287. const OMPMappableExprListSizeTy &Sizes)
  6288. : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr, Locs, Sizes) {}
  6289. /// Build an empty clause.
  6290. ///
  6291. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6292. /// NumVars: number of expressions listed in this clause; 2)
  6293. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6294. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6295. /// NumComponents: total number of expression components in the clause.
  6296. explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
  6297. : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr,
  6298. OMPVarListLocTy(), Sizes) {}
  6299. /// Define the sizes of each trailing object array except the last one. This
  6300. /// is required for TrailingObjects to work properly.
  6301. size_t numTrailingObjects(OverloadToken<Expr *>) const {
  6302. return varlist_size();
  6303. }
  6304. size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
  6305. return getUniqueDeclarationsNum();
  6306. }
  6307. size_t numTrailingObjects(OverloadToken<unsigned>) const {
  6308. return getUniqueDeclarationsNum() + getTotalComponentListNum();
  6309. }
  6310. public:
  6311. /// Creates clause with a list of variables \a Vars.
  6312. ///
  6313. /// \param C AST context.
  6314. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6315. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6316. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6317. /// \param Vars The original expression used in the clause.
  6318. /// \param Declarations Declarations used in the clause.
  6319. /// \param ComponentLists Component lists used in the clause.
  6320. static OMPIsDevicePtrClause *
  6321. Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  6322. ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
  6323. MappableExprComponentListsRef ComponentLists);
  6324. /// Creates an empty clause with the place for \a NumVars variables.
  6325. ///
  6326. /// \param C AST context.
  6327. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6328. /// NumVars: number of expressions listed in this clause; 2)
  6329. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6330. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6331. /// NumComponents: total number of expression components in the clause.
  6332. static OMPIsDevicePtrClause *
  6333. CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
  6334. child_range children() {
  6335. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6336. reinterpret_cast<Stmt **>(varlist_end()));
  6337. }
  6338. const_child_range children() const {
  6339. auto Children = const_cast<OMPIsDevicePtrClause *>(this)->children();
  6340. return const_child_range(Children.begin(), Children.end());
  6341. }
  6342. child_range used_children() {
  6343. return child_range(child_iterator(), child_iterator());
  6344. }
  6345. const_child_range used_children() const {
  6346. return const_child_range(const_child_iterator(), const_child_iterator());
  6347. }
  6348. static bool classof(const OMPClause *T) {
  6349. return T->getClauseKind() == llvm::omp::OMPC_is_device_ptr;
  6350. }
  6351. };
  6352. /// This represents clause 'has_device_ptr' in the '#pragma omp ...'
  6353. /// directives.
  6354. ///
  6355. /// \code
  6356. /// #pragma omp target has_device_addr(a,b)
  6357. /// \endcode
  6358. /// In this example directive '#pragma omp target' has clause
  6359. /// 'has_device_ptr' with the variables 'a' and 'b'.
  6360. class OMPHasDeviceAddrClause final
  6361. : public OMPMappableExprListClause<OMPHasDeviceAddrClause>,
  6362. private llvm::TrailingObjects<
  6363. OMPHasDeviceAddrClause, Expr *, ValueDecl *, unsigned,
  6364. OMPClauseMappableExprCommon::MappableComponent> {
  6365. friend class OMPClauseReader;
  6366. friend OMPMappableExprListClause;
  6367. friend OMPVarListClause;
  6368. friend TrailingObjects;
  6369. /// Build clause with number of variables \a NumVars.
  6370. ///
  6371. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6372. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6373. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6374. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6375. /// NumVars: number of expressions listed in this clause; 2)
  6376. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6377. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6378. /// NumComponents: total number of expression components in the clause.
  6379. explicit OMPHasDeviceAddrClause(const OMPVarListLocTy &Locs,
  6380. const OMPMappableExprListSizeTy &Sizes)
  6381. : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr, Locs,
  6382. Sizes) {}
  6383. /// Build an empty clause.
  6384. ///
  6385. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6386. /// NumVars: number of expressions listed in this clause; 2)
  6387. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6388. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6389. /// NumComponents: total number of expression components in the clause.
  6390. explicit OMPHasDeviceAddrClause(const OMPMappableExprListSizeTy &Sizes)
  6391. : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr,
  6392. OMPVarListLocTy(), Sizes) {}
  6393. /// Define the sizes of each trailing object array except the last one. This
  6394. /// is required for TrailingObjects to work properly.
  6395. size_t numTrailingObjects(OverloadToken<Expr *>) const {
  6396. return varlist_size();
  6397. }
  6398. size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
  6399. return getUniqueDeclarationsNum();
  6400. }
  6401. size_t numTrailingObjects(OverloadToken<unsigned>) const {
  6402. return getUniqueDeclarationsNum() + getTotalComponentListNum();
  6403. }
  6404. public:
  6405. /// Creates clause with a list of variables \a Vars.
  6406. ///
  6407. /// \param C AST context.
  6408. /// \param Locs Locations needed to build a mappable clause. It includes 1)
  6409. /// StartLoc: starting location of the clause (the clause keyword); 2)
  6410. /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
  6411. /// \param Vars The original expression used in the clause.
  6412. /// \param Declarations Declarations used in the clause.
  6413. /// \param ComponentLists Component lists used in the clause.
  6414. static OMPHasDeviceAddrClause *
  6415. Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  6416. ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
  6417. MappableExprComponentListsRef ComponentLists);
  6418. /// Creates an empty clause with the place for \a NumVars variables.
  6419. ///
  6420. /// \param C AST context.
  6421. /// \param Sizes All required sizes to build a mappable clause. It includes 1)
  6422. /// NumVars: number of expressions listed in this clause; 2)
  6423. /// NumUniqueDeclarations: number of unique base declarations in this clause;
  6424. /// 3) NumComponentLists: number of component lists in this clause; and 4)
  6425. /// NumComponents: total number of expression components in the clause.
  6426. static OMPHasDeviceAddrClause *
  6427. CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
  6428. child_range children() {
  6429. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6430. reinterpret_cast<Stmt **>(varlist_end()));
  6431. }
  6432. const_child_range children() const {
  6433. auto Children = const_cast<OMPHasDeviceAddrClause *>(this)->children();
  6434. return const_child_range(Children.begin(), Children.end());
  6435. }
  6436. child_range used_children() {
  6437. return child_range(child_iterator(), child_iterator());
  6438. }
  6439. const_child_range used_children() const {
  6440. return const_child_range(const_child_iterator(), const_child_iterator());
  6441. }
  6442. static bool classof(const OMPClause *T) {
  6443. return T->getClauseKind() == llvm::omp::OMPC_has_device_addr;
  6444. }
  6445. };
  6446. /// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
  6447. ///
  6448. /// \code
  6449. /// #pragma omp simd nontemporal(a)
  6450. /// \endcode
  6451. /// In this example directive '#pragma omp simd' has clause 'nontemporal' for
  6452. /// the variable 'a'.
  6453. class OMPNontemporalClause final
  6454. : public OMPVarListClause<OMPNontemporalClause>,
  6455. private llvm::TrailingObjects<OMPNontemporalClause, Expr *> {
  6456. friend class OMPClauseReader;
  6457. friend OMPVarListClause;
  6458. friend TrailingObjects;
  6459. /// Build clause with number of variables \a N.
  6460. ///
  6461. /// \param StartLoc Starting location of the clause.
  6462. /// \param LParenLoc Location of '('.
  6463. /// \param EndLoc Ending location of the clause.
  6464. /// \param N Number of the variables in the clause.
  6465. OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  6466. SourceLocation EndLoc, unsigned N)
  6467. : OMPVarListClause<OMPNontemporalClause>(llvm::omp::OMPC_nontemporal,
  6468. StartLoc, LParenLoc, EndLoc, N) {
  6469. }
  6470. /// Build an empty clause.
  6471. ///
  6472. /// \param N Number of variables.
  6473. explicit OMPNontemporalClause(unsigned N)
  6474. : OMPVarListClause<OMPNontemporalClause>(
  6475. llvm::omp::OMPC_nontemporal, SourceLocation(), SourceLocation(),
  6476. SourceLocation(), N) {}
  6477. /// Get the list of privatied copies if the member expression was captured by
  6478. /// one of the privatization clauses.
  6479. MutableArrayRef<Expr *> getPrivateRefs() {
  6480. return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
  6481. }
  6482. ArrayRef<const Expr *> getPrivateRefs() const {
  6483. return llvm::ArrayRef(varlist_end(), varlist_size());
  6484. }
  6485. public:
  6486. /// Creates clause with a list of variables \a VL.
  6487. ///
  6488. /// \param C AST context.
  6489. /// \param StartLoc Starting location of the clause.
  6490. /// \param LParenLoc Location of '('.
  6491. /// \param EndLoc Ending location of the clause.
  6492. /// \param VL List of references to the variables.
  6493. static OMPNontemporalClause *
  6494. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  6495. SourceLocation EndLoc, ArrayRef<Expr *> VL);
  6496. /// Creates an empty clause with the place for \a N variables.
  6497. ///
  6498. /// \param C AST context.
  6499. /// \param N The number of variables.
  6500. static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);
  6501. /// Sets the list of references to private copies created in private clauses.
  6502. /// \param VL List of references.
  6503. void setPrivateRefs(ArrayRef<Expr *> VL);
  6504. child_range children() {
  6505. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6506. reinterpret_cast<Stmt **>(varlist_end()));
  6507. }
  6508. const_child_range children() const {
  6509. auto Children = const_cast<OMPNontemporalClause *>(this)->children();
  6510. return const_child_range(Children.begin(), Children.end());
  6511. }
  6512. child_range private_refs() {
  6513. return child_range(reinterpret_cast<Stmt **>(getPrivateRefs().begin()),
  6514. reinterpret_cast<Stmt **>(getPrivateRefs().end()));
  6515. }
  6516. const_child_range private_refs() const {
  6517. auto Children = const_cast<OMPNontemporalClause *>(this)->private_refs();
  6518. return const_child_range(Children.begin(), Children.end());
  6519. }
  6520. child_range used_children() {
  6521. return child_range(child_iterator(), child_iterator());
  6522. }
  6523. const_child_range used_children() const {
  6524. return const_child_range(const_child_iterator(), const_child_iterator());
  6525. }
  6526. static bool classof(const OMPClause *T) {
  6527. return T->getClauseKind() == llvm::omp::OMPC_nontemporal;
  6528. }
  6529. };
  6530. /// This represents 'order' clause in the '#pragma omp ...' directive.
  6531. ///
  6532. /// \code
  6533. /// #pragma omp simd order(concurrent)
  6534. /// \endcode
  6535. /// In this example directive '#pragma omp parallel' has simple 'order'
  6536. /// clause with kind 'concurrent'.
  6537. class OMPOrderClause final : public OMPClause {
  6538. friend class OMPClauseReader;
  6539. /// Location of '('.
  6540. SourceLocation LParenLoc;
  6541. /// A kind of the 'order' clause.
  6542. OpenMPOrderClauseKind Kind = OMPC_ORDER_unknown;
  6543. /// Start location of the kind in source code.
  6544. SourceLocation KindKwLoc;
  6545. /// A modifier for order clause
  6546. OpenMPOrderClauseModifier Modifier = OMPC_ORDER_MODIFIER_unknown;
  6547. /// Start location of the modifier in source code.
  6548. SourceLocation ModifierKwLoc;
  6549. /// Set kind of the clause.
  6550. ///
  6551. /// \param K Argument of clause.
  6552. void setKind(OpenMPOrderClauseKind K) { Kind = K; }
  6553. /// Set argument location.
  6554. ///
  6555. /// \param KLoc Argument location.
  6556. void setKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
  6557. /// Set modifier of the clause.
  6558. ///
  6559. /// \param M Argument of clause.
  6560. void setModifier(OpenMPOrderClauseModifier M) { Modifier = M; }
  6561. /// Set modifier location.
  6562. ///
  6563. /// \param MLoc Modifier keyword location.
  6564. void setModifierKwLoc(SourceLocation MLoc) { ModifierKwLoc = MLoc; }
  6565. public:
  6566. /// Build 'order' clause with argument \p A ('concurrent').
  6567. ///
  6568. /// \param A Argument of the clause ('concurrent').
  6569. /// \param ALoc Starting location of the argument.
  6570. /// \param StartLoc Starting location of the clause.
  6571. /// \param LParenLoc Location of '('.
  6572. /// \param EndLoc Ending location of the clause.
  6573. /// \param Modifier The modifier applied to 'order' clause.
  6574. /// \param MLoc Location of the modifier
  6575. OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc,
  6576. SourceLocation StartLoc, SourceLocation LParenLoc,
  6577. SourceLocation EndLoc, OpenMPOrderClauseModifier M,
  6578. SourceLocation MLoc)
  6579. : OMPClause(llvm::omp::OMPC_order, StartLoc, EndLoc),
  6580. LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), Modifier(M),
  6581. ModifierKwLoc(MLoc) {}
  6582. /// Build an empty clause.
  6583. OMPOrderClause()
  6584. : OMPClause(llvm::omp::OMPC_order, SourceLocation(), SourceLocation()) {}
  6585. /// Sets the location of '('.
  6586. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  6587. /// Returns the location of '('.
  6588. SourceLocation getLParenLoc() const { return LParenLoc; }
  6589. /// Returns kind of the clause.
  6590. OpenMPOrderClauseKind getKind() const { return Kind; }
  6591. /// Returns location of clause kind.
  6592. SourceLocation getKindKwLoc() const { return KindKwLoc; }
  6593. /// Returns Modifier of the clause.
  6594. OpenMPOrderClauseModifier getModifier() const { return Modifier; }
  6595. /// Returns location of clause modifier.
  6596. SourceLocation getModifierKwLoc() const { return ModifierKwLoc; }
  6597. child_range children() {
  6598. return child_range(child_iterator(), child_iterator());
  6599. }
  6600. const_child_range children() const {
  6601. return const_child_range(const_child_iterator(), const_child_iterator());
  6602. }
  6603. child_range used_children() {
  6604. return child_range(child_iterator(), child_iterator());
  6605. }
  6606. const_child_range used_children() const {
  6607. return const_child_range(const_child_iterator(), const_child_iterator());
  6608. }
  6609. static bool classof(const OMPClause *T) {
  6610. return T->getClauseKind() == llvm::omp::OMPC_order;
  6611. }
  6612. };
  6613. /// This represents the 'init' clause in '#pragma omp ...' directives.
  6614. ///
  6615. /// \code
  6616. /// #pragma omp interop init(target:obj)
  6617. /// \endcode
  6618. class OMPInitClause final
  6619. : public OMPVarListClause<OMPInitClause>,
  6620. private llvm::TrailingObjects<OMPInitClause, Expr *> {
  6621. friend class OMPClauseReader;
  6622. friend OMPVarListClause;
  6623. friend TrailingObjects;
  6624. /// Location of interop variable.
  6625. SourceLocation VarLoc;
  6626. bool IsTarget = false;
  6627. bool IsTargetSync = false;
  6628. void setInteropVar(Expr *E) { varlist_begin()[0] = E; }
  6629. void setIsTarget(bool V) { IsTarget = V; }
  6630. void setIsTargetSync(bool V) { IsTargetSync = V; }
  6631. /// Sets the location of the interop variable.
  6632. void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
  6633. /// Build 'init' clause.
  6634. ///
  6635. /// \param IsTarget Uses the 'target' interop-type.
  6636. /// \param IsTargetSync Uses the 'targetsync' interop-type.
  6637. /// \param StartLoc Starting location of the clause.
  6638. /// \param LParenLoc Location of '('.
  6639. /// \param VarLoc Location of the interop variable.
  6640. /// \param EndLoc Ending location of the clause.
  6641. /// \param N Number of expressions.
  6642. OMPInitClause(bool IsTarget, bool IsTargetSync, SourceLocation StartLoc,
  6643. SourceLocation LParenLoc, SourceLocation VarLoc,
  6644. SourceLocation EndLoc, unsigned N)
  6645. : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, StartLoc,
  6646. LParenLoc, EndLoc, N),
  6647. VarLoc(VarLoc), IsTarget(IsTarget), IsTargetSync(IsTargetSync) {}
  6648. /// Build an empty clause.
  6649. OMPInitClause(unsigned N)
  6650. : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, SourceLocation(),
  6651. SourceLocation(), SourceLocation(), N) {
  6652. }
  6653. public:
  6654. /// Creates a fully specified clause.
  6655. ///
  6656. /// \param C AST context.
  6657. /// \param InteropVar The interop variable.
  6658. /// \param InteropInfo The interop-type and prefer_type list.
  6659. /// \param StartLoc Starting location of the clause.
  6660. /// \param LParenLoc Location of '('.
  6661. /// \param VarLoc Location of the interop variable.
  6662. /// \param EndLoc Ending location of the clause.
  6663. static OMPInitClause *Create(const ASTContext &C, Expr *InteropVar,
  6664. OMPInteropInfo &InteropInfo,
  6665. SourceLocation StartLoc,
  6666. SourceLocation LParenLoc, SourceLocation VarLoc,
  6667. SourceLocation EndLoc);
  6668. /// Creates an empty clause with \a N expressions.
  6669. ///
  6670. /// \param C AST context.
  6671. /// \param N Number of expression items.
  6672. static OMPInitClause *CreateEmpty(const ASTContext &C, unsigned N);
  6673. /// Returns the location of the interop variable.
  6674. SourceLocation getVarLoc() const { return VarLoc; }
  6675. /// Returns the interop variable.
  6676. Expr *getInteropVar() { return varlist_begin()[0]; }
  6677. const Expr *getInteropVar() const { return varlist_begin()[0]; }
  6678. /// Returns true is interop-type 'target' is used.
  6679. bool getIsTarget() const { return IsTarget; }
  6680. /// Returns true is interop-type 'targetsync' is used.
  6681. bool getIsTargetSync() const { return IsTargetSync; }
  6682. child_range children() {
  6683. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6684. reinterpret_cast<Stmt **>(varlist_end()));
  6685. }
  6686. const_child_range children() const {
  6687. auto Children = const_cast<OMPInitClause *>(this)->children();
  6688. return const_child_range(Children.begin(), Children.end());
  6689. }
  6690. child_range used_children() {
  6691. return child_range(child_iterator(), child_iterator());
  6692. }
  6693. const_child_range used_children() const {
  6694. return const_child_range(const_child_iterator(), const_child_iterator());
  6695. }
  6696. using prefs_iterator = MutableArrayRef<Expr *>::iterator;
  6697. using const_prefs_iterator = ArrayRef<const Expr *>::iterator;
  6698. using prefs_range = llvm::iterator_range<prefs_iterator>;
  6699. using const_prefs_range = llvm::iterator_range<const_prefs_iterator>;
  6700. prefs_range prefs() {
  6701. return prefs_range(reinterpret_cast<Expr **>(std::next(varlist_begin())),
  6702. reinterpret_cast<Expr **>(varlist_end()));
  6703. }
  6704. const_prefs_range prefs() const {
  6705. auto Prefs = const_cast<OMPInitClause *>(this)->prefs();
  6706. return const_prefs_range(Prefs.begin(), Prefs.end());
  6707. }
  6708. static bool classof(const OMPClause *T) {
  6709. return T->getClauseKind() == llvm::omp::OMPC_init;
  6710. }
  6711. };
  6712. /// This represents the 'use' clause in '#pragma omp ...' directives.
  6713. ///
  6714. /// \code
  6715. /// #pragma omp interop use(obj)
  6716. /// \endcode
  6717. class OMPUseClause final : public OMPClause {
  6718. friend class OMPClauseReader;
  6719. /// Location of '('.
  6720. SourceLocation LParenLoc;
  6721. /// Location of interop variable.
  6722. SourceLocation VarLoc;
  6723. /// The interop variable.
  6724. Stmt *InteropVar = nullptr;
  6725. /// Set the interop variable.
  6726. void setInteropVar(Expr *E) { InteropVar = E; }
  6727. /// Sets the location of '('.
  6728. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  6729. /// Sets the location of the interop variable.
  6730. void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
  6731. public:
  6732. /// Build 'use' clause with and interop variable expression \a InteropVar.
  6733. ///
  6734. /// \param InteropVar The interop variable.
  6735. /// \param StartLoc Starting location of the clause.
  6736. /// \param LParenLoc Location of '('.
  6737. /// \param VarLoc Location of the interop variable.
  6738. /// \param EndLoc Ending location of the clause.
  6739. OMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
  6740. SourceLocation LParenLoc, SourceLocation VarLoc,
  6741. SourceLocation EndLoc)
  6742. : OMPClause(llvm::omp::OMPC_use, StartLoc, EndLoc), LParenLoc(LParenLoc),
  6743. VarLoc(VarLoc), InteropVar(InteropVar) {}
  6744. /// Build an empty clause.
  6745. OMPUseClause()
  6746. : OMPClause(llvm::omp::OMPC_use, SourceLocation(), SourceLocation()) {}
  6747. /// Returns the location of '('.
  6748. SourceLocation getLParenLoc() const { return LParenLoc; }
  6749. /// Returns the location of the interop variable.
  6750. SourceLocation getVarLoc() const { return VarLoc; }
  6751. /// Returns the interop variable.
  6752. Expr *getInteropVar() const { return cast<Expr>(InteropVar); }
  6753. child_range children() { return child_range(&InteropVar, &InteropVar + 1); }
  6754. const_child_range children() const {
  6755. return const_child_range(&InteropVar, &InteropVar + 1);
  6756. }
  6757. child_range used_children() {
  6758. return child_range(child_iterator(), child_iterator());
  6759. }
  6760. const_child_range used_children() const {
  6761. return const_child_range(const_child_iterator(), const_child_iterator());
  6762. }
  6763. static bool classof(const OMPClause *T) {
  6764. return T->getClauseKind() == llvm::omp::OMPC_use;
  6765. }
  6766. };
  6767. /// This represents 'destroy' clause in the '#pragma omp depobj'
  6768. /// directive or the '#pragma omp interop' directive..
  6769. ///
  6770. /// \code
  6771. /// #pragma omp depobj(a) destroy
  6772. /// #pragma omp interop destroy(obj)
  6773. /// \endcode
  6774. /// In these examples directive '#pragma omp depobj' and '#pragma omp interop'
  6775. /// have a 'destroy' clause. The 'interop' directive includes an object.
  6776. class OMPDestroyClause final : public OMPClause {
  6777. friend class OMPClauseReader;
  6778. /// Location of '('.
  6779. SourceLocation LParenLoc;
  6780. /// Location of interop variable.
  6781. SourceLocation VarLoc;
  6782. /// The interop variable.
  6783. Stmt *InteropVar = nullptr;
  6784. /// Set the interop variable.
  6785. void setInteropVar(Expr *E) { InteropVar = E; }
  6786. /// Sets the location of '('.
  6787. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  6788. /// Sets the location of the interop variable.
  6789. void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
  6790. public:
  6791. /// Build 'destroy' clause with an interop variable expression \a InteropVar.
  6792. ///
  6793. /// \param InteropVar The interop variable.
  6794. /// \param StartLoc Starting location of the clause.
  6795. /// \param LParenLoc Location of '('.
  6796. /// \param VarLoc Location of the interop variable.
  6797. /// \param EndLoc Ending location of the clause.
  6798. OMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
  6799. SourceLocation LParenLoc, SourceLocation VarLoc,
  6800. SourceLocation EndLoc)
  6801. : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc),
  6802. LParenLoc(LParenLoc), VarLoc(VarLoc), InteropVar(InteropVar) {}
  6803. /// Build 'destroy' clause.
  6804. ///
  6805. /// \param StartLoc Starting location of the clause.
  6806. /// \param EndLoc Ending location of the clause.
  6807. OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
  6808. : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc) {}
  6809. /// Build an empty clause.
  6810. OMPDestroyClause()
  6811. : OMPClause(llvm::omp::OMPC_destroy, SourceLocation(), SourceLocation()) {
  6812. }
  6813. /// Returns the location of '('.
  6814. SourceLocation getLParenLoc() const { return LParenLoc; }
  6815. /// Returns the location of the interop variable.
  6816. SourceLocation getVarLoc() const { return VarLoc; }
  6817. /// Returns the interop variable.
  6818. Expr *getInteropVar() const { return cast_or_null<Expr>(InteropVar); }
  6819. child_range children() {
  6820. if (InteropVar)
  6821. return child_range(&InteropVar, &InteropVar + 1);
  6822. return child_range(child_iterator(), child_iterator());
  6823. }
  6824. const_child_range children() const {
  6825. if (InteropVar)
  6826. return const_child_range(&InteropVar, &InteropVar + 1);
  6827. return const_child_range(const_child_iterator(), const_child_iterator());
  6828. }
  6829. child_range used_children() {
  6830. return child_range(child_iterator(), child_iterator());
  6831. }
  6832. const_child_range used_children() const {
  6833. return const_child_range(const_child_iterator(), const_child_iterator());
  6834. }
  6835. static bool classof(const OMPClause *T) {
  6836. return T->getClauseKind() == llvm::omp::OMPC_destroy;
  6837. }
  6838. };
  6839. /// This represents 'novariants' clause in the '#pragma omp ...' directive.
  6840. ///
  6841. /// \code
  6842. /// #pragma omp dispatch novariants(a > 5)
  6843. /// \endcode
  6844. /// In this example directive '#pragma omp dispatch' has simple 'novariants'
  6845. /// clause with condition 'a > 5'.
  6846. class OMPNovariantsClause final
  6847. : public OMPOneStmtClause<llvm::omp::OMPC_novariants, OMPClause>,
  6848. public OMPClauseWithPreInit {
  6849. friend class OMPClauseReader;
  6850. /// Set condition.
  6851. void setCondition(Expr *Cond) { setStmt(Cond); }
  6852. public:
  6853. /// Build 'novariants' clause with condition \a Cond.
  6854. ///
  6855. /// \param Cond Condition of the clause.
  6856. /// \param HelperCond Helper condition for the construct.
  6857. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  6858. /// clause must be captured.
  6859. /// \param StartLoc Starting location of the clause.
  6860. /// \param LParenLoc Location of '('.
  6861. /// \param EndLoc Ending location of the clause.
  6862. OMPNovariantsClause(Expr *Cond, Stmt *HelperCond,
  6863. OpenMPDirectiveKind CaptureRegion,
  6864. SourceLocation StartLoc, SourceLocation LParenLoc,
  6865. SourceLocation EndLoc)
  6866. : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
  6867. OMPClauseWithPreInit(this) {
  6868. setPreInitStmt(HelperCond, CaptureRegion);
  6869. }
  6870. /// Build an empty clause.
  6871. OMPNovariantsClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
  6872. /// Returns condition.
  6873. Expr *getCondition() const { return getStmtAs<Expr>(); }
  6874. child_range used_children();
  6875. const_child_range used_children() const {
  6876. auto Children = const_cast<OMPNovariantsClause *>(this)->used_children();
  6877. return const_child_range(Children.begin(), Children.end());
  6878. }
  6879. };
  6880. /// This represents 'nocontext' clause in the '#pragma omp ...' directive.
  6881. ///
  6882. /// \code
  6883. /// #pragma omp dispatch nocontext(a > 5)
  6884. /// \endcode
  6885. /// In this example directive '#pragma omp dispatch' has simple 'nocontext'
  6886. /// clause with condition 'a > 5'.
  6887. class OMPNocontextClause final
  6888. : public OMPOneStmtClause<llvm::omp::OMPC_nocontext, OMPClause>,
  6889. public OMPClauseWithPreInit {
  6890. friend class OMPClauseReader;
  6891. /// Set condition.
  6892. void setCondition(Expr *Cond) { setStmt(Cond); }
  6893. public:
  6894. /// Build 'nocontext' clause with condition \a Cond.
  6895. ///
  6896. /// \param Cond Condition of the clause.
  6897. /// \param HelperCond Helper condition for the construct.
  6898. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  6899. /// clause must be captured.
  6900. /// \param StartLoc Starting location of the clause.
  6901. /// \param LParenLoc Location of '('.
  6902. /// \param EndLoc Ending location of the clause.
  6903. OMPNocontextClause(Expr *Cond, Stmt *HelperCond,
  6904. OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
  6905. SourceLocation LParenLoc, SourceLocation EndLoc)
  6906. : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
  6907. OMPClauseWithPreInit(this) {
  6908. setPreInitStmt(HelperCond, CaptureRegion);
  6909. }
  6910. /// Build an empty clause.
  6911. OMPNocontextClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
  6912. /// Returns condition.
  6913. Expr *getCondition() const { return getStmtAs<Expr>(); }
  6914. child_range used_children();
  6915. const_child_range used_children() const {
  6916. auto Children = const_cast<OMPNocontextClause *>(this)->used_children();
  6917. return const_child_range(Children.begin(), Children.end());
  6918. }
  6919. };
  6920. /// This represents 'detach' clause in the '#pragma omp task' directive.
  6921. ///
  6922. /// \code
  6923. /// #pragma omp task detach(evt)
  6924. /// \endcode
  6925. /// In this example directive '#pragma omp detach' has simple 'detach' clause
  6926. /// with the variable 'evt'.
  6927. class OMPDetachClause final
  6928. : public OMPOneStmtClause<llvm::omp::OMPC_detach, OMPClause> {
  6929. friend class OMPClauseReader;
  6930. /// Set condition.
  6931. void setEventHandler(Expr *E) { setStmt(E); }
  6932. public:
  6933. /// Build 'detach' clause with event-handler \a Evt.
  6934. ///
  6935. /// \param Evt Event handler expression.
  6936. /// \param StartLoc Starting location of the clause.
  6937. /// \param LParenLoc Location of '('.
  6938. /// \param EndLoc Ending location of the clause.
  6939. OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc,
  6940. SourceLocation EndLoc)
  6941. : OMPOneStmtClause(Evt, StartLoc, LParenLoc, EndLoc) {}
  6942. /// Build an empty clause.
  6943. OMPDetachClause() : OMPOneStmtClause() {}
  6944. /// Returns event-handler expression.
  6945. Expr *getEventHandler() const { return getStmtAs<Expr>(); }
  6946. };
  6947. /// This represents clause 'inclusive' in the '#pragma omp scan' directive.
  6948. ///
  6949. /// \code
  6950. /// #pragma omp scan inclusive(a,b)
  6951. /// \endcode
  6952. /// In this example directive '#pragma omp scan' has clause 'inclusive'
  6953. /// with the variables 'a' and 'b'.
  6954. class OMPInclusiveClause final
  6955. : public OMPVarListClause<OMPInclusiveClause>,
  6956. private llvm::TrailingObjects<OMPInclusiveClause, Expr *> {
  6957. friend class OMPClauseReader;
  6958. friend OMPVarListClause;
  6959. friend TrailingObjects;
  6960. /// Build clause with number of variables \a N.
  6961. ///
  6962. /// \param StartLoc Starting location of the clause.
  6963. /// \param LParenLoc Location of '('.
  6964. /// \param EndLoc Ending location of the clause.
  6965. /// \param N Number of the variables in the clause.
  6966. OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  6967. SourceLocation EndLoc, unsigned N)
  6968. : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
  6969. StartLoc, LParenLoc, EndLoc, N) {}
  6970. /// Build an empty clause.
  6971. ///
  6972. /// \param N Number of variables.
  6973. explicit OMPInclusiveClause(unsigned N)
  6974. : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
  6975. SourceLocation(), SourceLocation(),
  6976. SourceLocation(), N) {}
  6977. public:
  6978. /// Creates clause with a list of variables \a VL.
  6979. ///
  6980. /// \param C AST context.
  6981. /// \param StartLoc Starting location of the clause.
  6982. /// \param LParenLoc Location of '('.
  6983. /// \param EndLoc Ending location of the clause.
  6984. /// \param VL List of references to the original variables.
  6985. static OMPInclusiveClause *Create(const ASTContext &C,
  6986. SourceLocation StartLoc,
  6987. SourceLocation LParenLoc,
  6988. SourceLocation EndLoc, ArrayRef<Expr *> VL);
  6989. /// Creates an empty clause with the place for \a N variables.
  6990. ///
  6991. /// \param C AST context.
  6992. /// \param N The number of variables.
  6993. static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
  6994. child_range children() {
  6995. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  6996. reinterpret_cast<Stmt **>(varlist_end()));
  6997. }
  6998. const_child_range children() const {
  6999. auto Children = const_cast<OMPInclusiveClause *>(this)->children();
  7000. return const_child_range(Children.begin(), Children.end());
  7001. }
  7002. child_range used_children() {
  7003. return child_range(child_iterator(), child_iterator());
  7004. }
  7005. const_child_range used_children() const {
  7006. return const_child_range(const_child_iterator(), const_child_iterator());
  7007. }
  7008. static bool classof(const OMPClause *T) {
  7009. return T->getClauseKind() == llvm::omp::OMPC_inclusive;
  7010. }
  7011. };
  7012. /// This represents clause 'exclusive' in the '#pragma omp scan' directive.
  7013. ///
  7014. /// \code
  7015. /// #pragma omp scan exclusive(a,b)
  7016. /// \endcode
  7017. /// In this example directive '#pragma omp scan' has clause 'exclusive'
  7018. /// with the variables 'a' and 'b'.
  7019. class OMPExclusiveClause final
  7020. : public OMPVarListClause<OMPExclusiveClause>,
  7021. private llvm::TrailingObjects<OMPExclusiveClause, Expr *> {
  7022. friend class OMPClauseReader;
  7023. friend OMPVarListClause;
  7024. friend TrailingObjects;
  7025. /// Build clause with number of variables \a N.
  7026. ///
  7027. /// \param StartLoc Starting location of the clause.
  7028. /// \param LParenLoc Location of '('.
  7029. /// \param EndLoc Ending location of the clause.
  7030. /// \param N Number of the variables in the clause.
  7031. OMPExclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  7032. SourceLocation EndLoc, unsigned N)
  7033. : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
  7034. StartLoc, LParenLoc, EndLoc, N) {}
  7035. /// Build an empty clause.
  7036. ///
  7037. /// \param N Number of variables.
  7038. explicit OMPExclusiveClause(unsigned N)
  7039. : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
  7040. SourceLocation(), SourceLocation(),
  7041. SourceLocation(), N) {}
  7042. public:
  7043. /// Creates clause with a list of variables \a VL.
  7044. ///
  7045. /// \param C AST context.
  7046. /// \param StartLoc Starting location of the clause.
  7047. /// \param LParenLoc Location of '('.
  7048. /// \param EndLoc Ending location of the clause.
  7049. /// \param VL List of references to the original variables.
  7050. static OMPExclusiveClause *Create(const ASTContext &C,
  7051. SourceLocation StartLoc,
  7052. SourceLocation LParenLoc,
  7053. SourceLocation EndLoc, ArrayRef<Expr *> VL);
  7054. /// Creates an empty clause with the place for \a N variables.
  7055. ///
  7056. /// \param C AST context.
  7057. /// \param N The number of variables.
  7058. static OMPExclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
  7059. child_range children() {
  7060. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  7061. reinterpret_cast<Stmt **>(varlist_end()));
  7062. }
  7063. const_child_range children() const {
  7064. auto Children = const_cast<OMPExclusiveClause *>(this)->children();
  7065. return const_child_range(Children.begin(), Children.end());
  7066. }
  7067. child_range used_children() {
  7068. return child_range(child_iterator(), child_iterator());
  7069. }
  7070. const_child_range used_children() const {
  7071. return const_child_range(const_child_iterator(), const_child_iterator());
  7072. }
  7073. static bool classof(const OMPClause *T) {
  7074. return T->getClauseKind() == llvm::omp::OMPC_exclusive;
  7075. }
  7076. };
  7077. /// This represents clause 'uses_allocators' in the '#pragma omp target'-based
  7078. /// directives.
  7079. ///
  7080. /// \code
  7081. /// #pragma omp target uses_allocators(default_allocator, my_allocator(traits))
  7082. /// \endcode
  7083. /// In this example directive '#pragma omp target' has clause 'uses_allocators'
  7084. /// with the allocators 'default_allocator' and user-defined 'my_allocator'.
  7085. class OMPUsesAllocatorsClause final
  7086. : public OMPClause,
  7087. private llvm::TrailingObjects<OMPUsesAllocatorsClause, Expr *,
  7088. SourceLocation> {
  7089. public:
  7090. /// Data for list of allocators.
  7091. struct Data {
  7092. /// Allocator.
  7093. Expr *Allocator = nullptr;
  7094. /// Allocator traits.
  7095. Expr *AllocatorTraits = nullptr;
  7096. /// Locations of '(' and ')' symbols.
  7097. SourceLocation LParenLoc, RParenLoc;
  7098. };
  7099. private:
  7100. friend class OMPClauseReader;
  7101. friend TrailingObjects;
  7102. enum class ExprOffsets {
  7103. Allocator,
  7104. AllocatorTraits,
  7105. Total,
  7106. };
  7107. enum class ParenLocsOffsets {
  7108. LParen,
  7109. RParen,
  7110. Total,
  7111. };
  7112. /// Location of '('.
  7113. SourceLocation LParenLoc;
  7114. /// Total number of allocators in the clause.
  7115. unsigned NumOfAllocators = 0;
  7116. /// Build clause.
  7117. ///
  7118. /// \param StartLoc Starting location of the clause.
  7119. /// \param LParenLoc Location of '('.
  7120. /// \param EndLoc Ending location of the clause.
  7121. /// \param N Number of allocators associated with the clause.
  7122. OMPUsesAllocatorsClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  7123. SourceLocation EndLoc, unsigned N)
  7124. : OMPClause(llvm::omp::OMPC_uses_allocators, StartLoc, EndLoc),
  7125. LParenLoc(LParenLoc), NumOfAllocators(N) {}
  7126. /// Build an empty clause.
  7127. /// \param N Number of allocators associated with the clause.
  7128. ///
  7129. explicit OMPUsesAllocatorsClause(unsigned N)
  7130. : OMPClause(llvm::omp::OMPC_uses_allocators, SourceLocation(),
  7131. SourceLocation()),
  7132. NumOfAllocators(N) {}
  7133. unsigned numTrailingObjects(OverloadToken<Expr *>) const {
  7134. return NumOfAllocators * static_cast<int>(ExprOffsets::Total);
  7135. }
  7136. /// Sets the location of '('.
  7137. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  7138. /// Sets the allocators data for the clause.
  7139. void setAllocatorsData(ArrayRef<OMPUsesAllocatorsClause::Data> Data);
  7140. public:
  7141. /// Creates clause with a list of allocators \p Data.
  7142. ///
  7143. /// \param C AST context.
  7144. /// \param StartLoc Starting location of the clause.
  7145. /// \param LParenLoc Location of '('.
  7146. /// \param EndLoc Ending location of the clause.
  7147. /// \param Data List of allocators.
  7148. static OMPUsesAllocatorsClause *
  7149. Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  7150. SourceLocation EndLoc, ArrayRef<OMPUsesAllocatorsClause::Data> Data);
  7151. /// Creates an empty clause with the place for \p N allocators.
  7152. ///
  7153. /// \param C AST context.
  7154. /// \param N The number of allocators.
  7155. static OMPUsesAllocatorsClause *CreateEmpty(const ASTContext &C, unsigned N);
  7156. /// Returns the location of '('.
  7157. SourceLocation getLParenLoc() const { return LParenLoc; }
  7158. /// Returns number of allocators associated with the clause.
  7159. unsigned getNumberOfAllocators() const { return NumOfAllocators; }
  7160. /// Returns data for the specified allocator.
  7161. OMPUsesAllocatorsClause::Data getAllocatorData(unsigned I) const;
  7162. // Iterators
  7163. child_range children() {
  7164. Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
  7165. return child_range(Begin, Begin + NumOfAllocators *
  7166. static_cast<int>(ExprOffsets::Total));
  7167. }
  7168. const_child_range children() const {
  7169. Stmt *const *Begin =
  7170. reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
  7171. return const_child_range(
  7172. Begin, Begin + NumOfAllocators * static_cast<int>(ExprOffsets::Total));
  7173. }
  7174. child_range used_children() {
  7175. return child_range(child_iterator(), child_iterator());
  7176. }
  7177. const_child_range used_children() const {
  7178. return const_child_range(const_child_iterator(), const_child_iterator());
  7179. }
  7180. static bool classof(const OMPClause *T) {
  7181. return T->getClauseKind() == llvm::omp::OMPC_uses_allocators;
  7182. }
  7183. };
  7184. /// This represents clause 'affinity' in the '#pragma omp task'-based
  7185. /// directives.
  7186. ///
  7187. /// \code
  7188. /// #pragma omp task affinity(iterator(i = 0:n) : ([3][n])a, b[:n], c[i])
  7189. /// \endcode
  7190. /// In this example directive '#pragma omp task' has clause 'affinity' with the
  7191. /// affinity modifer 'iterator(i = 0:n)' and locator items '([3][n])a', 'b[:n]'
  7192. /// and 'c[i]'.
  7193. class OMPAffinityClause final
  7194. : public OMPVarListClause<OMPAffinityClause>,
  7195. private llvm::TrailingObjects<OMPAffinityClause, Expr *> {
  7196. friend class OMPClauseReader;
  7197. friend OMPVarListClause;
  7198. friend TrailingObjects;
  7199. /// Location of ':' symbol.
  7200. SourceLocation ColonLoc;
  7201. /// Build clause.
  7202. ///
  7203. /// \param StartLoc Starting location of the clause.
  7204. /// \param LParenLoc Location of '('.
  7205. /// \param ColonLoc Location of ':'.
  7206. /// \param EndLoc Ending location of the clause.
  7207. /// \param N Number of locators associated with the clause.
  7208. OMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc,
  7209. SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N)
  7210. : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity, StartLoc,
  7211. LParenLoc, EndLoc, N) {}
  7212. /// Build an empty clause.
  7213. /// \param N Number of locators associated with the clause.
  7214. ///
  7215. explicit OMPAffinityClause(unsigned N)
  7216. : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity,
  7217. SourceLocation(), SourceLocation(),
  7218. SourceLocation(), N) {}
  7219. /// Sets the affinity modifier for the clause, if any.
  7220. void setModifier(Expr *E) {
  7221. getTrailingObjects<Expr *>()[varlist_size()] = E;
  7222. }
  7223. /// Sets the location of ':' symbol.
  7224. void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
  7225. public:
  7226. /// Creates clause with a modifier a list of locator items.
  7227. ///
  7228. /// \param C AST context.
  7229. /// \param StartLoc Starting location of the clause.
  7230. /// \param LParenLoc Location of '('.
  7231. /// \param ColonLoc Location of ':'.
  7232. /// \param EndLoc Ending location of the clause.
  7233. /// \param Locators List of locator items.
  7234. static OMPAffinityClause *Create(const ASTContext &C, SourceLocation StartLoc,
  7235. SourceLocation LParenLoc,
  7236. SourceLocation ColonLoc,
  7237. SourceLocation EndLoc, Expr *Modifier,
  7238. ArrayRef<Expr *> Locators);
  7239. /// Creates an empty clause with the place for \p N locator items.
  7240. ///
  7241. /// \param C AST context.
  7242. /// \param N The number of locator items.
  7243. static OMPAffinityClause *CreateEmpty(const ASTContext &C, unsigned N);
  7244. /// Gets affinity modifier.
  7245. Expr *getModifier() { return getTrailingObjects<Expr *>()[varlist_size()]; }
  7246. Expr *getModifier() const {
  7247. return getTrailingObjects<Expr *>()[varlist_size()];
  7248. }
  7249. /// Gets the location of ':' symbol.
  7250. SourceLocation getColonLoc() const { return ColonLoc; }
  7251. // Iterators
  7252. child_range children() {
  7253. int Offset = getModifier() ? 1 : 0;
  7254. return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
  7255. reinterpret_cast<Stmt **>(varlist_end() + Offset));
  7256. }
  7257. const_child_range children() const {
  7258. auto Children = const_cast<OMPAffinityClause *>(this)->children();
  7259. return const_child_range(Children.begin(), Children.end());
  7260. }
  7261. child_range used_children() {
  7262. return child_range(child_iterator(), child_iterator());
  7263. }
  7264. const_child_range used_children() const {
  7265. return const_child_range(const_child_iterator(), const_child_iterator());
  7266. }
  7267. static bool classof(const OMPClause *T) {
  7268. return T->getClauseKind() == llvm::omp::OMPC_affinity;
  7269. }
  7270. };
  7271. /// This represents 'filter' clause in the '#pragma omp ...' directive.
  7272. ///
  7273. /// \code
  7274. /// #pragma omp masked filter(tid)
  7275. /// \endcode
  7276. /// In this example directive '#pragma omp masked' has 'filter' clause with
  7277. /// thread id.
  7278. class OMPFilterClause final
  7279. : public OMPOneStmtClause<llvm::omp::OMPC_filter, OMPClause>,
  7280. public OMPClauseWithPreInit {
  7281. friend class OMPClauseReader;
  7282. /// Sets the thread identifier.
  7283. void setThreadID(Expr *TID) { setStmt(TID); }
  7284. public:
  7285. /// Build 'filter' clause with thread-id \a ThreadID.
  7286. ///
  7287. /// \param ThreadID Thread identifier.
  7288. /// \param HelperE Helper expression associated with this clause.
  7289. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  7290. /// clause must be captured.
  7291. /// \param StartLoc Starting location of the clause.
  7292. /// \param LParenLoc Location of '('.
  7293. /// \param EndLoc Ending location of the clause.
  7294. OMPFilterClause(Expr *ThreadID, Stmt *HelperE,
  7295. OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
  7296. SourceLocation LParenLoc, SourceLocation EndLoc)
  7297. : OMPOneStmtClause(ThreadID, StartLoc, LParenLoc, EndLoc),
  7298. OMPClauseWithPreInit(this) {
  7299. setPreInitStmt(HelperE, CaptureRegion);
  7300. }
  7301. /// Build an empty clause.
  7302. OMPFilterClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
  7303. /// Return thread identifier.
  7304. Expr *getThreadID() const { return getStmtAs<Expr>(); }
  7305. /// Return thread identifier.
  7306. Expr *getThreadID() { return getStmtAs<Expr>(); }
  7307. };
  7308. /// This represents 'bind' clause in the '#pragma omp ...' directives.
  7309. ///
  7310. /// \code
  7311. /// #pragma omp loop bind(parallel)
  7312. /// \endcode
  7313. class OMPBindClause final : public OMPNoChildClause<llvm::omp::OMPC_bind> {
  7314. friend class OMPClauseReader;
  7315. /// Location of '('.
  7316. SourceLocation LParenLoc;
  7317. /// The binding kind of 'bind' clause.
  7318. OpenMPBindClauseKind Kind = OMPC_BIND_unknown;
  7319. /// Start location of the kind in source code.
  7320. SourceLocation KindLoc;
  7321. /// Sets the location of '('.
  7322. void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
  7323. /// Set the binding kind.
  7324. void setBindKind(OpenMPBindClauseKind K) { Kind = K; }
  7325. /// Set the binding kind location.
  7326. void setBindKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
  7327. /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread').
  7328. ///
  7329. /// \param K Binding kind of the clause ('teams', 'parallel' or 'thread').
  7330. /// \param KLoc Starting location of the binding kind.
  7331. /// \param StartLoc Starting location of the clause.
  7332. /// \param LParenLoc Location of '('.
  7333. /// \param EndLoc Ending location of the clause.
  7334. OMPBindClause(OpenMPBindClauseKind K, SourceLocation KLoc,
  7335. SourceLocation StartLoc, SourceLocation LParenLoc,
  7336. SourceLocation EndLoc)
  7337. : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Kind(K),
  7338. KindLoc(KLoc) {}
  7339. /// Build an empty clause.
  7340. OMPBindClause() : OMPNoChildClause() {}
  7341. public:
  7342. /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread').
  7343. ///
  7344. /// \param C AST context
  7345. /// \param K Binding kind of the clause ('teams', 'parallel' or 'thread').
  7346. /// \param KLoc Starting location of the binding kind.
  7347. /// \param StartLoc Starting location of the clause.
  7348. /// \param LParenLoc Location of '('.
  7349. /// \param EndLoc Ending location of the clause.
  7350. static OMPBindClause *Create(const ASTContext &C, OpenMPBindClauseKind K,
  7351. SourceLocation KLoc, SourceLocation StartLoc,
  7352. SourceLocation LParenLoc, SourceLocation EndLoc);
  7353. /// Build an empty 'bind' clause.
  7354. ///
  7355. /// \param C AST context
  7356. static OMPBindClause *CreateEmpty(const ASTContext &C);
  7357. /// Returns the location of '('.
  7358. SourceLocation getLParenLoc() const { return LParenLoc; }
  7359. /// Returns kind of the clause.
  7360. OpenMPBindClauseKind getBindKind() const { return Kind; }
  7361. /// Returns location of clause kind.
  7362. SourceLocation getBindKindLoc() const { return KindLoc; }
  7363. };
  7364. /// This class implements a simple visitor for OMPClause
  7365. /// subclasses.
  7366. template<class ImplClass, template <typename> class Ptr, typename RetTy>
  7367. class OMPClauseVisitorBase {
  7368. public:
  7369. #define PTR(CLASS) Ptr<CLASS>
  7370. #define DISPATCH(CLASS) \
  7371. return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
  7372. #define GEN_CLANG_CLAUSE_CLASS
  7373. #define CLAUSE_CLASS(Enum, Str, Class) \
  7374. RetTy Visit##Class(PTR(Class) S) { DISPATCH(Class); }
  7375. #include "llvm/Frontend/OpenMP/OMP.inc"
  7376. RetTy Visit(PTR(OMPClause) S) {
  7377. // Top switch clause: visit each OMPClause.
  7378. switch (S->getClauseKind()) {
  7379. #define GEN_CLANG_CLAUSE_CLASS
  7380. #define CLAUSE_CLASS(Enum, Str, Class) \
  7381. case llvm::omp::Clause::Enum: \
  7382. return Visit##Class(static_cast<PTR(Class)>(S));
  7383. #define CLAUSE_NO_CLASS(Enum, Str) \
  7384. case llvm::omp::Clause::Enum: \
  7385. break;
  7386. #include "llvm/Frontend/OpenMP/OMP.inc"
  7387. }
  7388. }
  7389. // Base case, ignore it. :)
  7390. RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
  7391. #undef PTR
  7392. #undef DISPATCH
  7393. };
  7394. template <typename T> using const_ptr = std::add_pointer_t<std::add_const_t<T>>;
  7395. template <class ImplClass, typename RetTy = void>
  7396. class OMPClauseVisitor
  7397. : public OMPClauseVisitorBase<ImplClass, std::add_pointer_t, RetTy> {};
  7398. template<class ImplClass, typename RetTy = void>
  7399. class ConstOMPClauseVisitor :
  7400. public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
  7401. class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
  7402. raw_ostream &OS;
  7403. const PrintingPolicy &Policy;
  7404. /// Process clauses with list of variables.
  7405. template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
  7406. /// Process motion clauses.
  7407. template <typename T> void VisitOMPMotionClause(T *Node);
  7408. public:
  7409. OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
  7410. : OS(OS), Policy(Policy) {}
  7411. #define GEN_CLANG_CLAUSE_CLASS
  7412. #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
  7413. #include "llvm/Frontend/OpenMP/OMP.inc"
  7414. };
  7415. struct OMPTraitProperty {
  7416. llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
  7417. /// The raw string as we parsed it. This is needed for the `isa` trait set
  7418. /// (which accepts anything) and (later) extensions.
  7419. StringRef RawString;
  7420. };
  7421. struct OMPTraitSelector {
  7422. Expr *ScoreOrCondition = nullptr;
  7423. llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
  7424. llvm::SmallVector<OMPTraitProperty, 1> Properties;
  7425. };
  7426. struct OMPTraitSet {
  7427. llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
  7428. llvm::SmallVector<OMPTraitSelector, 2> Selectors;
  7429. };
  7430. /// Helper data structure representing the traits in a match clause of an
  7431. /// `declare variant` or `metadirective`. The outer level is an ordered
  7432. /// collection of selector sets, each with an associated kind and an ordered
  7433. /// collection of selectors. A selector has a kind, an optional score/condition,
  7434. /// and an ordered collection of properties.
  7435. class OMPTraitInfo {
  7436. /// Private constructor accesible only by ASTContext.
  7437. OMPTraitInfo() {}
  7438. friend class ASTContext;
  7439. public:
  7440. /// Reconstruct a (partial) OMPTraitInfo object from a mangled name.
  7441. OMPTraitInfo(StringRef MangledName);
  7442. /// The outermost level of selector sets.
  7443. llvm::SmallVector<OMPTraitSet, 2> Sets;
  7444. bool anyScoreOrCondition(
  7445. llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) {
  7446. return llvm::any_of(Sets, [&](OMPTraitSet &Set) {
  7447. return llvm::any_of(
  7448. Set.Selectors, [&](OMPTraitSelector &Selector) {
  7449. return Cond(Selector.ScoreOrCondition,
  7450. /* IsScore */ Selector.Kind !=
  7451. llvm::omp::TraitSelector::user_condition);
  7452. });
  7453. });
  7454. }
  7455. /// Create a variant match info object from this trait info object. While the
  7456. /// former is a flat representation the actual main difference is that the
  7457. /// latter uses clang::Expr to store the score/condition while the former is
  7458. /// independent of clang. Thus, expressions and conditions are evaluated in
  7459. /// this method.
  7460. void getAsVariantMatchInfo(ASTContext &ASTCtx,
  7461. llvm::omp::VariantMatchInfo &VMI) const;
  7462. /// Return a string representation identifying this context selector.
  7463. std::string getMangledName() const;
  7464. /// Check the extension trait \p TP is active.
  7465. bool isExtensionActive(llvm::omp::TraitProperty TP) {
  7466. for (const OMPTraitSet &Set : Sets) {
  7467. if (Set.Kind != llvm::omp::TraitSet::implementation)
  7468. continue;
  7469. for (const OMPTraitSelector &Selector : Set.Selectors) {
  7470. if (Selector.Kind != llvm::omp::TraitSelector::implementation_extension)
  7471. continue;
  7472. for (const OMPTraitProperty &Property : Selector.Properties) {
  7473. if (Property.Kind == TP)
  7474. return true;
  7475. }
  7476. }
  7477. }
  7478. return false;
  7479. }
  7480. /// Print a human readable representation into \p OS.
  7481. void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
  7482. };
  7483. llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
  7484. llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
  7485. /// Clang specific specialization of the OMPContext to lookup target features.
  7486. struct TargetOMPContext final : public llvm::omp::OMPContext {
  7487. TargetOMPContext(ASTContext &ASTCtx,
  7488. std::function<void(StringRef)> &&DiagUnknownTrait,
  7489. const FunctionDecl *CurrentFunctionDecl,
  7490. ArrayRef<llvm::omp::TraitProperty> ConstructTraits);
  7491. virtual ~TargetOMPContext() = default;
  7492. /// See llvm::omp::OMPContext::matchesISATrait
  7493. bool matchesISATrait(StringRef RawString) const override;
  7494. private:
  7495. std::function<bool(StringRef)> FeatureValidityCheck;
  7496. std::function<void(StringRef)> DiagUnknownTrait;
  7497. llvm::StringMap<bool> FeatureMap;
  7498. };
  7499. /// Contains data for OpenMP directives: clauses, children
  7500. /// expressions/statements (helpers for codegen) and associated statement, if
  7501. /// any.
  7502. class OMPChildren final
  7503. : private llvm::TrailingObjects<OMPChildren, OMPClause *, Stmt *> {
  7504. friend TrailingObjects;
  7505. friend class OMPClauseReader;
  7506. friend class OMPExecutableDirective;
  7507. template <typename T> friend class OMPDeclarativeDirective;
  7508. /// Numbers of clauses.
  7509. unsigned NumClauses = 0;
  7510. /// Number of child expressions/stmts.
  7511. unsigned NumChildren = 0;
  7512. /// true if the directive has associated statement.
  7513. bool HasAssociatedStmt = false;
  7514. /// Define the sizes of each trailing object array except the last one. This
  7515. /// is required for TrailingObjects to work properly.
  7516. size_t numTrailingObjects(OverloadToken<OMPClause *>) const {
  7517. return NumClauses;
  7518. }
  7519. OMPChildren() = delete;
  7520. OMPChildren(unsigned NumClauses, unsigned NumChildren, bool HasAssociatedStmt)
  7521. : NumClauses(NumClauses), NumChildren(NumChildren),
  7522. HasAssociatedStmt(HasAssociatedStmt) {}
  7523. static size_t size(unsigned NumClauses, bool HasAssociatedStmt,
  7524. unsigned NumChildren);
  7525. static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses);
  7526. static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses, Stmt *S,
  7527. unsigned NumChildren = 0);
  7528. static OMPChildren *CreateEmpty(void *Mem, unsigned NumClauses,
  7529. bool HasAssociatedStmt = false,
  7530. unsigned NumChildren = 0);
  7531. public:
  7532. unsigned getNumClauses() const { return NumClauses; }
  7533. unsigned getNumChildren() const { return NumChildren; }
  7534. bool hasAssociatedStmt() const { return HasAssociatedStmt; }
  7535. /// Set associated statement.
  7536. void setAssociatedStmt(Stmt *S) {
  7537. getTrailingObjects<Stmt *>()[NumChildren] = S;
  7538. }
  7539. void setChildren(ArrayRef<Stmt *> Children);
  7540. /// Sets the list of variables for this clause.
  7541. ///
  7542. /// \param Clauses The list of clauses for the directive.
  7543. ///
  7544. void setClauses(ArrayRef<OMPClause *> Clauses);
  7545. /// Returns statement associated with the directive.
  7546. const Stmt *getAssociatedStmt() const {
  7547. return const_cast<OMPChildren *>(this)->getAssociatedStmt();
  7548. }
  7549. Stmt *getAssociatedStmt() {
  7550. assert(HasAssociatedStmt &&
  7551. "Expected directive with the associated statement.");
  7552. return getTrailingObjects<Stmt *>()[NumChildren];
  7553. }
  7554. /// Get the clauses storage.
  7555. MutableArrayRef<OMPClause *> getClauses() {
  7556. return llvm::MutableArrayRef(getTrailingObjects<OMPClause *>(),
  7557. NumClauses);
  7558. }
  7559. ArrayRef<OMPClause *> getClauses() const {
  7560. return const_cast<OMPChildren *>(this)->getClauses();
  7561. }
  7562. /// Returns the captured statement associated with the
  7563. /// component region within the (combined) directive.
  7564. ///
  7565. /// \param RegionKind Component region kind.
  7566. const CapturedStmt *
  7567. getCapturedStmt(OpenMPDirectiveKind RegionKind,
  7568. ArrayRef<OpenMPDirectiveKind> CaptureRegions) const {
  7569. assert(llvm::is_contained(CaptureRegions, RegionKind) &&
  7570. "RegionKind not found in OpenMP CaptureRegions.");
  7571. auto *CS = cast<CapturedStmt>(getAssociatedStmt());
  7572. for (auto ThisCaptureRegion : CaptureRegions) {
  7573. if (ThisCaptureRegion == RegionKind)
  7574. return CS;
  7575. CS = cast<CapturedStmt>(CS->getCapturedStmt());
  7576. }
  7577. llvm_unreachable("Incorrect RegionKind specified for directive.");
  7578. }
  7579. /// Get innermost captured statement for the construct.
  7580. CapturedStmt *
  7581. getInnermostCapturedStmt(ArrayRef<OpenMPDirectiveKind> CaptureRegions) {
  7582. assert(hasAssociatedStmt() && "Must have associated captured statement.");
  7583. assert(!CaptureRegions.empty() &&
  7584. "At least one captured statement must be provided.");
  7585. auto *CS = cast<CapturedStmt>(getAssociatedStmt());
  7586. for (unsigned Level = CaptureRegions.size(); Level > 1; --Level)
  7587. CS = cast<CapturedStmt>(CS->getCapturedStmt());
  7588. return CS;
  7589. }
  7590. const CapturedStmt *
  7591. getInnermostCapturedStmt(ArrayRef<OpenMPDirectiveKind> CaptureRegions) const {
  7592. return const_cast<OMPChildren *>(this)->getInnermostCapturedStmt(
  7593. CaptureRegions);
  7594. }
  7595. MutableArrayRef<Stmt *> getChildren();
  7596. ArrayRef<Stmt *> getChildren() const {
  7597. return const_cast<OMPChildren *>(this)->getChildren();
  7598. }
  7599. Stmt *getRawStmt() {
  7600. assert(HasAssociatedStmt &&
  7601. "Expected directive with the associated statement.");
  7602. if (auto *CS = dyn_cast<CapturedStmt>(getAssociatedStmt())) {
  7603. Stmt *S = nullptr;
  7604. do {
  7605. S = CS->getCapturedStmt();
  7606. CS = dyn_cast<CapturedStmt>(S);
  7607. } while (CS);
  7608. return S;
  7609. }
  7610. return getAssociatedStmt();
  7611. }
  7612. const Stmt *getRawStmt() const {
  7613. return const_cast<OMPChildren *>(this)->getRawStmt();
  7614. }
  7615. Stmt::child_range getAssociatedStmtAsRange() {
  7616. if (!HasAssociatedStmt)
  7617. return Stmt::child_range(Stmt::child_iterator(), Stmt::child_iterator());
  7618. return Stmt::child_range(&getTrailingObjects<Stmt *>()[NumChildren],
  7619. &getTrailingObjects<Stmt *>()[NumChildren + 1]);
  7620. }
  7621. };
  7622. /// This represents 'ompx_dyn_cgroup_mem' clause in the '#pragma omp target ...'
  7623. /// directive.
  7624. ///
  7625. /// \code
  7626. /// #pragma omp target [...] ompx_dyn_cgroup_mem(N)
  7627. /// \endcode
  7628. class OMPXDynCGroupMemClause
  7629. : public OMPOneStmtClause<llvm::omp::OMPC_ompx_dyn_cgroup_mem, OMPClause>,
  7630. public OMPClauseWithPreInit {
  7631. friend class OMPClauseReader;
  7632. /// Set size.
  7633. void setSize(Expr *E) { setStmt(E); }
  7634. public:
  7635. /// Build 'ompx_dyn_cgroup_mem' clause.
  7636. ///
  7637. /// \param Size Size expression.
  7638. /// \param HelperSize Helper Size expression
  7639. /// \param CaptureRegion Innermost OpenMP region where expressions in this
  7640. /// \param StartLoc Starting location of the clause.
  7641. /// \param LParenLoc Location of '('.
  7642. /// \param EndLoc Ending location of the clause.
  7643. OMPXDynCGroupMemClause(Expr *Size, Stmt *HelperSize,
  7644. OpenMPDirectiveKind CaptureRegion,
  7645. SourceLocation StartLoc, SourceLocation LParenLoc,
  7646. SourceLocation EndLoc)
  7647. : OMPOneStmtClause(Size, StartLoc, LParenLoc, EndLoc),
  7648. OMPClauseWithPreInit(this) {
  7649. setPreInitStmt(HelperSize, CaptureRegion);
  7650. }
  7651. /// Build an empty clause.
  7652. OMPXDynCGroupMemClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
  7653. /// Return the size expression.
  7654. Expr *getSize() { return getStmtAs<Expr>(); }
  7655. /// Return the size expression.
  7656. Expr *getSize() const { return getStmtAs<Expr>(); }
  7657. };
  7658. } // namespace clang
  7659. #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H
  7660. #ifdef __GNUC__
  7661. #pragma GCC diagnostic pop
  7662. #endif