OpenMPClause.cpp 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664
  1. //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the subclesses of Stmt class declared in OpenMPClause.h
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/AST/OpenMPClause.h"
  13. #include "clang/AST/ASTContext.h"
  14. #include "clang/AST/Attr.h"
  15. #include "clang/AST/Decl.h"
  16. #include "clang/AST/DeclOpenMP.h"
  17. #include "clang/Basic/LLVM.h"
  18. #include "clang/Basic/OpenMPKinds.h"
  19. #include "clang/Basic/TargetInfo.h"
  20. #include "llvm/ADT/SmallPtrSet.h"
  21. #include "llvm/Support/Casting.h"
  22. #include "llvm/Support/ErrorHandling.h"
  23. #include <algorithm>
  24. #include <cassert>
  25. #include <optional>
  26. using namespace clang;
  27. using namespace llvm;
  28. using namespace omp;
  29. OMPClause::child_range OMPClause::children() {
  30. switch (getClauseKind()) {
  31. default:
  32. break;
  33. #define GEN_CLANG_CLAUSE_CLASS
  34. #define CLAUSE_CLASS(Enum, Str, Class) \
  35. case Enum: \
  36. return static_cast<Class *>(this)->children();
  37. #include "llvm/Frontend/OpenMP/OMP.inc"
  38. }
  39. llvm_unreachable("unknown OMPClause");
  40. }
  41. OMPClause::child_range OMPClause::used_children() {
  42. switch (getClauseKind()) {
  43. #define GEN_CLANG_CLAUSE_CLASS
  44. #define CLAUSE_CLASS(Enum, Str, Class) \
  45. case Enum: \
  46. return static_cast<Class *>(this)->used_children();
  47. #define CLAUSE_NO_CLASS(Enum, Str) \
  48. case Enum: \
  49. break;
  50. #include "llvm/Frontend/OpenMP/OMP.inc"
  51. }
  52. llvm_unreachable("unknown OMPClause");
  53. }
  54. OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
  55. auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
  56. return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
  57. }
  58. const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
  59. switch (C->getClauseKind()) {
  60. case OMPC_schedule:
  61. return static_cast<const OMPScheduleClause *>(C);
  62. case OMPC_dist_schedule:
  63. return static_cast<const OMPDistScheduleClause *>(C);
  64. case OMPC_firstprivate:
  65. return static_cast<const OMPFirstprivateClause *>(C);
  66. case OMPC_lastprivate:
  67. return static_cast<const OMPLastprivateClause *>(C);
  68. case OMPC_reduction:
  69. return static_cast<const OMPReductionClause *>(C);
  70. case OMPC_task_reduction:
  71. return static_cast<const OMPTaskReductionClause *>(C);
  72. case OMPC_in_reduction:
  73. return static_cast<const OMPInReductionClause *>(C);
  74. case OMPC_linear:
  75. return static_cast<const OMPLinearClause *>(C);
  76. case OMPC_if:
  77. return static_cast<const OMPIfClause *>(C);
  78. case OMPC_num_threads:
  79. return static_cast<const OMPNumThreadsClause *>(C);
  80. case OMPC_num_teams:
  81. return static_cast<const OMPNumTeamsClause *>(C);
  82. case OMPC_thread_limit:
  83. return static_cast<const OMPThreadLimitClause *>(C);
  84. case OMPC_device:
  85. return static_cast<const OMPDeviceClause *>(C);
  86. case OMPC_grainsize:
  87. return static_cast<const OMPGrainsizeClause *>(C);
  88. case OMPC_num_tasks:
  89. return static_cast<const OMPNumTasksClause *>(C);
  90. case OMPC_final:
  91. return static_cast<const OMPFinalClause *>(C);
  92. case OMPC_priority:
  93. return static_cast<const OMPPriorityClause *>(C);
  94. case OMPC_novariants:
  95. return static_cast<const OMPNovariantsClause *>(C);
  96. case OMPC_nocontext:
  97. return static_cast<const OMPNocontextClause *>(C);
  98. case OMPC_filter:
  99. return static_cast<const OMPFilterClause *>(C);
  100. case OMPC_ompx_dyn_cgroup_mem:
  101. return static_cast<const OMPXDynCGroupMemClause *>(C);
  102. case OMPC_default:
  103. case OMPC_proc_bind:
  104. case OMPC_safelen:
  105. case OMPC_simdlen:
  106. case OMPC_sizes:
  107. case OMPC_allocator:
  108. case OMPC_allocate:
  109. case OMPC_collapse:
  110. case OMPC_private:
  111. case OMPC_shared:
  112. case OMPC_aligned:
  113. case OMPC_copyin:
  114. case OMPC_copyprivate:
  115. case OMPC_ordered:
  116. case OMPC_nowait:
  117. case OMPC_untied:
  118. case OMPC_mergeable:
  119. case OMPC_threadprivate:
  120. case OMPC_flush:
  121. case OMPC_depobj:
  122. case OMPC_read:
  123. case OMPC_write:
  124. case OMPC_update:
  125. case OMPC_capture:
  126. case OMPC_compare:
  127. case OMPC_seq_cst:
  128. case OMPC_acq_rel:
  129. case OMPC_acquire:
  130. case OMPC_release:
  131. case OMPC_relaxed:
  132. case OMPC_depend:
  133. case OMPC_threads:
  134. case OMPC_simd:
  135. case OMPC_map:
  136. case OMPC_nogroup:
  137. case OMPC_hint:
  138. case OMPC_defaultmap:
  139. case OMPC_unknown:
  140. case OMPC_uniform:
  141. case OMPC_to:
  142. case OMPC_from:
  143. case OMPC_use_device_ptr:
  144. case OMPC_use_device_addr:
  145. case OMPC_is_device_ptr:
  146. case OMPC_has_device_addr:
  147. case OMPC_unified_address:
  148. case OMPC_unified_shared_memory:
  149. case OMPC_reverse_offload:
  150. case OMPC_dynamic_allocators:
  151. case OMPC_atomic_default_mem_order:
  152. case OMPC_at:
  153. case OMPC_severity:
  154. case OMPC_message:
  155. case OMPC_device_type:
  156. case OMPC_match:
  157. case OMPC_nontemporal:
  158. case OMPC_order:
  159. case OMPC_destroy:
  160. case OMPC_detach:
  161. case OMPC_inclusive:
  162. case OMPC_exclusive:
  163. case OMPC_uses_allocators:
  164. case OMPC_affinity:
  165. case OMPC_when:
  166. case OMPC_bind:
  167. break;
  168. default:
  169. break;
  170. }
  171. return nullptr;
  172. }
  173. OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
  174. auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
  175. return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
  176. }
  177. const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
  178. switch (C->getClauseKind()) {
  179. case OMPC_lastprivate:
  180. return static_cast<const OMPLastprivateClause *>(C);
  181. case OMPC_reduction:
  182. return static_cast<const OMPReductionClause *>(C);
  183. case OMPC_task_reduction:
  184. return static_cast<const OMPTaskReductionClause *>(C);
  185. case OMPC_in_reduction:
  186. return static_cast<const OMPInReductionClause *>(C);
  187. case OMPC_linear:
  188. return static_cast<const OMPLinearClause *>(C);
  189. case OMPC_schedule:
  190. case OMPC_dist_schedule:
  191. case OMPC_firstprivate:
  192. case OMPC_default:
  193. case OMPC_proc_bind:
  194. case OMPC_if:
  195. case OMPC_final:
  196. case OMPC_num_threads:
  197. case OMPC_safelen:
  198. case OMPC_simdlen:
  199. case OMPC_sizes:
  200. case OMPC_allocator:
  201. case OMPC_allocate:
  202. case OMPC_collapse:
  203. case OMPC_private:
  204. case OMPC_shared:
  205. case OMPC_aligned:
  206. case OMPC_copyin:
  207. case OMPC_copyprivate:
  208. case OMPC_ordered:
  209. case OMPC_nowait:
  210. case OMPC_untied:
  211. case OMPC_mergeable:
  212. case OMPC_threadprivate:
  213. case OMPC_flush:
  214. case OMPC_depobj:
  215. case OMPC_read:
  216. case OMPC_write:
  217. case OMPC_update:
  218. case OMPC_capture:
  219. case OMPC_compare:
  220. case OMPC_seq_cst:
  221. case OMPC_acq_rel:
  222. case OMPC_acquire:
  223. case OMPC_release:
  224. case OMPC_relaxed:
  225. case OMPC_depend:
  226. case OMPC_device:
  227. case OMPC_threads:
  228. case OMPC_simd:
  229. case OMPC_map:
  230. case OMPC_num_teams:
  231. case OMPC_thread_limit:
  232. case OMPC_priority:
  233. case OMPC_grainsize:
  234. case OMPC_nogroup:
  235. case OMPC_num_tasks:
  236. case OMPC_hint:
  237. case OMPC_defaultmap:
  238. case OMPC_unknown:
  239. case OMPC_uniform:
  240. case OMPC_to:
  241. case OMPC_from:
  242. case OMPC_use_device_ptr:
  243. case OMPC_use_device_addr:
  244. case OMPC_is_device_ptr:
  245. case OMPC_has_device_addr:
  246. case OMPC_unified_address:
  247. case OMPC_unified_shared_memory:
  248. case OMPC_reverse_offload:
  249. case OMPC_dynamic_allocators:
  250. case OMPC_atomic_default_mem_order:
  251. case OMPC_at:
  252. case OMPC_severity:
  253. case OMPC_message:
  254. case OMPC_device_type:
  255. case OMPC_match:
  256. case OMPC_nontemporal:
  257. case OMPC_order:
  258. case OMPC_destroy:
  259. case OMPC_novariants:
  260. case OMPC_nocontext:
  261. case OMPC_detach:
  262. case OMPC_inclusive:
  263. case OMPC_exclusive:
  264. case OMPC_uses_allocators:
  265. case OMPC_affinity:
  266. case OMPC_when:
  267. case OMPC_bind:
  268. break;
  269. default:
  270. break;
  271. }
  272. return nullptr;
  273. }
  274. /// Gets the address of the original, non-captured, expression used in the
  275. /// clause as the preinitializer.
  276. static Stmt **getAddrOfExprAsWritten(Stmt *S) {
  277. if (!S)
  278. return nullptr;
  279. if (auto *DS = dyn_cast<DeclStmt>(S)) {
  280. assert(DS->isSingleDecl() && "Only single expression must be captured.");
  281. if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
  282. return OED->getInitAddress();
  283. }
  284. return nullptr;
  285. }
  286. OMPClause::child_range OMPIfClause::used_children() {
  287. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  288. return child_range(C, C + 1);
  289. return child_range(&Condition, &Condition + 1);
  290. }
  291. OMPClause::child_range OMPGrainsizeClause::used_children() {
  292. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  293. return child_range(C, C + 1);
  294. return child_range(&Grainsize, &Grainsize + 1);
  295. }
  296. OMPClause::child_range OMPNumTasksClause::used_children() {
  297. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  298. return child_range(C, C + 1);
  299. return child_range(&NumTasks, &NumTasks + 1);
  300. }
  301. OMPClause::child_range OMPFinalClause::used_children() {
  302. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  303. return child_range(C, C + 1);
  304. return children();
  305. }
  306. OMPClause::child_range OMPPriorityClause::used_children() {
  307. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  308. return child_range(C, C + 1);
  309. return child_range(&Priority, &Priority + 1);
  310. }
  311. OMPClause::child_range OMPNovariantsClause::used_children() {
  312. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  313. return child_range(C, C + 1);
  314. return children();
  315. }
  316. OMPClause::child_range OMPNocontextClause::used_children() {
  317. if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
  318. return child_range(C, C + 1);
  319. return children();
  320. }
  321. OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
  322. unsigned NumLoops,
  323. SourceLocation StartLoc,
  324. SourceLocation LParenLoc,
  325. SourceLocation EndLoc) {
  326. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
  327. auto *Clause =
  328. new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
  329. for (unsigned I = 0; I < NumLoops; ++I) {
  330. Clause->setLoopNumIterations(I, nullptr);
  331. Clause->setLoopCounter(I, nullptr);
  332. }
  333. return Clause;
  334. }
  335. OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
  336. unsigned NumLoops) {
  337. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
  338. auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
  339. for (unsigned I = 0; I < NumLoops; ++I) {
  340. Clause->setLoopNumIterations(I, nullptr);
  341. Clause->setLoopCounter(I, nullptr);
  342. }
  343. return Clause;
  344. }
  345. void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
  346. Expr *NumIterations) {
  347. assert(NumLoop < NumberOfLoops && "out of loops number.");
  348. getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
  349. }
  350. ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
  351. return llvm::ArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
  352. }
  353. void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
  354. assert(NumLoop < NumberOfLoops && "out of loops number.");
  355. getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
  356. }
  357. Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
  358. assert(NumLoop < NumberOfLoops && "out of loops number.");
  359. return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
  360. }
  361. const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
  362. assert(NumLoop < NumberOfLoops && "out of loops number.");
  363. return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
  364. }
  365. OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
  366. SourceLocation StartLoc,
  367. SourceLocation EndLoc) {
  368. return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false);
  369. }
  370. OMPUpdateClause *
  371. OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  372. SourceLocation LParenLoc, SourceLocation ArgumentLoc,
  373. OpenMPDependClauseKind DK, SourceLocation EndLoc) {
  374. void *Mem =
  375. C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
  376. alignof(OMPUpdateClause));
  377. auto *Clause =
  378. new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true);
  379. Clause->setLParenLoc(LParenLoc);
  380. Clause->setArgumentLoc(ArgumentLoc);
  381. Clause->setDependencyKind(DK);
  382. return Clause;
  383. }
  384. OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C,
  385. bool IsExtended) {
  386. if (!IsExtended)
  387. return new (C) OMPUpdateClause(/*IsExtended=*/false);
  388. void *Mem =
  389. C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1),
  390. alignof(OMPUpdateClause));
  391. auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true);
  392. Clause->IsExtended = true;
  393. return Clause;
  394. }
  395. void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  396. assert(VL.size() == varlist_size() &&
  397. "Number of private copies is not the same as the preallocated buffer");
  398. std::copy(VL.begin(), VL.end(), varlist_end());
  399. }
  400. OMPPrivateClause *
  401. OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  402. SourceLocation LParenLoc, SourceLocation EndLoc,
  403. ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
  404. // Allocate space for private variables and initializer expressions.
  405. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
  406. OMPPrivateClause *Clause =
  407. new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  408. Clause->setVarRefs(VL);
  409. Clause->setPrivateCopies(PrivateVL);
  410. return Clause;
  411. }
  412. OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
  413. unsigned N) {
  414. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
  415. return new (Mem) OMPPrivateClause(N);
  416. }
  417. void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  418. assert(VL.size() == varlist_size() &&
  419. "Number of private copies is not the same as the preallocated buffer");
  420. std::copy(VL.begin(), VL.end(), varlist_end());
  421. }
  422. void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
  423. assert(VL.size() == varlist_size() &&
  424. "Number of inits is not the same as the preallocated buffer");
  425. std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
  426. }
  427. OMPFirstprivateClause *
  428. OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  429. SourceLocation LParenLoc, SourceLocation EndLoc,
  430. ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
  431. ArrayRef<Expr *> InitVL, Stmt *PreInit) {
  432. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
  433. OMPFirstprivateClause *Clause =
  434. new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  435. Clause->setVarRefs(VL);
  436. Clause->setPrivateCopies(PrivateVL);
  437. Clause->setInits(InitVL);
  438. Clause->setPreInitStmt(PreInit);
  439. return Clause;
  440. }
  441. OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
  442. unsigned N) {
  443. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
  444. return new (Mem) OMPFirstprivateClause(N);
  445. }
  446. void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
  447. assert(PrivateCopies.size() == varlist_size() &&
  448. "Number of private copies is not the same as the preallocated buffer");
  449. std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
  450. }
  451. void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  452. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  453. "not the same as the "
  454. "preallocated buffer");
  455. std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
  456. }
  457. void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  458. assert(DstExprs.size() == varlist_size() && "Number of destination "
  459. "expressions is not the same as "
  460. "the preallocated buffer");
  461. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  462. }
  463. void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  464. assert(AssignmentOps.size() == varlist_size() &&
  465. "Number of assignment expressions is not the same as the preallocated "
  466. "buffer");
  467. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  468. getDestinationExprs().end());
  469. }
  470. OMPLastprivateClause *OMPLastprivateClause::Create(
  471. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  472. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  473. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
  474. OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
  475. SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
  476. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  477. OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
  478. StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
  479. Clause->setVarRefs(VL);
  480. Clause->setSourceExprs(SrcExprs);
  481. Clause->setDestinationExprs(DstExprs);
  482. Clause->setAssignmentOps(AssignmentOps);
  483. Clause->setPreInitStmt(PreInit);
  484. Clause->setPostUpdateExpr(PostUpdate);
  485. return Clause;
  486. }
  487. OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
  488. unsigned N) {
  489. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  490. return new (Mem) OMPLastprivateClause(N);
  491. }
  492. OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
  493. SourceLocation StartLoc,
  494. SourceLocation LParenLoc,
  495. SourceLocation EndLoc,
  496. ArrayRef<Expr *> VL) {
  497. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
  498. OMPSharedClause *Clause =
  499. new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
  500. Clause->setVarRefs(VL);
  501. return Clause;
  502. }
  503. OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
  504. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  505. return new (Mem) OMPSharedClause(N);
  506. }
  507. void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
  508. assert(PL.size() == varlist_size() &&
  509. "Number of privates is not the same as the preallocated buffer");
  510. std::copy(PL.begin(), PL.end(), varlist_end());
  511. }
  512. void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
  513. assert(IL.size() == varlist_size() &&
  514. "Number of inits is not the same as the preallocated buffer");
  515. std::copy(IL.begin(), IL.end(), getPrivates().end());
  516. }
  517. void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
  518. assert(UL.size() == varlist_size() &&
  519. "Number of updates is not the same as the preallocated buffer");
  520. std::copy(UL.begin(), UL.end(), getInits().end());
  521. }
  522. void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
  523. assert(FL.size() == varlist_size() &&
  524. "Number of final updates is not the same as the preallocated buffer");
  525. std::copy(FL.begin(), FL.end(), getUpdates().end());
  526. }
  527. void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
  528. assert(
  529. UE.size() == varlist_size() + 1 &&
  530. "Number of used expressions is not the same as the preallocated buffer");
  531. std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
  532. }
  533. OMPLinearClause *OMPLinearClause::Create(
  534. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  535. OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
  536. SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
  537. ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
  538. Stmt *PreInit, Expr *PostUpdate) {
  539. // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
  540. // (Step and CalcStep), list of used expression + step.
  541. void *Mem =
  542. C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
  543. OMPLinearClause *Clause = new (Mem) OMPLinearClause(
  544. StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
  545. Clause->setVarRefs(VL);
  546. Clause->setPrivates(PL);
  547. Clause->setInits(IL);
  548. // Fill update and final expressions with zeroes, they are provided later,
  549. // after the directive construction.
  550. std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
  551. nullptr);
  552. std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
  553. nullptr);
  554. std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
  555. nullptr);
  556. Clause->setStep(Step);
  557. Clause->setCalcStep(CalcStep);
  558. Clause->setPreInitStmt(PreInit);
  559. Clause->setPostUpdateExpr(PostUpdate);
  560. return Clause;
  561. }
  562. OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
  563. unsigned NumVars) {
  564. // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
  565. // (Step and CalcStep), list of used expression + step.
  566. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1));
  567. return new (Mem) OMPLinearClause(NumVars);
  568. }
  569. OMPClause::child_range OMPLinearClause::used_children() {
  570. // Range includes only non-nullptr elements.
  571. return child_range(
  572. reinterpret_cast<Stmt **>(getUsedExprs().begin()),
  573. reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
  574. }
  575. OMPAlignedClause *
  576. OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
  577. SourceLocation LParenLoc, SourceLocation ColonLoc,
  578. SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
  579. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
  580. OMPAlignedClause *Clause = new (Mem)
  581. OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
  582. Clause->setVarRefs(VL);
  583. Clause->setAlignment(A);
  584. return Clause;
  585. }
  586. OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
  587. unsigned NumVars) {
  588. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
  589. return new (Mem) OMPAlignedClause(NumVars);
  590. }
  591. OMPAlignClause *OMPAlignClause::Create(const ASTContext &C, Expr *A,
  592. SourceLocation StartLoc,
  593. SourceLocation LParenLoc,
  594. SourceLocation EndLoc) {
  595. return new (C) OMPAlignClause(A, StartLoc, LParenLoc, EndLoc);
  596. }
  597. void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  598. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  599. "not the same as the "
  600. "preallocated buffer");
  601. std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
  602. }
  603. void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  604. assert(DstExprs.size() == varlist_size() && "Number of destination "
  605. "expressions is not the same as "
  606. "the preallocated buffer");
  607. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  608. }
  609. void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  610. assert(AssignmentOps.size() == varlist_size() &&
  611. "Number of assignment expressions is not the same as the preallocated "
  612. "buffer");
  613. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  614. getDestinationExprs().end());
  615. }
  616. OMPCopyinClause *OMPCopyinClause::Create(
  617. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  618. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  619. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
  620. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
  621. OMPCopyinClause *Clause =
  622. new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
  623. Clause->setVarRefs(VL);
  624. Clause->setSourceExprs(SrcExprs);
  625. Clause->setDestinationExprs(DstExprs);
  626. Clause->setAssignmentOps(AssignmentOps);
  627. return Clause;
  628. }
  629. OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
  630. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
  631. return new (Mem) OMPCopyinClause(N);
  632. }
  633. void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
  634. assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
  635. "not the same as the "
  636. "preallocated buffer");
  637. std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
  638. }
  639. void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
  640. assert(DstExprs.size() == varlist_size() && "Number of destination "
  641. "expressions is not the same as "
  642. "the preallocated buffer");
  643. std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
  644. }
  645. void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
  646. assert(AssignmentOps.size() == varlist_size() &&
  647. "Number of assignment expressions is not the same as the preallocated "
  648. "buffer");
  649. std::copy(AssignmentOps.begin(), AssignmentOps.end(),
  650. getDestinationExprs().end());
  651. }
  652. OMPCopyprivateClause *OMPCopyprivateClause::Create(
  653. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  654. SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
  655. ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
  656. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
  657. OMPCopyprivateClause *Clause =
  658. new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
  659. Clause->setVarRefs(VL);
  660. Clause->setSourceExprs(SrcExprs);
  661. Clause->setDestinationExprs(DstExprs);
  662. Clause->setAssignmentOps(AssignmentOps);
  663. return Clause;
  664. }
  665. OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
  666. unsigned N) {
  667. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
  668. return new (Mem) OMPCopyprivateClause(N);
  669. }
  670. void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  671. assert(Privates.size() == varlist_size() &&
  672. "Number of private copies is not the same as the preallocated buffer");
  673. std::copy(Privates.begin(), Privates.end(), varlist_end());
  674. }
  675. void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  676. assert(
  677. LHSExprs.size() == varlist_size() &&
  678. "Number of LHS expressions is not the same as the preallocated buffer");
  679. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  680. }
  681. void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  682. assert(
  683. RHSExprs.size() == varlist_size() &&
  684. "Number of RHS expressions is not the same as the preallocated buffer");
  685. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  686. }
  687. void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  688. assert(ReductionOps.size() == varlist_size() && "Number of reduction "
  689. "expressions is not the same "
  690. "as the preallocated buffer");
  691. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  692. }
  693. void OMPReductionClause::setInscanCopyOps(ArrayRef<Expr *> Ops) {
  694. assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
  695. assert(Ops.size() == varlist_size() && "Number of copy "
  696. "expressions is not the same "
  697. "as the preallocated buffer");
  698. llvm::copy(Ops, getReductionOps().end());
  699. }
  700. void OMPReductionClause::setInscanCopyArrayTemps(
  701. ArrayRef<Expr *> CopyArrayTemps) {
  702. assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
  703. assert(CopyArrayTemps.size() == varlist_size() &&
  704. "Number of copy temp expressions is not the same as the preallocated "
  705. "buffer");
  706. llvm::copy(CopyArrayTemps, getInscanCopyOps().end());
  707. }
  708. void OMPReductionClause::setInscanCopyArrayElems(
  709. ArrayRef<Expr *> CopyArrayElems) {
  710. assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction.");
  711. assert(CopyArrayElems.size() == varlist_size() &&
  712. "Number of copy temp expressions is not the same as the preallocated "
  713. "buffer");
  714. llvm::copy(CopyArrayElems, getInscanCopyArrayTemps().end());
  715. }
  716. OMPReductionClause *OMPReductionClause::Create(
  717. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  718. SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc,
  719. OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL,
  720. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  721. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  722. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
  723. ArrayRef<Expr *> CopyOps, ArrayRef<Expr *> CopyArrayTemps,
  724. ArrayRef<Expr *> CopyArrayElems, Stmt *PreInit, Expr *PostUpdate) {
  725. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
  726. (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size()));
  727. auto *Clause = new (Mem)
  728. OMPReductionClause(StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc,
  729. Modifier, VL.size(), QualifierLoc, NameInfo);
  730. Clause->setVarRefs(VL);
  731. Clause->setPrivates(Privates);
  732. Clause->setLHSExprs(LHSExprs);
  733. Clause->setRHSExprs(RHSExprs);
  734. Clause->setReductionOps(ReductionOps);
  735. Clause->setPreInitStmt(PreInit);
  736. Clause->setPostUpdateExpr(PostUpdate);
  737. if (Modifier == OMPC_REDUCTION_inscan) {
  738. Clause->setInscanCopyOps(CopyOps);
  739. Clause->setInscanCopyArrayTemps(CopyArrayTemps);
  740. Clause->setInscanCopyArrayElems(CopyArrayElems);
  741. } else {
  742. assert(CopyOps.empty() &&
  743. "copy operations are expected in inscan reductions only.");
  744. assert(CopyArrayTemps.empty() &&
  745. "copy array temps are expected in inscan reductions only.");
  746. assert(CopyArrayElems.empty() &&
  747. "copy array temps are expected in inscan reductions only.");
  748. }
  749. return Clause;
  750. }
  751. OMPReductionClause *
  752. OMPReductionClause::CreateEmpty(const ASTContext &C, unsigned N,
  753. OpenMPReductionClauseModifier Modifier) {
  754. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(
  755. (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N));
  756. auto *Clause = new (Mem) OMPReductionClause(N);
  757. Clause->setModifier(Modifier);
  758. return Clause;
  759. }
  760. void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  761. assert(Privates.size() == varlist_size() &&
  762. "Number of private copies is not the same as the preallocated buffer");
  763. std::copy(Privates.begin(), Privates.end(), varlist_end());
  764. }
  765. void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  766. assert(
  767. LHSExprs.size() == varlist_size() &&
  768. "Number of LHS expressions is not the same as the preallocated buffer");
  769. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  770. }
  771. void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  772. assert(
  773. RHSExprs.size() == varlist_size() &&
  774. "Number of RHS expressions is not the same as the preallocated buffer");
  775. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  776. }
  777. void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  778. assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
  779. "expressions is not the same "
  780. "as the preallocated buffer");
  781. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  782. }
  783. OMPTaskReductionClause *OMPTaskReductionClause::Create(
  784. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  785. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  786. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  787. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  788. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
  789. Expr *PostUpdate) {
  790. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
  791. OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
  792. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  793. Clause->setVarRefs(VL);
  794. Clause->setPrivates(Privates);
  795. Clause->setLHSExprs(LHSExprs);
  796. Clause->setRHSExprs(RHSExprs);
  797. Clause->setReductionOps(ReductionOps);
  798. Clause->setPreInitStmt(PreInit);
  799. Clause->setPostUpdateExpr(PostUpdate);
  800. return Clause;
  801. }
  802. OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
  803. unsigned N) {
  804. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
  805. return new (Mem) OMPTaskReductionClause(N);
  806. }
  807. void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
  808. assert(Privates.size() == varlist_size() &&
  809. "Number of private copies is not the same as the preallocated buffer");
  810. std::copy(Privates.begin(), Privates.end(), varlist_end());
  811. }
  812. void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
  813. assert(
  814. LHSExprs.size() == varlist_size() &&
  815. "Number of LHS expressions is not the same as the preallocated buffer");
  816. std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
  817. }
  818. void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
  819. assert(
  820. RHSExprs.size() == varlist_size() &&
  821. "Number of RHS expressions is not the same as the preallocated buffer");
  822. std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
  823. }
  824. void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
  825. assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
  826. "expressions is not the same "
  827. "as the preallocated buffer");
  828. std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
  829. }
  830. void OMPInReductionClause::setTaskgroupDescriptors(
  831. ArrayRef<Expr *> TaskgroupDescriptors) {
  832. assert(TaskgroupDescriptors.size() == varlist_size() &&
  833. "Number of in reduction descriptors is not the same as the "
  834. "preallocated buffer");
  835. std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
  836. getReductionOps().end());
  837. }
  838. OMPInReductionClause *OMPInReductionClause::Create(
  839. const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
  840. SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
  841. NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
  842. ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
  843. ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
  844. ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
  845. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
  846. OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
  847. StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
  848. Clause->setVarRefs(VL);
  849. Clause->setPrivates(Privates);
  850. Clause->setLHSExprs(LHSExprs);
  851. Clause->setRHSExprs(RHSExprs);
  852. Clause->setReductionOps(ReductionOps);
  853. Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
  854. Clause->setPreInitStmt(PreInit);
  855. Clause->setPostUpdateExpr(PostUpdate);
  856. return Clause;
  857. }
  858. OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
  859. unsigned N) {
  860. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
  861. return new (Mem) OMPInReductionClause(N);
  862. }
  863. OMPSizesClause *OMPSizesClause::Create(const ASTContext &C,
  864. SourceLocation StartLoc,
  865. SourceLocation LParenLoc,
  866. SourceLocation EndLoc,
  867. ArrayRef<Expr *> Sizes) {
  868. OMPSizesClause *Clause = CreateEmpty(C, Sizes.size());
  869. Clause->setLocStart(StartLoc);
  870. Clause->setLParenLoc(LParenLoc);
  871. Clause->setLocEnd(EndLoc);
  872. Clause->setSizesRefs(Sizes);
  873. return Clause;
  874. }
  875. OMPSizesClause *OMPSizesClause::CreateEmpty(const ASTContext &C,
  876. unsigned NumSizes) {
  877. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumSizes));
  878. return new (Mem) OMPSizesClause(NumSizes);
  879. }
  880. OMPFullClause *OMPFullClause::Create(const ASTContext &C,
  881. SourceLocation StartLoc,
  882. SourceLocation EndLoc) {
  883. OMPFullClause *Clause = CreateEmpty(C);
  884. Clause->setLocStart(StartLoc);
  885. Clause->setLocEnd(EndLoc);
  886. return Clause;
  887. }
  888. OMPFullClause *OMPFullClause::CreateEmpty(const ASTContext &C) {
  889. return new (C) OMPFullClause();
  890. }
  891. OMPPartialClause *OMPPartialClause::Create(const ASTContext &C,
  892. SourceLocation StartLoc,
  893. SourceLocation LParenLoc,
  894. SourceLocation EndLoc,
  895. Expr *Factor) {
  896. OMPPartialClause *Clause = CreateEmpty(C);
  897. Clause->setLocStart(StartLoc);
  898. Clause->setLParenLoc(LParenLoc);
  899. Clause->setLocEnd(EndLoc);
  900. Clause->setFactor(Factor);
  901. return Clause;
  902. }
  903. OMPPartialClause *OMPPartialClause::CreateEmpty(const ASTContext &C) {
  904. return new (C) OMPPartialClause();
  905. }
  906. OMPAllocateClause *
  907. OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
  908. SourceLocation LParenLoc, Expr *Allocator,
  909. SourceLocation ColonLoc, SourceLocation EndLoc,
  910. ArrayRef<Expr *> VL) {
  911. // Allocate space for private variables and initializer expressions.
  912. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
  913. auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
  914. ColonLoc, EndLoc, VL.size());
  915. Clause->setVarRefs(VL);
  916. return Clause;
  917. }
  918. OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
  919. unsigned N) {
  920. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  921. return new (Mem) OMPAllocateClause(N);
  922. }
  923. OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
  924. SourceLocation StartLoc,
  925. SourceLocation LParenLoc,
  926. SourceLocation EndLoc,
  927. ArrayRef<Expr *> VL) {
  928. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
  929. OMPFlushClause *Clause =
  930. new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
  931. Clause->setVarRefs(VL);
  932. return Clause;
  933. }
  934. OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
  935. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  936. return new (Mem) OMPFlushClause(N);
  937. }
  938. OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C,
  939. SourceLocation StartLoc,
  940. SourceLocation LParenLoc,
  941. SourceLocation RParenLoc,
  942. Expr *Depobj) {
  943. auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc);
  944. Clause->setDepobj(Depobj);
  945. return Clause;
  946. }
  947. OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
  948. return new (C) OMPDepobjClause();
  949. }
  950. OMPDependClause *
  951. OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
  952. SourceLocation LParenLoc, SourceLocation EndLoc,
  953. DependDataTy Data, Expr *DepModifier,
  954. ArrayRef<Expr *> VL, unsigned NumLoops) {
  955. void *Mem = C.Allocate(
  956. totalSizeToAlloc<Expr *>(VL.size() + /*depend-modifier*/ 1 + NumLoops),
  957. alignof(OMPDependClause));
  958. OMPDependClause *Clause = new (Mem)
  959. OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
  960. Clause->setDependencyKind(Data.DepKind);
  961. Clause->setDependencyLoc(Data.DepLoc);
  962. Clause->setColonLoc(Data.ColonLoc);
  963. Clause->setOmpAllMemoryLoc(Data.OmpAllMemoryLoc);
  964. Clause->setModifier(DepModifier);
  965. Clause->setVarRefs(VL);
  966. for (unsigned I = 0 ; I < NumLoops; ++I)
  967. Clause->setLoopData(I, nullptr);
  968. return Clause;
  969. }
  970. OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
  971. unsigned NumLoops) {
  972. void *Mem =
  973. C.Allocate(totalSizeToAlloc<Expr *>(N + /*depend-modifier*/ 1 + NumLoops),
  974. alignof(OMPDependClause));
  975. return new (Mem) OMPDependClause(N, NumLoops);
  976. }
  977. void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
  978. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  979. getDependencyKind() == OMPC_DEPEND_source) &&
  980. NumLoop < NumLoops &&
  981. "Expected sink or source depend + loop index must be less number of "
  982. "loops.");
  983. auto *It = std::next(getVarRefs().end(), NumLoop + 1);
  984. *It = Cnt;
  985. }
  986. Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
  987. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  988. getDependencyKind() == OMPC_DEPEND_source) &&
  989. NumLoop < NumLoops &&
  990. "Expected sink or source depend + loop index must be less number of "
  991. "loops.");
  992. auto *It = std::next(getVarRefs().end(), NumLoop + 1);
  993. return *It;
  994. }
  995. const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
  996. assert((getDependencyKind() == OMPC_DEPEND_sink ||
  997. getDependencyKind() == OMPC_DEPEND_source) &&
  998. NumLoop < NumLoops &&
  999. "Expected sink or source depend + loop index must be less number of "
  1000. "loops.");
  1001. const auto *It = std::next(getVarRefs().end(), NumLoop + 1);
  1002. return *It;
  1003. }
  1004. void OMPDependClause::setModifier(Expr *DepModifier) {
  1005. *getVarRefs().end() = DepModifier;
  1006. }
  1007. Expr *OMPDependClause::getModifier() { return *getVarRefs().end(); }
  1008. unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
  1009. MappableExprComponentListsRef ComponentLists) {
  1010. unsigned TotalNum = 0u;
  1011. for (auto &C : ComponentLists)
  1012. TotalNum += C.size();
  1013. return TotalNum;
  1014. }
  1015. unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
  1016. ArrayRef<const ValueDecl *> Declarations) {
  1017. unsigned TotalNum = 0u;
  1018. llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
  1019. for (const ValueDecl *D : Declarations) {
  1020. const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
  1021. if (Cache.count(VD))
  1022. continue;
  1023. ++TotalNum;
  1024. Cache.insert(VD);
  1025. }
  1026. return TotalNum;
  1027. }
  1028. OMPMapClause *OMPMapClause::Create(
  1029. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  1030. ArrayRef<ValueDecl *> Declarations,
  1031. MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
  1032. Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapModifiers,
  1033. ArrayRef<SourceLocation> MapModifiersLoc,
  1034. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
  1035. OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
  1036. OMPMappableExprListSizeTy Sizes;
  1037. Sizes.NumVars = Vars.size();
  1038. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1039. Sizes.NumComponentLists = ComponentLists.size();
  1040. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1041. // We need to allocate:
  1042. // 2 x NumVars x Expr* - we have an original list expression and an associated
  1043. // user-defined mapper for each clause list entry.
  1044. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1045. // with each component list.
  1046. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1047. // number of lists for each unique declaration and the size of each component
  1048. // list.
  1049. // NumComponents x MappableComponent - the total of all the components in all
  1050. // the lists.
  1051. void *Mem = C.Allocate(
  1052. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1053. OMPClauseMappableExprCommon::MappableComponent>(
  1054. 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
  1055. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1056. Sizes.NumComponents));
  1057. OMPMapClause *Clause = new (Mem)
  1058. OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
  1059. Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
  1060. Clause->setVarRefs(Vars);
  1061. Clause->setUDMapperRefs(UDMapperRefs);
  1062. Clause->setIteratorModifier(IteratorModifier);
  1063. Clause->setClauseInfo(Declarations, ComponentLists);
  1064. Clause->setMapType(Type);
  1065. Clause->setMapLoc(TypeLoc);
  1066. return Clause;
  1067. }
  1068. OMPMapClause *
  1069. OMPMapClause::CreateEmpty(const ASTContext &C,
  1070. const OMPMappableExprListSizeTy &Sizes) {
  1071. void *Mem = C.Allocate(
  1072. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1073. OMPClauseMappableExprCommon::MappableComponent>(
  1074. 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
  1075. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1076. Sizes.NumComponents));
  1077. OMPMapClause *Clause = new (Mem) OMPMapClause(Sizes);
  1078. Clause->setIteratorModifier(nullptr);
  1079. return Clause;
  1080. }
  1081. OMPToClause *OMPToClause::Create(
  1082. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  1083. ArrayRef<ValueDecl *> Declarations,
  1084. MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
  1085. ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
  1086. ArrayRef<SourceLocation> MotionModifiersLoc,
  1087. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
  1088. OMPMappableExprListSizeTy Sizes;
  1089. Sizes.NumVars = Vars.size();
  1090. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1091. Sizes.NumComponentLists = ComponentLists.size();
  1092. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1093. // We need to allocate:
  1094. // 2 x NumVars x Expr* - we have an original list expression and an associated
  1095. // user-defined mapper for each clause list entry.
  1096. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1097. // with each component list.
  1098. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1099. // number of lists for each unique declaration and the size of each component
  1100. // list.
  1101. // NumComponents x MappableComponent - the total of all the components in all
  1102. // the lists.
  1103. void *Mem = C.Allocate(
  1104. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1105. OMPClauseMappableExprCommon::MappableComponent>(
  1106. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1107. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1108. Sizes.NumComponents));
  1109. auto *Clause = new (Mem) OMPToClause(MotionModifiers, MotionModifiersLoc,
  1110. UDMQualifierLoc, MapperId, Locs, Sizes);
  1111. Clause->setVarRefs(Vars);
  1112. Clause->setUDMapperRefs(UDMapperRefs);
  1113. Clause->setClauseInfo(Declarations, ComponentLists);
  1114. return Clause;
  1115. }
  1116. OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
  1117. const OMPMappableExprListSizeTy &Sizes) {
  1118. void *Mem = C.Allocate(
  1119. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1120. OMPClauseMappableExprCommon::MappableComponent>(
  1121. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1122. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1123. Sizes.NumComponents));
  1124. return new (Mem) OMPToClause(Sizes);
  1125. }
  1126. OMPFromClause *OMPFromClause::Create(
  1127. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  1128. ArrayRef<ValueDecl *> Declarations,
  1129. MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
  1130. ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
  1131. ArrayRef<SourceLocation> MotionModifiersLoc,
  1132. NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
  1133. OMPMappableExprListSizeTy Sizes;
  1134. Sizes.NumVars = Vars.size();
  1135. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1136. Sizes.NumComponentLists = ComponentLists.size();
  1137. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1138. // We need to allocate:
  1139. // 2 x NumVars x Expr* - we have an original list expression and an associated
  1140. // user-defined mapper for each clause list entry.
  1141. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1142. // with each component list.
  1143. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1144. // number of lists for each unique declaration and the size of each component
  1145. // list.
  1146. // NumComponents x MappableComponent - the total of all the components in all
  1147. // the lists.
  1148. void *Mem = C.Allocate(
  1149. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1150. OMPClauseMappableExprCommon::MappableComponent>(
  1151. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1152. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1153. Sizes.NumComponents));
  1154. auto *Clause =
  1155. new (Mem) OMPFromClause(MotionModifiers, MotionModifiersLoc,
  1156. UDMQualifierLoc, MapperId, Locs, Sizes);
  1157. Clause->setVarRefs(Vars);
  1158. Clause->setUDMapperRefs(UDMapperRefs);
  1159. Clause->setClauseInfo(Declarations, ComponentLists);
  1160. return Clause;
  1161. }
  1162. OMPFromClause *
  1163. OMPFromClause::CreateEmpty(const ASTContext &C,
  1164. const OMPMappableExprListSizeTy &Sizes) {
  1165. void *Mem = C.Allocate(
  1166. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1167. OMPClauseMappableExprCommon::MappableComponent>(
  1168. 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1169. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1170. Sizes.NumComponents));
  1171. return new (Mem) OMPFromClause(Sizes);
  1172. }
  1173. void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
  1174. assert(VL.size() == varlist_size() &&
  1175. "Number of private copies is not the same as the preallocated buffer");
  1176. std::copy(VL.begin(), VL.end(), varlist_end());
  1177. }
  1178. void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
  1179. assert(VL.size() == varlist_size() &&
  1180. "Number of inits is not the same as the preallocated buffer");
  1181. std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
  1182. }
  1183. OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
  1184. const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
  1185. ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
  1186. ArrayRef<ValueDecl *> Declarations,
  1187. MappableExprComponentListsRef ComponentLists) {
  1188. OMPMappableExprListSizeTy Sizes;
  1189. Sizes.NumVars = Vars.size();
  1190. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1191. Sizes.NumComponentLists = ComponentLists.size();
  1192. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1193. // We need to allocate:
  1194. // NumVars x Expr* - we have an original list expression for each clause
  1195. // list entry.
  1196. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1197. // with each component list.
  1198. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1199. // number of lists for each unique declaration and the size of each component
  1200. // list.
  1201. // NumComponents x MappableComponent - the total of all the components in all
  1202. // the lists.
  1203. void *Mem = C.Allocate(
  1204. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1205. OMPClauseMappableExprCommon::MappableComponent>(
  1206. 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1207. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1208. Sizes.NumComponents));
  1209. OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
  1210. Clause->setVarRefs(Vars);
  1211. Clause->setPrivateCopies(PrivateVars);
  1212. Clause->setInits(Inits);
  1213. Clause->setClauseInfo(Declarations, ComponentLists);
  1214. return Clause;
  1215. }
  1216. OMPUseDevicePtrClause *
  1217. OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
  1218. const OMPMappableExprListSizeTy &Sizes) {
  1219. void *Mem = C.Allocate(
  1220. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1221. OMPClauseMappableExprCommon::MappableComponent>(
  1222. 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1223. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1224. Sizes.NumComponents));
  1225. return new (Mem) OMPUseDevicePtrClause(Sizes);
  1226. }
  1227. OMPUseDeviceAddrClause *
  1228. OMPUseDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  1229. ArrayRef<Expr *> Vars,
  1230. ArrayRef<ValueDecl *> Declarations,
  1231. MappableExprComponentListsRef ComponentLists) {
  1232. OMPMappableExprListSizeTy Sizes;
  1233. Sizes.NumVars = Vars.size();
  1234. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1235. Sizes.NumComponentLists = ComponentLists.size();
  1236. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1237. // We need to allocate:
  1238. // 3 x NumVars x Expr* - we have an original list expression for each clause
  1239. // list entry and an equal number of private copies and inits.
  1240. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1241. // with each component list.
  1242. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1243. // number of lists for each unique declaration and the size of each component
  1244. // list.
  1245. // NumComponents x MappableComponent - the total of all the components in all
  1246. // the lists.
  1247. void *Mem = C.Allocate(
  1248. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1249. OMPClauseMappableExprCommon::MappableComponent>(
  1250. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1251. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1252. Sizes.NumComponents));
  1253. auto *Clause = new (Mem) OMPUseDeviceAddrClause(Locs, Sizes);
  1254. Clause->setVarRefs(Vars);
  1255. Clause->setClauseInfo(Declarations, ComponentLists);
  1256. return Clause;
  1257. }
  1258. OMPUseDeviceAddrClause *
  1259. OMPUseDeviceAddrClause::CreateEmpty(const ASTContext &C,
  1260. const OMPMappableExprListSizeTy &Sizes) {
  1261. void *Mem = C.Allocate(
  1262. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1263. OMPClauseMappableExprCommon::MappableComponent>(
  1264. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1265. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1266. Sizes.NumComponents));
  1267. return new (Mem) OMPUseDeviceAddrClause(Sizes);
  1268. }
  1269. OMPIsDevicePtrClause *
  1270. OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  1271. ArrayRef<Expr *> Vars,
  1272. ArrayRef<ValueDecl *> Declarations,
  1273. MappableExprComponentListsRef ComponentLists) {
  1274. OMPMappableExprListSizeTy Sizes;
  1275. Sizes.NumVars = Vars.size();
  1276. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1277. Sizes.NumComponentLists = ComponentLists.size();
  1278. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1279. // We need to allocate:
  1280. // NumVars x Expr* - we have an original list expression for each clause list
  1281. // entry.
  1282. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1283. // with each component list.
  1284. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1285. // number of lists for each unique declaration and the size of each component
  1286. // list.
  1287. // NumComponents x MappableComponent - the total of all the components in all
  1288. // the lists.
  1289. void *Mem = C.Allocate(
  1290. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1291. OMPClauseMappableExprCommon::MappableComponent>(
  1292. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1293. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1294. Sizes.NumComponents));
  1295. OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
  1296. Clause->setVarRefs(Vars);
  1297. Clause->setClauseInfo(Declarations, ComponentLists);
  1298. return Clause;
  1299. }
  1300. OMPIsDevicePtrClause *
  1301. OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
  1302. const OMPMappableExprListSizeTy &Sizes) {
  1303. void *Mem = C.Allocate(
  1304. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1305. OMPClauseMappableExprCommon::MappableComponent>(
  1306. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1307. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1308. Sizes.NumComponents));
  1309. return new (Mem) OMPIsDevicePtrClause(Sizes);
  1310. }
  1311. OMPHasDeviceAddrClause *
  1312. OMPHasDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
  1313. ArrayRef<Expr *> Vars,
  1314. ArrayRef<ValueDecl *> Declarations,
  1315. MappableExprComponentListsRef ComponentLists) {
  1316. OMPMappableExprListSizeTy Sizes;
  1317. Sizes.NumVars = Vars.size();
  1318. Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
  1319. Sizes.NumComponentLists = ComponentLists.size();
  1320. Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
  1321. // We need to allocate:
  1322. // NumVars x Expr* - we have an original list expression for each clause list
  1323. // entry.
  1324. // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
  1325. // with each component list.
  1326. // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
  1327. // number of lists for each unique declaration and the size of each component
  1328. // list.
  1329. // NumComponents x MappableComponent - the total of all the components in all
  1330. // the lists.
  1331. void *Mem = C.Allocate(
  1332. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1333. OMPClauseMappableExprCommon::MappableComponent>(
  1334. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1335. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1336. Sizes.NumComponents));
  1337. auto *Clause = new (Mem) OMPHasDeviceAddrClause(Locs, Sizes);
  1338. Clause->setVarRefs(Vars);
  1339. Clause->setClauseInfo(Declarations, ComponentLists);
  1340. return Clause;
  1341. }
  1342. OMPHasDeviceAddrClause *
  1343. OMPHasDeviceAddrClause::CreateEmpty(const ASTContext &C,
  1344. const OMPMappableExprListSizeTy &Sizes) {
  1345. void *Mem = C.Allocate(
  1346. totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
  1347. OMPClauseMappableExprCommon::MappableComponent>(
  1348. Sizes.NumVars, Sizes.NumUniqueDeclarations,
  1349. Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
  1350. Sizes.NumComponents));
  1351. return new (Mem) OMPHasDeviceAddrClause(Sizes);
  1352. }
  1353. OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
  1354. SourceLocation StartLoc,
  1355. SourceLocation LParenLoc,
  1356. SourceLocation EndLoc,
  1357. ArrayRef<Expr *> VL) {
  1358. // Allocate space for nontemporal variables + private references.
  1359. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
  1360. auto *Clause =
  1361. new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
  1362. Clause->setVarRefs(VL);
  1363. return Clause;
  1364. }
  1365. OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
  1366. unsigned N) {
  1367. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
  1368. return new (Mem) OMPNontemporalClause(N);
  1369. }
  1370. void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
  1371. assert(VL.size() == varlist_size() && "Number of private references is not "
  1372. "the same as the preallocated buffer");
  1373. std::copy(VL.begin(), VL.end(), varlist_end());
  1374. }
  1375. OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
  1376. SourceLocation StartLoc,
  1377. SourceLocation LParenLoc,
  1378. SourceLocation EndLoc,
  1379. ArrayRef<Expr *> VL) {
  1380. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
  1381. auto *Clause =
  1382. new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
  1383. Clause->setVarRefs(VL);
  1384. return Clause;
  1385. }
  1386. OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
  1387. unsigned N) {
  1388. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  1389. return new (Mem) OMPInclusiveClause(N);
  1390. }
  1391. OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
  1392. SourceLocation StartLoc,
  1393. SourceLocation LParenLoc,
  1394. SourceLocation EndLoc,
  1395. ArrayRef<Expr *> VL) {
  1396. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
  1397. auto *Clause =
  1398. new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
  1399. Clause->setVarRefs(VL);
  1400. return Clause;
  1401. }
  1402. OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
  1403. unsigned N) {
  1404. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  1405. return new (Mem) OMPExclusiveClause(N);
  1406. }
  1407. void OMPUsesAllocatorsClause::setAllocatorsData(
  1408. ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
  1409. assert(Data.size() == NumOfAllocators &&
  1410. "Size of allocators data is not the same as the preallocated buffer.");
  1411. for (unsigned I = 0, E = Data.size(); I < E; ++I) {
  1412. const OMPUsesAllocatorsClause::Data &D = Data[I];
  1413. getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
  1414. static_cast<int>(ExprOffsets::Allocator)] =
  1415. D.Allocator;
  1416. getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
  1417. static_cast<int>(
  1418. ExprOffsets::AllocatorTraits)] =
  1419. D.AllocatorTraits;
  1420. getTrailingObjects<
  1421. SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
  1422. static_cast<int>(ParenLocsOffsets::LParen)] =
  1423. D.LParenLoc;
  1424. getTrailingObjects<
  1425. SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
  1426. static_cast<int>(ParenLocsOffsets::RParen)] =
  1427. D.RParenLoc;
  1428. }
  1429. }
  1430. OMPUsesAllocatorsClause::Data
  1431. OMPUsesAllocatorsClause::getAllocatorData(unsigned I) const {
  1432. OMPUsesAllocatorsClause::Data Data;
  1433. Data.Allocator =
  1434. getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
  1435. static_cast<int>(ExprOffsets::Allocator)];
  1436. Data.AllocatorTraits =
  1437. getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) +
  1438. static_cast<int>(
  1439. ExprOffsets::AllocatorTraits)];
  1440. Data.LParenLoc = getTrailingObjects<
  1441. SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
  1442. static_cast<int>(ParenLocsOffsets::LParen)];
  1443. Data.RParenLoc = getTrailingObjects<
  1444. SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) +
  1445. static_cast<int>(ParenLocsOffsets::RParen)];
  1446. return Data;
  1447. }
  1448. OMPUsesAllocatorsClause *
  1449. OMPUsesAllocatorsClause::Create(const ASTContext &C, SourceLocation StartLoc,
  1450. SourceLocation LParenLoc, SourceLocation EndLoc,
  1451. ArrayRef<OMPUsesAllocatorsClause::Data> Data) {
  1452. void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
  1453. static_cast<int>(ExprOffsets::Total) * Data.size(),
  1454. static_cast<int>(ParenLocsOffsets::Total) * Data.size()));
  1455. auto *Clause = new (Mem)
  1456. OMPUsesAllocatorsClause(StartLoc, LParenLoc, EndLoc, Data.size());
  1457. Clause->setAllocatorsData(Data);
  1458. return Clause;
  1459. }
  1460. OMPUsesAllocatorsClause *
  1461. OMPUsesAllocatorsClause::CreateEmpty(const ASTContext &C, unsigned N) {
  1462. void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>(
  1463. static_cast<int>(ExprOffsets::Total) * N,
  1464. static_cast<int>(ParenLocsOffsets::Total) * N));
  1465. return new (Mem) OMPUsesAllocatorsClause(N);
  1466. }
  1467. OMPAffinityClause *
  1468. OMPAffinityClause::Create(const ASTContext &C, SourceLocation StartLoc,
  1469. SourceLocation LParenLoc, SourceLocation ColonLoc,
  1470. SourceLocation EndLoc, Expr *Modifier,
  1471. ArrayRef<Expr *> Locators) {
  1472. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Locators.size() + 1));
  1473. auto *Clause = new (Mem)
  1474. OMPAffinityClause(StartLoc, LParenLoc, ColonLoc, EndLoc, Locators.size());
  1475. Clause->setModifier(Modifier);
  1476. Clause->setVarRefs(Locators);
  1477. return Clause;
  1478. }
  1479. OMPAffinityClause *OMPAffinityClause::CreateEmpty(const ASTContext &C,
  1480. unsigned N) {
  1481. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
  1482. return new (Mem) OMPAffinityClause(N);
  1483. }
  1484. OMPInitClause *OMPInitClause::Create(const ASTContext &C, Expr *InteropVar,
  1485. OMPInteropInfo &InteropInfo,
  1486. SourceLocation StartLoc,
  1487. SourceLocation LParenLoc,
  1488. SourceLocation VarLoc,
  1489. SourceLocation EndLoc) {
  1490. void *Mem =
  1491. C.Allocate(totalSizeToAlloc<Expr *>(InteropInfo.PreferTypes.size() + 1));
  1492. auto *Clause = new (Mem) OMPInitClause(
  1493. InteropInfo.IsTarget, InteropInfo.IsTargetSync, StartLoc, LParenLoc,
  1494. VarLoc, EndLoc, InteropInfo.PreferTypes.size() + 1);
  1495. Clause->setInteropVar(InteropVar);
  1496. llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects<Expr *>() + 1);
  1497. return Clause;
  1498. }
  1499. OMPInitClause *OMPInitClause::CreateEmpty(const ASTContext &C, unsigned N) {
  1500. void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
  1501. return new (Mem) OMPInitClause(N);
  1502. }
  1503. OMPBindClause *
  1504. OMPBindClause::Create(const ASTContext &C, OpenMPBindClauseKind K,
  1505. SourceLocation KLoc, SourceLocation StartLoc,
  1506. SourceLocation LParenLoc, SourceLocation EndLoc) {
  1507. return new (C) OMPBindClause(K, KLoc, StartLoc, LParenLoc, EndLoc);
  1508. }
  1509. OMPBindClause *OMPBindClause::CreateEmpty(const ASTContext &C) {
  1510. return new (C) OMPBindClause();
  1511. }
  1512. //===----------------------------------------------------------------------===//
  1513. // OpenMP clauses printing methods
  1514. //===----------------------------------------------------------------------===//
  1515. void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
  1516. OS << "if(";
  1517. if (Node->getNameModifier() != OMPD_unknown)
  1518. OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
  1519. Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
  1520. OS << ")";
  1521. }
  1522. void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
  1523. OS << "final(";
  1524. Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
  1525. OS << ")";
  1526. }
  1527. void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
  1528. OS << "num_threads(";
  1529. Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
  1530. OS << ")";
  1531. }
  1532. void OMPClausePrinter::VisitOMPAlignClause(OMPAlignClause *Node) {
  1533. OS << "align(";
  1534. Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
  1535. OS << ")";
  1536. }
  1537. void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
  1538. OS << "safelen(";
  1539. Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
  1540. OS << ")";
  1541. }
  1542. void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
  1543. OS << "simdlen(";
  1544. Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
  1545. OS << ")";
  1546. }
  1547. void OMPClausePrinter::VisitOMPSizesClause(OMPSizesClause *Node) {
  1548. OS << "sizes(";
  1549. bool First = true;
  1550. for (auto *Size : Node->getSizesRefs()) {
  1551. if (!First)
  1552. OS << ", ";
  1553. Size->printPretty(OS, nullptr, Policy, 0);
  1554. First = false;
  1555. }
  1556. OS << ")";
  1557. }
  1558. void OMPClausePrinter::VisitOMPFullClause(OMPFullClause *Node) { OS << "full"; }
  1559. void OMPClausePrinter::VisitOMPPartialClause(OMPPartialClause *Node) {
  1560. OS << "partial";
  1561. if (Expr *Factor = Node->getFactor()) {
  1562. OS << '(';
  1563. Factor->printPretty(OS, nullptr, Policy, 0);
  1564. OS << ')';
  1565. }
  1566. }
  1567. void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
  1568. OS << "allocator(";
  1569. Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
  1570. OS << ")";
  1571. }
  1572. void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
  1573. OS << "collapse(";
  1574. Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
  1575. OS << ")";
  1576. }
  1577. void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
  1578. OS << "detach(";
  1579. Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0);
  1580. OS << ")";
  1581. }
  1582. void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
  1583. OS << "default("
  1584. << getOpenMPSimpleClauseTypeName(OMPC_default,
  1585. unsigned(Node->getDefaultKind()))
  1586. << ")";
  1587. }
  1588. void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
  1589. OS << "proc_bind("
  1590. << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
  1591. unsigned(Node->getProcBindKind()))
  1592. << ")";
  1593. }
  1594. void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
  1595. OS << "unified_address";
  1596. }
  1597. void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
  1598. OMPUnifiedSharedMemoryClause *) {
  1599. OS << "unified_shared_memory";
  1600. }
  1601. void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
  1602. OS << "reverse_offload";
  1603. }
  1604. void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
  1605. OMPDynamicAllocatorsClause *) {
  1606. OS << "dynamic_allocators";
  1607. }
  1608. void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
  1609. OMPAtomicDefaultMemOrderClause *Node) {
  1610. OS << "atomic_default_mem_order("
  1611. << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
  1612. Node->getAtomicDefaultMemOrderKind())
  1613. << ")";
  1614. }
  1615. void OMPClausePrinter::VisitOMPAtClause(OMPAtClause *Node) {
  1616. OS << "at(" << getOpenMPSimpleClauseTypeName(OMPC_at, Node->getAtKind())
  1617. << ")";
  1618. }
  1619. void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) {
  1620. OS << "severity("
  1621. << getOpenMPSimpleClauseTypeName(OMPC_severity, Node->getSeverityKind())
  1622. << ")";
  1623. }
  1624. void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause *Node) {
  1625. OS << "message(\""
  1626. << cast<StringLiteral>(Node->getMessageString())->getString() << "\")";
  1627. }
  1628. void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
  1629. OS << "schedule(";
  1630. if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
  1631. OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
  1632. Node->getFirstScheduleModifier());
  1633. if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
  1634. OS << ", ";
  1635. OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
  1636. Node->getSecondScheduleModifier());
  1637. }
  1638. OS << ": ";
  1639. }
  1640. OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
  1641. if (auto *E = Node->getChunkSize()) {
  1642. OS << ", ";
  1643. E->printPretty(OS, nullptr, Policy);
  1644. }
  1645. OS << ")";
  1646. }
  1647. void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
  1648. OS << "ordered";
  1649. if (auto *Num = Node->getNumForLoops()) {
  1650. OS << "(";
  1651. Num->printPretty(OS, nullptr, Policy, 0);
  1652. OS << ")";
  1653. }
  1654. }
  1655. void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
  1656. OS << "nowait";
  1657. }
  1658. void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
  1659. OS << "untied";
  1660. }
  1661. void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
  1662. OS << "nogroup";
  1663. }
  1664. void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
  1665. OS << "mergeable";
  1666. }
  1667. void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
  1668. void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
  1669. void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) {
  1670. OS << "update";
  1671. if (Node->isExtended()) {
  1672. OS << "(";
  1673. OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
  1674. Node->getDependencyKind());
  1675. OS << ")";
  1676. }
  1677. }
  1678. void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
  1679. OS << "capture";
  1680. }
  1681. void OMPClausePrinter::VisitOMPCompareClause(OMPCompareClause *) {
  1682. OS << "compare";
  1683. }
  1684. void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
  1685. OS << "seq_cst";
  1686. }
  1687. void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
  1688. OS << "acq_rel";
  1689. }
  1690. void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
  1691. OS << "acquire";
  1692. }
  1693. void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
  1694. OS << "release";
  1695. }
  1696. void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
  1697. OS << "relaxed";
  1698. }
  1699. void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
  1700. OS << "threads";
  1701. }
  1702. void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
  1703. void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
  1704. OS << "device(";
  1705. OpenMPDeviceClauseModifier Modifier = Node->getModifier();
  1706. if (Modifier != OMPC_DEVICE_unknown) {
  1707. OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
  1708. << ": ";
  1709. }
  1710. Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
  1711. OS << ")";
  1712. }
  1713. void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
  1714. OS << "num_teams(";
  1715. Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
  1716. OS << ")";
  1717. }
  1718. void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
  1719. OS << "thread_limit(";
  1720. Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
  1721. OS << ")";
  1722. }
  1723. void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
  1724. OS << "priority(";
  1725. Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
  1726. OS << ")";
  1727. }
  1728. void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
  1729. OS << "grainsize(";
  1730. OpenMPGrainsizeClauseModifier Modifier = Node->getModifier();
  1731. if (Modifier != OMPC_GRAINSIZE_unknown) {
  1732. OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
  1733. << ": ";
  1734. }
  1735. Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
  1736. OS << ")";
  1737. }
  1738. void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
  1739. OS << "num_tasks(";
  1740. OpenMPNumTasksClauseModifier Modifier = Node->getModifier();
  1741. if (Modifier != OMPC_NUMTASKS_unknown) {
  1742. OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
  1743. << ": ";
  1744. }
  1745. Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
  1746. OS << ")";
  1747. }
  1748. void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
  1749. OS << "hint(";
  1750. Node->getHint()->printPretty(OS, nullptr, Policy, 0);
  1751. OS << ")";
  1752. }
  1753. void OMPClausePrinter::VisitOMPInitClause(OMPInitClause *Node) {
  1754. OS << "init(";
  1755. bool First = true;
  1756. for (const Expr *E : Node->prefs()) {
  1757. if (First)
  1758. OS << "prefer_type(";
  1759. else
  1760. OS << ",";
  1761. E->printPretty(OS, nullptr, Policy);
  1762. First = false;
  1763. }
  1764. if (!First)
  1765. OS << "), ";
  1766. if (Node->getIsTarget())
  1767. OS << "target";
  1768. if (Node->getIsTargetSync()) {
  1769. if (Node->getIsTarget())
  1770. OS << ", ";
  1771. OS << "targetsync";
  1772. }
  1773. OS << " : ";
  1774. Node->getInteropVar()->printPretty(OS, nullptr, Policy);
  1775. OS << ")";
  1776. }
  1777. void OMPClausePrinter::VisitOMPUseClause(OMPUseClause *Node) {
  1778. OS << "use(";
  1779. Node->getInteropVar()->printPretty(OS, nullptr, Policy);
  1780. OS << ")";
  1781. }
  1782. void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *Node) {
  1783. OS << "destroy";
  1784. if (Expr *E = Node->getInteropVar()) {
  1785. OS << "(";
  1786. E->printPretty(OS, nullptr, Policy);
  1787. OS << ")";
  1788. }
  1789. }
  1790. void OMPClausePrinter::VisitOMPNovariantsClause(OMPNovariantsClause *Node) {
  1791. OS << "novariants";
  1792. if (Expr *E = Node->getCondition()) {
  1793. OS << "(";
  1794. E->printPretty(OS, nullptr, Policy, 0);
  1795. OS << ")";
  1796. }
  1797. }
  1798. void OMPClausePrinter::VisitOMPNocontextClause(OMPNocontextClause *Node) {
  1799. OS << "nocontext";
  1800. if (Expr *E = Node->getCondition()) {
  1801. OS << "(";
  1802. E->printPretty(OS, nullptr, Policy, 0);
  1803. OS << ")";
  1804. }
  1805. }
  1806. template<typename T>
  1807. void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
  1808. for (typename T::varlist_iterator I = Node->varlist_begin(),
  1809. E = Node->varlist_end();
  1810. I != E; ++I) {
  1811. assert(*I && "Expected non-null Stmt");
  1812. OS << (I == Node->varlist_begin() ? StartSym : ',');
  1813. if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
  1814. if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
  1815. DRE->printPretty(OS, nullptr, Policy, 0);
  1816. else
  1817. DRE->getDecl()->printQualifiedName(OS);
  1818. } else
  1819. (*I)->printPretty(OS, nullptr, Policy, 0);
  1820. }
  1821. }
  1822. void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
  1823. if (Node->varlist_empty())
  1824. return;
  1825. OS << "allocate";
  1826. if (Expr *Allocator = Node->getAllocator()) {
  1827. OS << "(";
  1828. Allocator->printPretty(OS, nullptr, Policy, 0);
  1829. OS << ":";
  1830. VisitOMPClauseList(Node, ' ');
  1831. } else {
  1832. VisitOMPClauseList(Node, '(');
  1833. }
  1834. OS << ")";
  1835. }
  1836. void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
  1837. if (!Node->varlist_empty()) {
  1838. OS << "private";
  1839. VisitOMPClauseList(Node, '(');
  1840. OS << ")";
  1841. }
  1842. }
  1843. void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
  1844. if (!Node->varlist_empty()) {
  1845. OS << "firstprivate";
  1846. VisitOMPClauseList(Node, '(');
  1847. OS << ")";
  1848. }
  1849. }
  1850. void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
  1851. if (!Node->varlist_empty()) {
  1852. OS << "lastprivate";
  1853. OpenMPLastprivateModifier LPKind = Node->getKind();
  1854. if (LPKind != OMPC_LASTPRIVATE_unknown) {
  1855. OS << "("
  1856. << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
  1857. << ":";
  1858. }
  1859. VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' ');
  1860. OS << ")";
  1861. }
  1862. }
  1863. void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
  1864. if (!Node->varlist_empty()) {
  1865. OS << "shared";
  1866. VisitOMPClauseList(Node, '(');
  1867. OS << ")";
  1868. }
  1869. }
  1870. void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
  1871. if (!Node->varlist_empty()) {
  1872. OS << "reduction(";
  1873. if (Node->getModifierLoc().isValid())
  1874. OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier())
  1875. << ", ";
  1876. NestedNameSpecifier *QualifierLoc =
  1877. Node->getQualifierLoc().getNestedNameSpecifier();
  1878. OverloadedOperatorKind OOK =
  1879. Node->getNameInfo().getName().getCXXOverloadedOperator();
  1880. if (QualifierLoc == nullptr && OOK != OO_None) {
  1881. // Print reduction identifier in C format
  1882. OS << getOperatorSpelling(OOK);
  1883. } else {
  1884. // Use C++ format
  1885. if (QualifierLoc != nullptr)
  1886. QualifierLoc->print(OS, Policy);
  1887. OS << Node->getNameInfo();
  1888. }
  1889. OS << ":";
  1890. VisitOMPClauseList(Node, ' ');
  1891. OS << ")";
  1892. }
  1893. }
  1894. void OMPClausePrinter::VisitOMPTaskReductionClause(
  1895. OMPTaskReductionClause *Node) {
  1896. if (!Node->varlist_empty()) {
  1897. OS << "task_reduction(";
  1898. NestedNameSpecifier *QualifierLoc =
  1899. Node->getQualifierLoc().getNestedNameSpecifier();
  1900. OverloadedOperatorKind OOK =
  1901. Node->getNameInfo().getName().getCXXOverloadedOperator();
  1902. if (QualifierLoc == nullptr && OOK != OO_None) {
  1903. // Print reduction identifier in C format
  1904. OS << getOperatorSpelling(OOK);
  1905. } else {
  1906. // Use C++ format
  1907. if (QualifierLoc != nullptr)
  1908. QualifierLoc->print(OS, Policy);
  1909. OS << Node->getNameInfo();
  1910. }
  1911. OS << ":";
  1912. VisitOMPClauseList(Node, ' ');
  1913. OS << ")";
  1914. }
  1915. }
  1916. void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
  1917. if (!Node->varlist_empty()) {
  1918. OS << "in_reduction(";
  1919. NestedNameSpecifier *QualifierLoc =
  1920. Node->getQualifierLoc().getNestedNameSpecifier();
  1921. OverloadedOperatorKind OOK =
  1922. Node->getNameInfo().getName().getCXXOverloadedOperator();
  1923. if (QualifierLoc == nullptr && OOK != OO_None) {
  1924. // Print reduction identifier in C format
  1925. OS << getOperatorSpelling(OOK);
  1926. } else {
  1927. // Use C++ format
  1928. if (QualifierLoc != nullptr)
  1929. QualifierLoc->print(OS, Policy);
  1930. OS << Node->getNameInfo();
  1931. }
  1932. OS << ":";
  1933. VisitOMPClauseList(Node, ' ');
  1934. OS << ")";
  1935. }
  1936. }
  1937. void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
  1938. if (!Node->varlist_empty()) {
  1939. OS << "linear";
  1940. if (Node->getModifierLoc().isValid()) {
  1941. OS << '('
  1942. << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
  1943. }
  1944. VisitOMPClauseList(Node, '(');
  1945. if (Node->getModifierLoc().isValid())
  1946. OS << ')';
  1947. if (Node->getStep() != nullptr) {
  1948. OS << ": ";
  1949. Node->getStep()->printPretty(OS, nullptr, Policy, 0);
  1950. }
  1951. OS << ")";
  1952. }
  1953. }
  1954. void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
  1955. if (!Node->varlist_empty()) {
  1956. OS << "aligned";
  1957. VisitOMPClauseList(Node, '(');
  1958. if (Node->getAlignment() != nullptr) {
  1959. OS << ": ";
  1960. Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
  1961. }
  1962. OS << ")";
  1963. }
  1964. }
  1965. void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
  1966. if (!Node->varlist_empty()) {
  1967. OS << "copyin";
  1968. VisitOMPClauseList(Node, '(');
  1969. OS << ")";
  1970. }
  1971. }
  1972. void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
  1973. if (!Node->varlist_empty()) {
  1974. OS << "copyprivate";
  1975. VisitOMPClauseList(Node, '(');
  1976. OS << ")";
  1977. }
  1978. }
  1979. void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
  1980. if (!Node->varlist_empty()) {
  1981. VisitOMPClauseList(Node, '(');
  1982. OS << ")";
  1983. }
  1984. }
  1985. void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) {
  1986. OS << "(";
  1987. Node->getDepobj()->printPretty(OS, nullptr, Policy, 0);
  1988. OS << ")";
  1989. }
  1990. void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
  1991. OS << "depend(";
  1992. if (Expr *DepModifier = Node->getModifier()) {
  1993. DepModifier->printPretty(OS, nullptr, Policy);
  1994. OS << ", ";
  1995. }
  1996. OpenMPDependClauseKind DepKind = Node->getDependencyKind();
  1997. OpenMPDependClauseKind PrintKind = DepKind;
  1998. bool IsOmpAllMemory = false;
  1999. if (PrintKind == OMPC_DEPEND_outallmemory) {
  2000. PrintKind = OMPC_DEPEND_out;
  2001. IsOmpAllMemory = true;
  2002. } else if (PrintKind == OMPC_DEPEND_inoutallmemory) {
  2003. PrintKind = OMPC_DEPEND_inout;
  2004. IsOmpAllMemory = true;
  2005. }
  2006. OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), PrintKind);
  2007. if (!Node->varlist_empty() || IsOmpAllMemory)
  2008. OS << " :";
  2009. VisitOMPClauseList(Node, ' ');
  2010. if (IsOmpAllMemory) {
  2011. OS << (Node->varlist_empty() ? " " : ",");
  2012. OS << "omp_all_memory";
  2013. }
  2014. OS << ")";
  2015. }
  2016. template <typename T>
  2017. static void PrintMapper(raw_ostream &OS, T *Node,
  2018. const PrintingPolicy &Policy) {
  2019. OS << '(';
  2020. NestedNameSpecifier *MapperNNS =
  2021. Node->getMapperQualifierLoc().getNestedNameSpecifier();
  2022. if (MapperNNS)
  2023. MapperNNS->print(OS, Policy);
  2024. OS << Node->getMapperIdInfo() << ')';
  2025. }
  2026. template <typename T>
  2027. static void PrintIterator(raw_ostream &OS, T *Node,
  2028. const PrintingPolicy &Policy) {
  2029. if (Expr *IteratorModifier = Node->getIteratorModifier())
  2030. IteratorModifier->printPretty(OS, nullptr, Policy);
  2031. }
  2032. void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
  2033. if (!Node->varlist_empty()) {
  2034. OS << "map(";
  2035. if (Node->getMapType() != OMPC_MAP_unknown) {
  2036. for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
  2037. if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
  2038. if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_iterator) {
  2039. PrintIterator(OS, Node, Policy);
  2040. } else {
  2041. OS << getOpenMPSimpleClauseTypeName(OMPC_map,
  2042. Node->getMapTypeModifier(I));
  2043. if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper)
  2044. PrintMapper(OS, Node, Policy);
  2045. }
  2046. OS << ',';
  2047. }
  2048. }
  2049. OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
  2050. OS << ':';
  2051. }
  2052. VisitOMPClauseList(Node, ' ');
  2053. OS << ")";
  2054. }
  2055. }
  2056. template <typename T> void OMPClausePrinter::VisitOMPMotionClause(T *Node) {
  2057. if (Node->varlist_empty())
  2058. return;
  2059. OS << getOpenMPClauseName(Node->getClauseKind());
  2060. unsigned ModifierCount = 0;
  2061. for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
  2062. if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown)
  2063. ++ModifierCount;
  2064. }
  2065. if (ModifierCount) {
  2066. OS << '(';
  2067. for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
  2068. if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) {
  2069. OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
  2070. Node->getMotionModifier(I));
  2071. if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
  2072. PrintMapper(OS, Node, Policy);
  2073. if (I < ModifierCount - 1)
  2074. OS << ", ";
  2075. }
  2076. }
  2077. OS << ':';
  2078. VisitOMPClauseList(Node, ' ');
  2079. } else {
  2080. VisitOMPClauseList(Node, '(');
  2081. }
  2082. OS << ")";
  2083. }
  2084. void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
  2085. VisitOMPMotionClause(Node);
  2086. }
  2087. void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
  2088. VisitOMPMotionClause(Node);
  2089. }
  2090. void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
  2091. OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
  2092. OMPC_dist_schedule, Node->getDistScheduleKind());
  2093. if (auto *E = Node->getChunkSize()) {
  2094. OS << ", ";
  2095. E->printPretty(OS, nullptr, Policy);
  2096. }
  2097. OS << ")";
  2098. }
  2099. void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
  2100. OS << "defaultmap(";
  2101. OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
  2102. Node->getDefaultmapModifier());
  2103. if (Node->getDefaultmapKind() != OMPC_DEFAULTMAP_unknown) {
  2104. OS << ": ";
  2105. OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
  2106. Node->getDefaultmapKind());
  2107. }
  2108. OS << ")";
  2109. }
  2110. void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
  2111. if (!Node->varlist_empty()) {
  2112. OS << "use_device_ptr";
  2113. VisitOMPClauseList(Node, '(');
  2114. OS << ")";
  2115. }
  2116. }
  2117. void OMPClausePrinter::VisitOMPUseDeviceAddrClause(
  2118. OMPUseDeviceAddrClause *Node) {
  2119. if (!Node->varlist_empty()) {
  2120. OS << "use_device_addr";
  2121. VisitOMPClauseList(Node, '(');
  2122. OS << ")";
  2123. }
  2124. }
  2125. void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
  2126. if (!Node->varlist_empty()) {
  2127. OS << "is_device_ptr";
  2128. VisitOMPClauseList(Node, '(');
  2129. OS << ")";
  2130. }
  2131. }
  2132. void OMPClausePrinter::VisitOMPHasDeviceAddrClause(OMPHasDeviceAddrClause *Node) {
  2133. if (!Node->varlist_empty()) {
  2134. OS << "has_device_addr";
  2135. VisitOMPClauseList(Node, '(');
  2136. OS << ")";
  2137. }
  2138. }
  2139. void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
  2140. if (!Node->varlist_empty()) {
  2141. OS << "nontemporal";
  2142. VisitOMPClauseList(Node, '(');
  2143. OS << ")";
  2144. }
  2145. }
  2146. void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
  2147. OS << "order(";
  2148. if (Node->getModifier() != OMPC_ORDER_MODIFIER_unknown) {
  2149. OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getModifier());
  2150. OS << ": ";
  2151. }
  2152. OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind()) << ")";
  2153. }
  2154. void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
  2155. if (!Node->varlist_empty()) {
  2156. OS << "inclusive";
  2157. VisitOMPClauseList(Node, '(');
  2158. OS << ")";
  2159. }
  2160. }
  2161. void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
  2162. if (!Node->varlist_empty()) {
  2163. OS << "exclusive";
  2164. VisitOMPClauseList(Node, '(');
  2165. OS << ")";
  2166. }
  2167. }
  2168. void OMPClausePrinter::VisitOMPUsesAllocatorsClause(
  2169. OMPUsesAllocatorsClause *Node) {
  2170. if (Node->getNumberOfAllocators() == 0)
  2171. return;
  2172. OS << "uses_allocators(";
  2173. for (unsigned I = 0, E = Node->getNumberOfAllocators(); I < E; ++I) {
  2174. OMPUsesAllocatorsClause::Data Data = Node->getAllocatorData(I);
  2175. Data.Allocator->printPretty(OS, nullptr, Policy);
  2176. if (Data.AllocatorTraits) {
  2177. OS << "(";
  2178. Data.AllocatorTraits->printPretty(OS, nullptr, Policy);
  2179. OS << ")";
  2180. }
  2181. if (I < E - 1)
  2182. OS << ",";
  2183. }
  2184. OS << ")";
  2185. }
  2186. void OMPClausePrinter::VisitOMPAffinityClause(OMPAffinityClause *Node) {
  2187. if (Node->varlist_empty())
  2188. return;
  2189. OS << "affinity";
  2190. char StartSym = '(';
  2191. if (Expr *Modifier = Node->getModifier()) {
  2192. OS << "(";
  2193. Modifier->printPretty(OS, nullptr, Policy);
  2194. OS << " :";
  2195. StartSym = ' ';
  2196. }
  2197. VisitOMPClauseList(Node, StartSym);
  2198. OS << ")";
  2199. }
  2200. void OMPClausePrinter::VisitOMPFilterClause(OMPFilterClause *Node) {
  2201. OS << "filter(";
  2202. Node->getThreadID()->printPretty(OS, nullptr, Policy, 0);
  2203. OS << ")";
  2204. }
  2205. void OMPClausePrinter::VisitOMPBindClause(OMPBindClause *Node) {
  2206. OS << "bind("
  2207. << getOpenMPSimpleClauseTypeName(OMPC_bind, unsigned(Node->getBindKind()))
  2208. << ")";
  2209. }
  2210. void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
  2211. OMPXDynCGroupMemClause *Node) {
  2212. OS << "ompx_dyn_cgroup_mem(";
  2213. Node->getSize()->printPretty(OS, nullptr, Policy, 0);
  2214. OS << ")";
  2215. }
  2216. void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
  2217. VariantMatchInfo &VMI) const {
  2218. for (const OMPTraitSet &Set : Sets) {
  2219. for (const OMPTraitSelector &Selector : Set.Selectors) {
  2220. // User conditions are special as we evaluate the condition here.
  2221. if (Selector.Kind == TraitSelector::user_condition) {
  2222. assert(Selector.ScoreOrCondition &&
  2223. "Ill-formed user condition, expected condition expression!");
  2224. assert(Selector.Properties.size() == 1 &&
  2225. Selector.Properties.front().Kind ==
  2226. TraitProperty::user_condition_unknown &&
  2227. "Ill-formed user condition, expected unknown trait property!");
  2228. if (std::optional<APSInt> CondVal =
  2229. Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))
  2230. VMI.addTrait(CondVal->isZero() ? TraitProperty::user_condition_false
  2231. : TraitProperty::user_condition_true,
  2232. "<condition>");
  2233. else
  2234. VMI.addTrait(TraitProperty::user_condition_false, "<condition>");
  2235. continue;
  2236. }
  2237. std::optional<llvm::APSInt> Score;
  2238. llvm::APInt *ScorePtr = nullptr;
  2239. if (Selector.ScoreOrCondition) {
  2240. if ((Score = Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)))
  2241. ScorePtr = &*Score;
  2242. else
  2243. VMI.addTrait(TraitProperty::user_condition_false,
  2244. "<non-constant-score>");
  2245. }
  2246. for (const OMPTraitProperty &Property : Selector.Properties)
  2247. VMI.addTrait(Set.Kind, Property.Kind, Property.RawString, ScorePtr);
  2248. if (Set.Kind != TraitSet::construct)
  2249. continue;
  2250. // TODO: This might not hold once we implement SIMD properly.
  2251. assert(Selector.Properties.size() == 1 &&
  2252. Selector.Properties.front().Kind ==
  2253. getOpenMPContextTraitPropertyForSelector(
  2254. Selector.Kind) &&
  2255. "Ill-formed construct selector!");
  2256. }
  2257. }
  2258. }
  2259. void OMPTraitInfo::print(llvm::raw_ostream &OS,
  2260. const PrintingPolicy &Policy) const {
  2261. bool FirstSet = true;
  2262. for (const OMPTraitSet &Set : Sets) {
  2263. if (!FirstSet)
  2264. OS << ", ";
  2265. FirstSet = false;
  2266. OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
  2267. bool FirstSelector = true;
  2268. for (const OMPTraitSelector &Selector : Set.Selectors) {
  2269. if (!FirstSelector)
  2270. OS << ", ";
  2271. FirstSelector = false;
  2272. OS << getOpenMPContextTraitSelectorName(Selector.Kind);
  2273. bool AllowsTraitScore = false;
  2274. bool RequiresProperty = false;
  2275. isValidTraitSelectorForTraitSet(
  2276. Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
  2277. if (!RequiresProperty)
  2278. continue;
  2279. OS << "(";
  2280. if (Selector.Kind == TraitSelector::user_condition) {
  2281. if (Selector.ScoreOrCondition)
  2282. Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
  2283. else
  2284. OS << "...";
  2285. } else {
  2286. if (Selector.ScoreOrCondition) {
  2287. OS << "score(";
  2288. Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
  2289. OS << "): ";
  2290. }
  2291. bool FirstProperty = true;
  2292. for (const OMPTraitProperty &Property : Selector.Properties) {
  2293. if (!FirstProperty)
  2294. OS << ", ";
  2295. FirstProperty = false;
  2296. OS << getOpenMPContextTraitPropertyName(Property.Kind,
  2297. Property.RawString);
  2298. }
  2299. }
  2300. OS << ")";
  2301. }
  2302. OS << "}";
  2303. }
  2304. }
  2305. std::string OMPTraitInfo::getMangledName() const {
  2306. std::string MangledName;
  2307. llvm::raw_string_ostream OS(MangledName);
  2308. for (const OMPTraitSet &Set : Sets) {
  2309. OS << '$' << 'S' << unsigned(Set.Kind);
  2310. for (const OMPTraitSelector &Selector : Set.Selectors) {
  2311. bool AllowsTraitScore = false;
  2312. bool RequiresProperty = false;
  2313. isValidTraitSelectorForTraitSet(
  2314. Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
  2315. OS << '$' << 's' << unsigned(Selector.Kind);
  2316. if (!RequiresProperty ||
  2317. Selector.Kind == TraitSelector::user_condition)
  2318. continue;
  2319. for (const OMPTraitProperty &Property : Selector.Properties)
  2320. OS << '$' << 'P'
  2321. << getOpenMPContextTraitPropertyName(Property.Kind,
  2322. Property.RawString);
  2323. }
  2324. }
  2325. return MangledName;
  2326. }
  2327. OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
  2328. unsigned long U;
  2329. do {
  2330. if (!MangledName.consume_front("$S"))
  2331. break;
  2332. if (MangledName.consumeInteger(10, U))
  2333. break;
  2334. Sets.push_back(OMPTraitSet());
  2335. OMPTraitSet &Set = Sets.back();
  2336. Set.Kind = TraitSet(U);
  2337. do {
  2338. if (!MangledName.consume_front("$s"))
  2339. break;
  2340. if (MangledName.consumeInteger(10, U))
  2341. break;
  2342. Set.Selectors.push_back(OMPTraitSelector());
  2343. OMPTraitSelector &Selector = Set.Selectors.back();
  2344. Selector.Kind = TraitSelector(U);
  2345. do {
  2346. if (!MangledName.consume_front("$P"))
  2347. break;
  2348. Selector.Properties.push_back(OMPTraitProperty());
  2349. OMPTraitProperty &Property = Selector.Properties.back();
  2350. std::pair<StringRef, StringRef> PropRestPair = MangledName.split('$');
  2351. Property.RawString = PropRestPair.first;
  2352. Property.Kind = getOpenMPContextTraitPropertyKind(
  2353. Set.Kind, Selector.Kind, PropRestPair.first);
  2354. MangledName = MangledName.drop_front(PropRestPair.first.size());
  2355. } while (true);
  2356. } while (true);
  2357. } while (true);
  2358. }
  2359. llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
  2360. const OMPTraitInfo &TI) {
  2361. LangOptions LO;
  2362. PrintingPolicy Policy(LO);
  2363. TI.print(OS, Policy);
  2364. return OS;
  2365. }
  2366. llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
  2367. const OMPTraitInfo *TI) {
  2368. return TI ? OS << *TI : OS;
  2369. }
  2370. TargetOMPContext::TargetOMPContext(
  2371. ASTContext &ASTCtx, std::function<void(StringRef)> &&DiagUnknownTrait,
  2372. const FunctionDecl *CurrentFunctionDecl,
  2373. ArrayRef<llvm::omp::TraitProperty> ConstructTraits)
  2374. : OMPContext(ASTCtx.getLangOpts().OpenMPIsDevice,
  2375. ASTCtx.getTargetInfo().getTriple()),
  2376. FeatureValidityCheck([&](StringRef FeatureName) {
  2377. return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName);
  2378. }),
  2379. DiagUnknownTrait(std::move(DiagUnknownTrait)) {
  2380. ASTCtx.getFunctionFeatureMap(FeatureMap, CurrentFunctionDecl);
  2381. for (llvm::omp::TraitProperty Property : ConstructTraits)
  2382. addTrait(Property);
  2383. }
  2384. bool TargetOMPContext::matchesISATrait(StringRef RawString) const {
  2385. auto It = FeatureMap.find(RawString);
  2386. if (It != FeatureMap.end())
  2387. return It->second;
  2388. if (!FeatureValidityCheck(RawString))
  2389. DiagUnknownTrait(RawString);
  2390. return false;
  2391. }