OpenMPClause.cpp 90 KB

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