OpenMPClause.h 320 KB

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