StmtProfile.cpp 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389
  1. //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
  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 Stmt::Profile method, which builds a unique bit
  10. // representation that identifies a statement/expression.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/ASTContext.h"
  14. #include "clang/AST/DeclCXX.h"
  15. #include "clang/AST/DeclObjC.h"
  16. #include "clang/AST/DeclTemplate.h"
  17. #include "clang/AST/Expr.h"
  18. #include "clang/AST/ExprCXX.h"
  19. #include "clang/AST/ExprObjC.h"
  20. #include "clang/AST/ExprOpenMP.h"
  21. #include "clang/AST/ODRHash.h"
  22. #include "clang/AST/OpenMPClause.h"
  23. #include "clang/AST/StmtVisitor.h"
  24. #include "llvm/ADT/FoldingSet.h"
  25. using namespace clang;
  26. namespace {
  27. class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
  28. protected:
  29. llvm::FoldingSetNodeID &ID;
  30. bool Canonical;
  31. public:
  32. StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical)
  33. : ID(ID), Canonical(Canonical) {}
  34. virtual ~StmtProfiler() {}
  35. void VisitStmt(const Stmt *S);
  36. void VisitStmtNoChildren(const Stmt *S) {
  37. HandleStmtClass(S->getStmtClass());
  38. }
  39. virtual void HandleStmtClass(Stmt::StmtClass SC) = 0;
  40. #define STMT(Node, Base) void Visit##Node(const Node *S);
  41. #include "clang/AST/StmtNodes.inc"
  42. /// Visit a declaration that is referenced within an expression
  43. /// or statement.
  44. virtual void VisitDecl(const Decl *D) = 0;
  45. /// Visit a type that is referenced within an expression or
  46. /// statement.
  47. virtual void VisitType(QualType T) = 0;
  48. /// Visit a name that occurs within an expression or statement.
  49. virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0;
  50. /// Visit identifiers that are not in Decl's or Type's.
  51. virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0;
  52. /// Visit a nested-name-specifier that occurs within an expression
  53. /// or statement.
  54. virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0;
  55. /// Visit a template name that occurs within an expression or
  56. /// statement.
  57. virtual void VisitTemplateName(TemplateName Name) = 0;
  58. /// Visit template arguments that occur within an expression or
  59. /// statement.
  60. void VisitTemplateArguments(const TemplateArgumentLoc *Args,
  61. unsigned NumArgs);
  62. /// Visit a single template argument.
  63. void VisitTemplateArgument(const TemplateArgument &Arg);
  64. };
  65. class StmtProfilerWithPointers : public StmtProfiler {
  66. const ASTContext &Context;
  67. public:
  68. StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID,
  69. const ASTContext &Context, bool Canonical)
  70. : StmtProfiler(ID, Canonical), Context(Context) {}
  71. private:
  72. void HandleStmtClass(Stmt::StmtClass SC) override {
  73. ID.AddInteger(SC);
  74. }
  75. void VisitDecl(const Decl *D) override {
  76. ID.AddInteger(D ? D->getKind() : 0);
  77. if (Canonical && D) {
  78. if (const NonTypeTemplateParmDecl *NTTP =
  79. dyn_cast<NonTypeTemplateParmDecl>(D)) {
  80. ID.AddInteger(NTTP->getDepth());
  81. ID.AddInteger(NTTP->getIndex());
  82. ID.AddBoolean(NTTP->isParameterPack());
  83. VisitType(NTTP->getType());
  84. return;
  85. }
  86. if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
  87. // The Itanium C++ ABI uses the type, scope depth, and scope
  88. // index of a parameter when mangling expressions that involve
  89. // function parameters, so we will use the parameter's type for
  90. // establishing function parameter identity. That way, our
  91. // definition of "equivalent" (per C++ [temp.over.link]) is at
  92. // least as strong as the definition of "equivalent" used for
  93. // name mangling.
  94. VisitType(Parm->getType());
  95. ID.AddInteger(Parm->getFunctionScopeDepth());
  96. ID.AddInteger(Parm->getFunctionScopeIndex());
  97. return;
  98. }
  99. if (const TemplateTypeParmDecl *TTP =
  100. dyn_cast<TemplateTypeParmDecl>(D)) {
  101. ID.AddInteger(TTP->getDepth());
  102. ID.AddInteger(TTP->getIndex());
  103. ID.AddBoolean(TTP->isParameterPack());
  104. return;
  105. }
  106. if (const TemplateTemplateParmDecl *TTP =
  107. dyn_cast<TemplateTemplateParmDecl>(D)) {
  108. ID.AddInteger(TTP->getDepth());
  109. ID.AddInteger(TTP->getIndex());
  110. ID.AddBoolean(TTP->isParameterPack());
  111. return;
  112. }
  113. }
  114. ID.AddPointer(D ? D->getCanonicalDecl() : nullptr);
  115. }
  116. void VisitType(QualType T) override {
  117. if (Canonical && !T.isNull())
  118. T = Context.getCanonicalType(T);
  119. ID.AddPointer(T.getAsOpaquePtr());
  120. }
  121. void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override {
  122. ID.AddPointer(Name.getAsOpaquePtr());
  123. }
  124. void VisitIdentifierInfo(IdentifierInfo *II) override {
  125. ID.AddPointer(II);
  126. }
  127. void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
  128. if (Canonical)
  129. NNS = Context.getCanonicalNestedNameSpecifier(NNS);
  130. ID.AddPointer(NNS);
  131. }
  132. void VisitTemplateName(TemplateName Name) override {
  133. if (Canonical)
  134. Name = Context.getCanonicalTemplateName(Name);
  135. Name.Profile(ID);
  136. }
  137. };
  138. class StmtProfilerWithoutPointers : public StmtProfiler {
  139. ODRHash &Hash;
  140. public:
  141. StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
  142. : StmtProfiler(ID, false), Hash(Hash) {}
  143. private:
  144. void HandleStmtClass(Stmt::StmtClass SC) override {
  145. if (SC == Stmt::UnresolvedLookupExprClass) {
  146. // Pretend that the name looked up is a Decl due to how templates
  147. // handle some Decl lookups.
  148. ID.AddInteger(Stmt::DeclRefExprClass);
  149. } else {
  150. ID.AddInteger(SC);
  151. }
  152. }
  153. void VisitType(QualType T) override {
  154. Hash.AddQualType(T);
  155. }
  156. void VisitName(DeclarationName Name, bool TreatAsDecl) override {
  157. if (TreatAsDecl) {
  158. // A Decl can be null, so each Decl is preceded by a boolean to
  159. // store its nullness. Add a boolean here to match.
  160. ID.AddBoolean(true);
  161. }
  162. Hash.AddDeclarationName(Name, TreatAsDecl);
  163. }
  164. void VisitIdentifierInfo(IdentifierInfo *II) override {
  165. ID.AddBoolean(II);
  166. if (II) {
  167. Hash.AddIdentifierInfo(II);
  168. }
  169. }
  170. void VisitDecl(const Decl *D) override {
  171. ID.AddBoolean(D);
  172. if (D) {
  173. Hash.AddDecl(D);
  174. }
  175. }
  176. void VisitTemplateName(TemplateName Name) override {
  177. Hash.AddTemplateName(Name);
  178. }
  179. void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
  180. ID.AddBoolean(NNS);
  181. if (NNS) {
  182. Hash.AddNestedNameSpecifier(NNS);
  183. }
  184. }
  185. };
  186. }
  187. void StmtProfiler::VisitStmt(const Stmt *S) {
  188. assert(S && "Requires non-null Stmt pointer");
  189. VisitStmtNoChildren(S);
  190. for (const Stmt *SubStmt : S->children()) {
  191. if (SubStmt)
  192. Visit(SubStmt);
  193. else
  194. ID.AddInteger(0);
  195. }
  196. }
  197. void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
  198. VisitStmt(S);
  199. for (const auto *D : S->decls())
  200. VisitDecl(D);
  201. }
  202. void StmtProfiler::VisitNullStmt(const NullStmt *S) {
  203. VisitStmt(S);
  204. }
  205. void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
  206. VisitStmt(S);
  207. }
  208. void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
  209. VisitStmt(S);
  210. }
  211. void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
  212. VisitStmt(S);
  213. }
  214. void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
  215. VisitStmt(S);
  216. VisitDecl(S->getDecl());
  217. }
  218. void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
  219. VisitStmt(S);
  220. // TODO: maybe visit attributes?
  221. }
  222. void StmtProfiler::VisitIfStmt(const IfStmt *S) {
  223. VisitStmt(S);
  224. VisitDecl(S->getConditionVariable());
  225. }
  226. void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
  227. VisitStmt(S);
  228. VisitDecl(S->getConditionVariable());
  229. }
  230. void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
  231. VisitStmt(S);
  232. VisitDecl(S->getConditionVariable());
  233. }
  234. void StmtProfiler::VisitDoStmt(const DoStmt *S) {
  235. VisitStmt(S);
  236. }
  237. void StmtProfiler::VisitForStmt(const ForStmt *S) {
  238. VisitStmt(S);
  239. }
  240. void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
  241. VisitStmt(S);
  242. VisitDecl(S->getLabel());
  243. }
  244. void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
  245. VisitStmt(S);
  246. }
  247. void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
  248. VisitStmt(S);
  249. }
  250. void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
  251. VisitStmt(S);
  252. }
  253. void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
  254. VisitStmt(S);
  255. }
  256. void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
  257. VisitStmt(S);
  258. ID.AddBoolean(S->isVolatile());
  259. ID.AddBoolean(S->isSimple());
  260. VisitStringLiteral(S->getAsmString());
  261. ID.AddInteger(S->getNumOutputs());
  262. for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
  263. ID.AddString(S->getOutputName(I));
  264. VisitStringLiteral(S->getOutputConstraintLiteral(I));
  265. }
  266. ID.AddInteger(S->getNumInputs());
  267. for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
  268. ID.AddString(S->getInputName(I));
  269. VisitStringLiteral(S->getInputConstraintLiteral(I));
  270. }
  271. ID.AddInteger(S->getNumClobbers());
  272. for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
  273. VisitStringLiteral(S->getClobberStringLiteral(I));
  274. ID.AddInteger(S->getNumLabels());
  275. for (auto *L : S->labels())
  276. VisitDecl(L->getLabel());
  277. }
  278. void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
  279. // FIXME: Implement MS style inline asm statement profiler.
  280. VisitStmt(S);
  281. }
  282. void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
  283. VisitStmt(S);
  284. VisitType(S->getCaughtType());
  285. }
  286. void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
  287. VisitStmt(S);
  288. }
  289. void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
  290. VisitStmt(S);
  291. }
  292. void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
  293. VisitStmt(S);
  294. ID.AddBoolean(S->isIfExists());
  295. VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
  296. VisitName(S->getNameInfo().getName());
  297. }
  298. void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
  299. VisitStmt(S);
  300. }
  301. void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
  302. VisitStmt(S);
  303. }
  304. void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
  305. VisitStmt(S);
  306. }
  307. void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
  308. VisitStmt(S);
  309. }
  310. void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
  311. VisitStmt(S);
  312. }
  313. void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
  314. VisitStmt(S);
  315. }
  316. void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
  317. VisitStmt(S);
  318. ID.AddBoolean(S->hasEllipsis());
  319. if (S->getCatchParamDecl())
  320. VisitType(S->getCatchParamDecl()->getType());
  321. }
  322. void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
  323. VisitStmt(S);
  324. }
  325. void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
  326. VisitStmt(S);
  327. }
  328. void
  329. StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
  330. VisitStmt(S);
  331. }
  332. void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
  333. VisitStmt(S);
  334. }
  335. void
  336. StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
  337. VisitStmt(S);
  338. }
  339. namespace {
  340. class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
  341. StmtProfiler *Profiler;
  342. /// Process clauses with list of variables.
  343. template <typename T>
  344. void VisitOMPClauseList(T *Node);
  345. public:
  346. OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
  347. #define GEN_CLANG_CLAUSE_CLASS
  348. #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
  349. #include "llvm/Frontend/OpenMP/OMP.inc"
  350. void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
  351. void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
  352. };
  353. void OMPClauseProfiler::VistOMPClauseWithPreInit(
  354. const OMPClauseWithPreInit *C) {
  355. if (auto *S = C->getPreInitStmt())
  356. Profiler->VisitStmt(S);
  357. }
  358. void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
  359. const OMPClauseWithPostUpdate *C) {
  360. VistOMPClauseWithPreInit(C);
  361. if (auto *E = C->getPostUpdateExpr())
  362. Profiler->VisitStmt(E);
  363. }
  364. void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
  365. VistOMPClauseWithPreInit(C);
  366. if (C->getCondition())
  367. Profiler->VisitStmt(C->getCondition());
  368. }
  369. void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
  370. VistOMPClauseWithPreInit(C);
  371. if (C->getCondition())
  372. Profiler->VisitStmt(C->getCondition());
  373. }
  374. void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
  375. VistOMPClauseWithPreInit(C);
  376. if (C->getNumThreads())
  377. Profiler->VisitStmt(C->getNumThreads());
  378. }
  379. void OMPClauseProfiler::VisitOMPAlignClause(const OMPAlignClause *C) {
  380. if (C->getAlignment())
  381. Profiler->VisitStmt(C->getAlignment());
  382. }
  383. void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
  384. if (C->getSafelen())
  385. Profiler->VisitStmt(C->getSafelen());
  386. }
  387. void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
  388. if (C->getSimdlen())
  389. Profiler->VisitStmt(C->getSimdlen());
  390. }
  391. void OMPClauseProfiler::VisitOMPSizesClause(const OMPSizesClause *C) {
  392. for (auto *E : C->getSizesRefs())
  393. if (E)
  394. Profiler->VisitExpr(E);
  395. }
  396. void OMPClauseProfiler::VisitOMPFullClause(const OMPFullClause *C) {}
  397. void OMPClauseProfiler::VisitOMPPartialClause(const OMPPartialClause *C) {
  398. if (const Expr *Factor = C->getFactor())
  399. Profiler->VisitExpr(Factor);
  400. }
  401. void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
  402. if (C->getAllocator())
  403. Profiler->VisitStmt(C->getAllocator());
  404. }
  405. void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
  406. if (C->getNumForLoops())
  407. Profiler->VisitStmt(C->getNumForLoops());
  408. }
  409. void OMPClauseProfiler::VisitOMPDetachClause(const OMPDetachClause *C) {
  410. if (Expr *Evt = C->getEventHandler())
  411. Profiler->VisitStmt(Evt);
  412. }
  413. void OMPClauseProfiler::VisitOMPNovariantsClause(const OMPNovariantsClause *C) {
  414. VistOMPClauseWithPreInit(C);
  415. if (C->getCondition())
  416. Profiler->VisitStmt(C->getCondition());
  417. }
  418. void OMPClauseProfiler::VisitOMPNocontextClause(const OMPNocontextClause *C) {
  419. VistOMPClauseWithPreInit(C);
  420. if (C->getCondition())
  421. Profiler->VisitStmt(C->getCondition());
  422. }
  423. void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
  424. void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
  425. void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
  426. const OMPUnifiedAddressClause *C) {}
  427. void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
  428. const OMPUnifiedSharedMemoryClause *C) {}
  429. void OMPClauseProfiler::VisitOMPReverseOffloadClause(
  430. const OMPReverseOffloadClause *C) {}
  431. void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
  432. const OMPDynamicAllocatorsClause *C) {}
  433. void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
  434. const OMPAtomicDefaultMemOrderClause *C) {}
  435. void OMPClauseProfiler::VisitOMPAtClause(const OMPAtClause *C) {}
  436. void OMPClauseProfiler::VisitOMPSeverityClause(const OMPSeverityClause *C) {}
  437. void OMPClauseProfiler::VisitOMPMessageClause(const OMPMessageClause *C) {
  438. if (C->getMessageString())
  439. Profiler->VisitStmt(C->getMessageString());
  440. }
  441. void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
  442. VistOMPClauseWithPreInit(C);
  443. if (auto *S = C->getChunkSize())
  444. Profiler->VisitStmt(S);
  445. }
  446. void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
  447. if (auto *Num = C->getNumForLoops())
  448. Profiler->VisitStmt(Num);
  449. }
  450. void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
  451. void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
  452. void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
  453. void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
  454. void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
  455. void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
  456. void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
  457. void OMPClauseProfiler::VisitOMPCompareClause(const OMPCompareClause *) {}
  458. void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
  459. void OMPClauseProfiler::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
  460. void OMPClauseProfiler::VisitOMPAcquireClause(const OMPAcquireClause *) {}
  461. void OMPClauseProfiler::VisitOMPReleaseClause(const OMPReleaseClause *) {}
  462. void OMPClauseProfiler::VisitOMPRelaxedClause(const OMPRelaxedClause *) {}
  463. void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
  464. void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
  465. void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
  466. void OMPClauseProfiler::VisitOMPInitClause(const OMPInitClause *C) {
  467. VisitOMPClauseList(C);
  468. }
  469. void OMPClauseProfiler::VisitOMPUseClause(const OMPUseClause *C) {
  470. if (C->getInteropVar())
  471. Profiler->VisitStmt(C->getInteropVar());
  472. }
  473. void OMPClauseProfiler::VisitOMPDestroyClause(const OMPDestroyClause *C) {
  474. if (C->getInteropVar())
  475. Profiler->VisitStmt(C->getInteropVar());
  476. }
  477. void OMPClauseProfiler::VisitOMPFilterClause(const OMPFilterClause *C) {
  478. VistOMPClauseWithPreInit(C);
  479. if (C->getThreadID())
  480. Profiler->VisitStmt(C->getThreadID());
  481. }
  482. template<typename T>
  483. void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
  484. for (auto *E : Node->varlists()) {
  485. if (E)
  486. Profiler->VisitStmt(E);
  487. }
  488. }
  489. void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
  490. VisitOMPClauseList(C);
  491. for (auto *E : C->private_copies()) {
  492. if (E)
  493. Profiler->VisitStmt(E);
  494. }
  495. }
  496. void
  497. OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
  498. VisitOMPClauseList(C);
  499. VistOMPClauseWithPreInit(C);
  500. for (auto *E : C->private_copies()) {
  501. if (E)
  502. Profiler->VisitStmt(E);
  503. }
  504. for (auto *E : C->inits()) {
  505. if (E)
  506. Profiler->VisitStmt(E);
  507. }
  508. }
  509. void
  510. OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
  511. VisitOMPClauseList(C);
  512. VistOMPClauseWithPostUpdate(C);
  513. for (auto *E : C->source_exprs()) {
  514. if (E)
  515. Profiler->VisitStmt(E);
  516. }
  517. for (auto *E : C->destination_exprs()) {
  518. if (E)
  519. Profiler->VisitStmt(E);
  520. }
  521. for (auto *E : C->assignment_ops()) {
  522. if (E)
  523. Profiler->VisitStmt(E);
  524. }
  525. }
  526. void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
  527. VisitOMPClauseList(C);
  528. }
  529. void OMPClauseProfiler::VisitOMPReductionClause(
  530. const OMPReductionClause *C) {
  531. Profiler->VisitNestedNameSpecifier(
  532. C->getQualifierLoc().getNestedNameSpecifier());
  533. Profiler->VisitName(C->getNameInfo().getName());
  534. VisitOMPClauseList(C);
  535. VistOMPClauseWithPostUpdate(C);
  536. for (auto *E : C->privates()) {
  537. if (E)
  538. Profiler->VisitStmt(E);
  539. }
  540. for (auto *E : C->lhs_exprs()) {
  541. if (E)
  542. Profiler->VisitStmt(E);
  543. }
  544. for (auto *E : C->rhs_exprs()) {
  545. if (E)
  546. Profiler->VisitStmt(E);
  547. }
  548. for (auto *E : C->reduction_ops()) {
  549. if (E)
  550. Profiler->VisitStmt(E);
  551. }
  552. if (C->getModifier() == clang::OMPC_REDUCTION_inscan) {
  553. for (auto *E : C->copy_ops()) {
  554. if (E)
  555. Profiler->VisitStmt(E);
  556. }
  557. for (auto *E : C->copy_array_temps()) {
  558. if (E)
  559. Profiler->VisitStmt(E);
  560. }
  561. for (auto *E : C->copy_array_elems()) {
  562. if (E)
  563. Profiler->VisitStmt(E);
  564. }
  565. }
  566. }
  567. void OMPClauseProfiler::VisitOMPTaskReductionClause(
  568. const OMPTaskReductionClause *C) {
  569. Profiler->VisitNestedNameSpecifier(
  570. C->getQualifierLoc().getNestedNameSpecifier());
  571. Profiler->VisitName(C->getNameInfo().getName());
  572. VisitOMPClauseList(C);
  573. VistOMPClauseWithPostUpdate(C);
  574. for (auto *E : C->privates()) {
  575. if (E)
  576. Profiler->VisitStmt(E);
  577. }
  578. for (auto *E : C->lhs_exprs()) {
  579. if (E)
  580. Profiler->VisitStmt(E);
  581. }
  582. for (auto *E : C->rhs_exprs()) {
  583. if (E)
  584. Profiler->VisitStmt(E);
  585. }
  586. for (auto *E : C->reduction_ops()) {
  587. if (E)
  588. Profiler->VisitStmt(E);
  589. }
  590. }
  591. void OMPClauseProfiler::VisitOMPInReductionClause(
  592. const OMPInReductionClause *C) {
  593. Profiler->VisitNestedNameSpecifier(
  594. C->getQualifierLoc().getNestedNameSpecifier());
  595. Profiler->VisitName(C->getNameInfo().getName());
  596. VisitOMPClauseList(C);
  597. VistOMPClauseWithPostUpdate(C);
  598. for (auto *E : C->privates()) {
  599. if (E)
  600. Profiler->VisitStmt(E);
  601. }
  602. for (auto *E : C->lhs_exprs()) {
  603. if (E)
  604. Profiler->VisitStmt(E);
  605. }
  606. for (auto *E : C->rhs_exprs()) {
  607. if (E)
  608. Profiler->VisitStmt(E);
  609. }
  610. for (auto *E : C->reduction_ops()) {
  611. if (E)
  612. Profiler->VisitStmt(E);
  613. }
  614. for (auto *E : C->taskgroup_descriptors()) {
  615. if (E)
  616. Profiler->VisitStmt(E);
  617. }
  618. }
  619. void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
  620. VisitOMPClauseList(C);
  621. VistOMPClauseWithPostUpdate(C);
  622. for (auto *E : C->privates()) {
  623. if (E)
  624. Profiler->VisitStmt(E);
  625. }
  626. for (auto *E : C->inits()) {
  627. if (E)
  628. Profiler->VisitStmt(E);
  629. }
  630. for (auto *E : C->updates()) {
  631. if (E)
  632. Profiler->VisitStmt(E);
  633. }
  634. for (auto *E : C->finals()) {
  635. if (E)
  636. Profiler->VisitStmt(E);
  637. }
  638. if (C->getStep())
  639. Profiler->VisitStmt(C->getStep());
  640. if (C->getCalcStep())
  641. Profiler->VisitStmt(C->getCalcStep());
  642. }
  643. void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
  644. VisitOMPClauseList(C);
  645. if (C->getAlignment())
  646. Profiler->VisitStmt(C->getAlignment());
  647. }
  648. void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
  649. VisitOMPClauseList(C);
  650. for (auto *E : C->source_exprs()) {
  651. if (E)
  652. Profiler->VisitStmt(E);
  653. }
  654. for (auto *E : C->destination_exprs()) {
  655. if (E)
  656. Profiler->VisitStmt(E);
  657. }
  658. for (auto *E : C->assignment_ops()) {
  659. if (E)
  660. Profiler->VisitStmt(E);
  661. }
  662. }
  663. void
  664. OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
  665. VisitOMPClauseList(C);
  666. for (auto *E : C->source_exprs()) {
  667. if (E)
  668. Profiler->VisitStmt(E);
  669. }
  670. for (auto *E : C->destination_exprs()) {
  671. if (E)
  672. Profiler->VisitStmt(E);
  673. }
  674. for (auto *E : C->assignment_ops()) {
  675. if (E)
  676. Profiler->VisitStmt(E);
  677. }
  678. }
  679. void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
  680. VisitOMPClauseList(C);
  681. }
  682. void OMPClauseProfiler::VisitOMPDepobjClause(const OMPDepobjClause *C) {
  683. if (const Expr *Depobj = C->getDepobj())
  684. Profiler->VisitStmt(Depobj);
  685. }
  686. void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
  687. VisitOMPClauseList(C);
  688. }
  689. void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
  690. if (C->getDevice())
  691. Profiler->VisitStmt(C->getDevice());
  692. }
  693. void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
  694. VisitOMPClauseList(C);
  695. }
  696. void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
  697. if (Expr *Allocator = C->getAllocator())
  698. Profiler->VisitStmt(Allocator);
  699. VisitOMPClauseList(C);
  700. }
  701. void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
  702. VistOMPClauseWithPreInit(C);
  703. if (C->getNumTeams())
  704. Profiler->VisitStmt(C->getNumTeams());
  705. }
  706. void OMPClauseProfiler::VisitOMPThreadLimitClause(
  707. const OMPThreadLimitClause *C) {
  708. VistOMPClauseWithPreInit(C);
  709. if (C->getThreadLimit())
  710. Profiler->VisitStmt(C->getThreadLimit());
  711. }
  712. void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
  713. VistOMPClauseWithPreInit(C);
  714. if (C->getPriority())
  715. Profiler->VisitStmt(C->getPriority());
  716. }
  717. void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
  718. VistOMPClauseWithPreInit(C);
  719. if (C->getGrainsize())
  720. Profiler->VisitStmt(C->getGrainsize());
  721. }
  722. void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
  723. VistOMPClauseWithPreInit(C);
  724. if (C->getNumTasks())
  725. Profiler->VisitStmt(C->getNumTasks());
  726. }
  727. void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
  728. if (C->getHint())
  729. Profiler->VisitStmt(C->getHint());
  730. }
  731. void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
  732. VisitOMPClauseList(C);
  733. }
  734. void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
  735. VisitOMPClauseList(C);
  736. }
  737. void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
  738. const OMPUseDevicePtrClause *C) {
  739. VisitOMPClauseList(C);
  740. }
  741. void OMPClauseProfiler::VisitOMPUseDeviceAddrClause(
  742. const OMPUseDeviceAddrClause *C) {
  743. VisitOMPClauseList(C);
  744. }
  745. void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
  746. const OMPIsDevicePtrClause *C) {
  747. VisitOMPClauseList(C);
  748. }
  749. void OMPClauseProfiler::VisitOMPHasDeviceAddrClause(
  750. const OMPHasDeviceAddrClause *C) {
  751. VisitOMPClauseList(C);
  752. }
  753. void OMPClauseProfiler::VisitOMPNontemporalClause(
  754. const OMPNontemporalClause *C) {
  755. VisitOMPClauseList(C);
  756. for (auto *E : C->private_refs())
  757. Profiler->VisitStmt(E);
  758. }
  759. void OMPClauseProfiler::VisitOMPInclusiveClause(const OMPInclusiveClause *C) {
  760. VisitOMPClauseList(C);
  761. }
  762. void OMPClauseProfiler::VisitOMPExclusiveClause(const OMPExclusiveClause *C) {
  763. VisitOMPClauseList(C);
  764. }
  765. void OMPClauseProfiler::VisitOMPUsesAllocatorsClause(
  766. const OMPUsesAllocatorsClause *C) {
  767. for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
  768. OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
  769. Profiler->VisitStmt(D.Allocator);
  770. if (D.AllocatorTraits)
  771. Profiler->VisitStmt(D.AllocatorTraits);
  772. }
  773. }
  774. void OMPClauseProfiler::VisitOMPAffinityClause(const OMPAffinityClause *C) {
  775. if (const Expr *Modifier = C->getModifier())
  776. Profiler->VisitStmt(Modifier);
  777. for (const Expr *E : C->varlists())
  778. Profiler->VisitStmt(E);
  779. }
  780. void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {}
  781. void OMPClauseProfiler::VisitOMPBindClause(const OMPBindClause *C) {}
  782. void OMPClauseProfiler::VisitOMPXDynCGroupMemClause(
  783. const OMPXDynCGroupMemClause *C) {
  784. VistOMPClauseWithPreInit(C);
  785. if (Expr *Size = C->getSize())
  786. Profiler->VisitStmt(Size);
  787. }
  788. } // namespace
  789. void
  790. StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
  791. VisitStmt(S);
  792. OMPClauseProfiler P(this);
  793. ArrayRef<OMPClause *> Clauses = S->clauses();
  794. for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
  795. I != E; ++I)
  796. if (*I)
  797. P.Visit(*I);
  798. }
  799. void StmtProfiler::VisitOMPCanonicalLoop(const OMPCanonicalLoop *L) {
  800. VisitStmt(L);
  801. }
  802. void StmtProfiler::VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *S) {
  803. VisitOMPExecutableDirective(S);
  804. }
  805. void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
  806. VisitOMPLoopBasedDirective(S);
  807. }
  808. void StmtProfiler::VisitOMPMetaDirective(const OMPMetaDirective *S) {
  809. VisitOMPExecutableDirective(S);
  810. }
  811. void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
  812. VisitOMPExecutableDirective(S);
  813. }
  814. void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
  815. VisitOMPLoopDirective(S);
  816. }
  817. void StmtProfiler::VisitOMPLoopTransformationDirective(
  818. const OMPLoopTransformationDirective *S) {
  819. VisitOMPLoopBasedDirective(S);
  820. }
  821. void StmtProfiler::VisitOMPTileDirective(const OMPTileDirective *S) {
  822. VisitOMPLoopTransformationDirective(S);
  823. }
  824. void StmtProfiler::VisitOMPUnrollDirective(const OMPUnrollDirective *S) {
  825. VisitOMPLoopTransformationDirective(S);
  826. }
  827. void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
  828. VisitOMPLoopDirective(S);
  829. }
  830. void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
  831. VisitOMPLoopDirective(S);
  832. }
  833. void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
  834. VisitOMPExecutableDirective(S);
  835. }
  836. void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
  837. VisitOMPExecutableDirective(S);
  838. }
  839. void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
  840. VisitOMPExecutableDirective(S);
  841. }
  842. void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
  843. VisitOMPExecutableDirective(S);
  844. }
  845. void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
  846. VisitOMPExecutableDirective(S);
  847. VisitName(S->getDirectiveName().getName());
  848. }
  849. void
  850. StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
  851. VisitOMPLoopDirective(S);
  852. }
  853. void StmtProfiler::VisitOMPParallelForSimdDirective(
  854. const OMPParallelForSimdDirective *S) {
  855. VisitOMPLoopDirective(S);
  856. }
  857. void StmtProfiler::VisitOMPParallelMasterDirective(
  858. const OMPParallelMasterDirective *S) {
  859. VisitOMPExecutableDirective(S);
  860. }
  861. void StmtProfiler::VisitOMPParallelMaskedDirective(
  862. const OMPParallelMaskedDirective *S) {
  863. VisitOMPExecutableDirective(S);
  864. }
  865. void StmtProfiler::VisitOMPParallelSectionsDirective(
  866. const OMPParallelSectionsDirective *S) {
  867. VisitOMPExecutableDirective(S);
  868. }
  869. void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
  870. VisitOMPExecutableDirective(S);
  871. }
  872. void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
  873. VisitOMPExecutableDirective(S);
  874. }
  875. void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
  876. VisitOMPExecutableDirective(S);
  877. }
  878. void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
  879. VisitOMPExecutableDirective(S);
  880. }
  881. void StmtProfiler::VisitOMPErrorDirective(const OMPErrorDirective *S) {
  882. VisitOMPExecutableDirective(S);
  883. }
  884. void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
  885. VisitOMPExecutableDirective(S);
  886. if (const Expr *E = S->getReductionRef())
  887. VisitStmt(E);
  888. }
  889. void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
  890. VisitOMPExecutableDirective(S);
  891. }
  892. void StmtProfiler::VisitOMPDepobjDirective(const OMPDepobjDirective *S) {
  893. VisitOMPExecutableDirective(S);
  894. }
  895. void StmtProfiler::VisitOMPScanDirective(const OMPScanDirective *S) {
  896. VisitOMPExecutableDirective(S);
  897. }
  898. void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
  899. VisitOMPExecutableDirective(S);
  900. }
  901. void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
  902. VisitOMPExecutableDirective(S);
  903. }
  904. void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
  905. VisitOMPExecutableDirective(S);
  906. }
  907. void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
  908. VisitOMPExecutableDirective(S);
  909. }
  910. void StmtProfiler::VisitOMPTargetEnterDataDirective(
  911. const OMPTargetEnterDataDirective *S) {
  912. VisitOMPExecutableDirective(S);
  913. }
  914. void StmtProfiler::VisitOMPTargetExitDataDirective(
  915. const OMPTargetExitDataDirective *S) {
  916. VisitOMPExecutableDirective(S);
  917. }
  918. void StmtProfiler::VisitOMPTargetParallelDirective(
  919. const OMPTargetParallelDirective *S) {
  920. VisitOMPExecutableDirective(S);
  921. }
  922. void StmtProfiler::VisitOMPTargetParallelForDirective(
  923. const OMPTargetParallelForDirective *S) {
  924. VisitOMPExecutableDirective(S);
  925. }
  926. void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
  927. VisitOMPExecutableDirective(S);
  928. }
  929. void StmtProfiler::VisitOMPCancellationPointDirective(
  930. const OMPCancellationPointDirective *S) {
  931. VisitOMPExecutableDirective(S);
  932. }
  933. void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
  934. VisitOMPExecutableDirective(S);
  935. }
  936. void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
  937. VisitOMPLoopDirective(S);
  938. }
  939. void StmtProfiler::VisitOMPTaskLoopSimdDirective(
  940. const OMPTaskLoopSimdDirective *S) {
  941. VisitOMPLoopDirective(S);
  942. }
  943. void StmtProfiler::VisitOMPMasterTaskLoopDirective(
  944. const OMPMasterTaskLoopDirective *S) {
  945. VisitOMPLoopDirective(S);
  946. }
  947. void StmtProfiler::VisitOMPMaskedTaskLoopDirective(
  948. const OMPMaskedTaskLoopDirective *S) {
  949. VisitOMPLoopDirective(S);
  950. }
  951. void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
  952. const OMPMasterTaskLoopSimdDirective *S) {
  953. VisitOMPLoopDirective(S);
  954. }
  955. void StmtProfiler::VisitOMPMaskedTaskLoopSimdDirective(
  956. const OMPMaskedTaskLoopSimdDirective *S) {
  957. VisitOMPLoopDirective(S);
  958. }
  959. void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
  960. const OMPParallelMasterTaskLoopDirective *S) {
  961. VisitOMPLoopDirective(S);
  962. }
  963. void StmtProfiler::VisitOMPParallelMaskedTaskLoopDirective(
  964. const OMPParallelMaskedTaskLoopDirective *S) {
  965. VisitOMPLoopDirective(S);
  966. }
  967. void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective(
  968. const OMPParallelMasterTaskLoopSimdDirective *S) {
  969. VisitOMPLoopDirective(S);
  970. }
  971. void StmtProfiler::VisitOMPParallelMaskedTaskLoopSimdDirective(
  972. const OMPParallelMaskedTaskLoopSimdDirective *S) {
  973. VisitOMPLoopDirective(S);
  974. }
  975. void StmtProfiler::VisitOMPDistributeDirective(
  976. const OMPDistributeDirective *S) {
  977. VisitOMPLoopDirective(S);
  978. }
  979. void OMPClauseProfiler::VisitOMPDistScheduleClause(
  980. const OMPDistScheduleClause *C) {
  981. VistOMPClauseWithPreInit(C);
  982. if (auto *S = C->getChunkSize())
  983. Profiler->VisitStmt(S);
  984. }
  985. void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
  986. void StmtProfiler::VisitOMPTargetUpdateDirective(
  987. const OMPTargetUpdateDirective *S) {
  988. VisitOMPExecutableDirective(S);
  989. }
  990. void StmtProfiler::VisitOMPDistributeParallelForDirective(
  991. const OMPDistributeParallelForDirective *S) {
  992. VisitOMPLoopDirective(S);
  993. }
  994. void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
  995. const OMPDistributeParallelForSimdDirective *S) {
  996. VisitOMPLoopDirective(S);
  997. }
  998. void StmtProfiler::VisitOMPDistributeSimdDirective(
  999. const OMPDistributeSimdDirective *S) {
  1000. VisitOMPLoopDirective(S);
  1001. }
  1002. void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
  1003. const OMPTargetParallelForSimdDirective *S) {
  1004. VisitOMPLoopDirective(S);
  1005. }
  1006. void StmtProfiler::VisitOMPTargetSimdDirective(
  1007. const OMPTargetSimdDirective *S) {
  1008. VisitOMPLoopDirective(S);
  1009. }
  1010. void StmtProfiler::VisitOMPTeamsDistributeDirective(
  1011. const OMPTeamsDistributeDirective *S) {
  1012. VisitOMPLoopDirective(S);
  1013. }
  1014. void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
  1015. const OMPTeamsDistributeSimdDirective *S) {
  1016. VisitOMPLoopDirective(S);
  1017. }
  1018. void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
  1019. const OMPTeamsDistributeParallelForSimdDirective *S) {
  1020. VisitOMPLoopDirective(S);
  1021. }
  1022. void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
  1023. const OMPTeamsDistributeParallelForDirective *S) {
  1024. VisitOMPLoopDirective(S);
  1025. }
  1026. void StmtProfiler::VisitOMPTargetTeamsDirective(
  1027. const OMPTargetTeamsDirective *S) {
  1028. VisitOMPExecutableDirective(S);
  1029. }
  1030. void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
  1031. const OMPTargetTeamsDistributeDirective *S) {
  1032. VisitOMPLoopDirective(S);
  1033. }
  1034. void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
  1035. const OMPTargetTeamsDistributeParallelForDirective *S) {
  1036. VisitOMPLoopDirective(S);
  1037. }
  1038. void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
  1039. const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
  1040. VisitOMPLoopDirective(S);
  1041. }
  1042. void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
  1043. const OMPTargetTeamsDistributeSimdDirective *S) {
  1044. VisitOMPLoopDirective(S);
  1045. }
  1046. void StmtProfiler::VisitOMPInteropDirective(const OMPInteropDirective *S) {
  1047. VisitOMPExecutableDirective(S);
  1048. }
  1049. void StmtProfiler::VisitOMPDispatchDirective(const OMPDispatchDirective *S) {
  1050. VisitOMPExecutableDirective(S);
  1051. }
  1052. void StmtProfiler::VisitOMPMaskedDirective(const OMPMaskedDirective *S) {
  1053. VisitOMPExecutableDirective(S);
  1054. }
  1055. void StmtProfiler::VisitOMPGenericLoopDirective(
  1056. const OMPGenericLoopDirective *S) {
  1057. VisitOMPLoopDirective(S);
  1058. }
  1059. void StmtProfiler::VisitOMPTeamsGenericLoopDirective(
  1060. const OMPTeamsGenericLoopDirective *S) {
  1061. VisitOMPLoopDirective(S);
  1062. }
  1063. void StmtProfiler::VisitOMPTargetTeamsGenericLoopDirective(
  1064. const OMPTargetTeamsGenericLoopDirective *S) {
  1065. VisitOMPLoopDirective(S);
  1066. }
  1067. void StmtProfiler::VisitOMPParallelGenericLoopDirective(
  1068. const OMPParallelGenericLoopDirective *S) {
  1069. VisitOMPLoopDirective(S);
  1070. }
  1071. void StmtProfiler::VisitOMPTargetParallelGenericLoopDirective(
  1072. const OMPTargetParallelGenericLoopDirective *S) {
  1073. VisitOMPLoopDirective(S);
  1074. }
  1075. void StmtProfiler::VisitExpr(const Expr *S) {
  1076. VisitStmt(S);
  1077. }
  1078. void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
  1079. VisitExpr(S);
  1080. }
  1081. void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
  1082. VisitExpr(S);
  1083. if (!Canonical)
  1084. VisitNestedNameSpecifier(S->getQualifier());
  1085. VisitDecl(S->getDecl());
  1086. if (!Canonical) {
  1087. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1088. if (S->hasExplicitTemplateArgs())
  1089. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1090. }
  1091. }
  1092. void StmtProfiler::VisitSYCLUniqueStableNameExpr(
  1093. const SYCLUniqueStableNameExpr *S) {
  1094. VisitExpr(S);
  1095. VisitType(S->getTypeSourceInfo()->getType());
  1096. }
  1097. void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
  1098. VisitExpr(S);
  1099. ID.AddInteger(S->getIdentKind());
  1100. }
  1101. void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
  1102. VisitExpr(S);
  1103. S->getValue().Profile(ID);
  1104. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  1105. }
  1106. void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
  1107. VisitExpr(S);
  1108. S->getValue().Profile(ID);
  1109. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  1110. }
  1111. void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
  1112. VisitExpr(S);
  1113. ID.AddInteger(S->getKind());
  1114. ID.AddInteger(S->getValue());
  1115. }
  1116. void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
  1117. VisitExpr(S);
  1118. S->getValue().Profile(ID);
  1119. ID.AddBoolean(S->isExact());
  1120. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  1121. }
  1122. void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
  1123. VisitExpr(S);
  1124. }
  1125. void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
  1126. VisitExpr(S);
  1127. ID.AddString(S->getBytes());
  1128. ID.AddInteger(S->getKind());
  1129. }
  1130. void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
  1131. VisitExpr(S);
  1132. }
  1133. void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
  1134. VisitExpr(S);
  1135. }
  1136. void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
  1137. VisitExpr(S);
  1138. ID.AddInteger(S->getOpcode());
  1139. }
  1140. void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
  1141. VisitType(S->getTypeSourceInfo()->getType());
  1142. unsigned n = S->getNumComponents();
  1143. for (unsigned i = 0; i < n; ++i) {
  1144. const OffsetOfNode &ON = S->getComponent(i);
  1145. ID.AddInteger(ON.getKind());
  1146. switch (ON.getKind()) {
  1147. case OffsetOfNode::Array:
  1148. // Expressions handled below.
  1149. break;
  1150. case OffsetOfNode::Field:
  1151. VisitDecl(ON.getField());
  1152. break;
  1153. case OffsetOfNode::Identifier:
  1154. VisitIdentifierInfo(ON.getFieldName());
  1155. break;
  1156. case OffsetOfNode::Base:
  1157. // These nodes are implicit, and therefore don't need profiling.
  1158. break;
  1159. }
  1160. }
  1161. VisitExpr(S);
  1162. }
  1163. void
  1164. StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
  1165. VisitExpr(S);
  1166. ID.AddInteger(S->getKind());
  1167. if (S->isArgumentType())
  1168. VisitType(S->getArgumentType());
  1169. }
  1170. void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
  1171. VisitExpr(S);
  1172. }
  1173. void StmtProfiler::VisitMatrixSubscriptExpr(const MatrixSubscriptExpr *S) {
  1174. VisitExpr(S);
  1175. }
  1176. void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
  1177. VisitExpr(S);
  1178. }
  1179. void StmtProfiler::VisitOMPArrayShapingExpr(const OMPArrayShapingExpr *S) {
  1180. VisitExpr(S);
  1181. }
  1182. void StmtProfiler::VisitOMPIteratorExpr(const OMPIteratorExpr *S) {
  1183. VisitExpr(S);
  1184. for (unsigned I = 0, E = S->numOfIterators(); I < E; ++I)
  1185. VisitDecl(S->getIteratorDecl(I));
  1186. }
  1187. void StmtProfiler::VisitCallExpr(const CallExpr *S) {
  1188. VisitExpr(S);
  1189. }
  1190. void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
  1191. VisitExpr(S);
  1192. VisitDecl(S->getMemberDecl());
  1193. if (!Canonical)
  1194. VisitNestedNameSpecifier(S->getQualifier());
  1195. ID.AddBoolean(S->isArrow());
  1196. }
  1197. void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
  1198. VisitExpr(S);
  1199. ID.AddBoolean(S->isFileScope());
  1200. }
  1201. void StmtProfiler::VisitCastExpr(const CastExpr *S) {
  1202. VisitExpr(S);
  1203. }
  1204. void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
  1205. VisitCastExpr(S);
  1206. ID.AddInteger(S->getValueKind());
  1207. }
  1208. void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
  1209. VisitCastExpr(S);
  1210. VisitType(S->getTypeAsWritten());
  1211. }
  1212. void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
  1213. VisitExplicitCastExpr(S);
  1214. }
  1215. void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
  1216. VisitExpr(S);
  1217. ID.AddInteger(S->getOpcode());
  1218. }
  1219. void
  1220. StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
  1221. VisitBinaryOperator(S);
  1222. }
  1223. void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
  1224. VisitExpr(S);
  1225. }
  1226. void StmtProfiler::VisitBinaryConditionalOperator(
  1227. const BinaryConditionalOperator *S) {
  1228. VisitExpr(S);
  1229. }
  1230. void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
  1231. VisitExpr(S);
  1232. VisitDecl(S->getLabel());
  1233. }
  1234. void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
  1235. VisitExpr(S);
  1236. }
  1237. void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
  1238. VisitExpr(S);
  1239. }
  1240. void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
  1241. VisitExpr(S);
  1242. }
  1243. void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
  1244. VisitExpr(S);
  1245. }
  1246. void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
  1247. VisitExpr(S);
  1248. }
  1249. void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
  1250. VisitExpr(S);
  1251. }
  1252. void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
  1253. if (S->getSyntacticForm()) {
  1254. VisitInitListExpr(S->getSyntacticForm());
  1255. return;
  1256. }
  1257. VisitExpr(S);
  1258. }
  1259. void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
  1260. VisitExpr(S);
  1261. ID.AddBoolean(S->usesGNUSyntax());
  1262. for (const DesignatedInitExpr::Designator &D : S->designators()) {
  1263. if (D.isFieldDesignator()) {
  1264. ID.AddInteger(0);
  1265. VisitName(D.getFieldName());
  1266. continue;
  1267. }
  1268. if (D.isArrayDesignator()) {
  1269. ID.AddInteger(1);
  1270. } else {
  1271. assert(D.isArrayRangeDesignator());
  1272. ID.AddInteger(2);
  1273. }
  1274. ID.AddInteger(D.getFirstExprIndex());
  1275. }
  1276. }
  1277. // Seems that if VisitInitListExpr() only works on the syntactic form of an
  1278. // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
  1279. void StmtProfiler::VisitDesignatedInitUpdateExpr(
  1280. const DesignatedInitUpdateExpr *S) {
  1281. llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
  1282. "initializer");
  1283. }
  1284. void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
  1285. VisitExpr(S);
  1286. }
  1287. void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
  1288. VisitExpr(S);
  1289. }
  1290. void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
  1291. llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
  1292. }
  1293. void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
  1294. VisitExpr(S);
  1295. }
  1296. void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
  1297. VisitExpr(S);
  1298. VisitName(&S->getAccessor());
  1299. }
  1300. void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
  1301. VisitExpr(S);
  1302. VisitDecl(S->getBlockDecl());
  1303. }
  1304. void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
  1305. VisitExpr(S);
  1306. for (const GenericSelectionExpr::ConstAssociation Assoc :
  1307. S->associations()) {
  1308. QualType T = Assoc.getType();
  1309. if (T.isNull())
  1310. ID.AddPointer(nullptr);
  1311. else
  1312. VisitType(T);
  1313. VisitExpr(Assoc.getAssociationExpr());
  1314. }
  1315. }
  1316. void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
  1317. VisitExpr(S);
  1318. for (PseudoObjectExpr::const_semantics_iterator
  1319. i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
  1320. // Normally, we would not profile the source expressions of OVEs.
  1321. if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
  1322. Visit(OVE->getSourceExpr());
  1323. }
  1324. void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
  1325. VisitExpr(S);
  1326. ID.AddInteger(S->getOp());
  1327. }
  1328. void StmtProfiler::VisitConceptSpecializationExpr(
  1329. const ConceptSpecializationExpr *S) {
  1330. VisitExpr(S);
  1331. VisitDecl(S->getNamedConcept());
  1332. for (const TemplateArgument &Arg : S->getTemplateArguments())
  1333. VisitTemplateArgument(Arg);
  1334. }
  1335. void StmtProfiler::VisitRequiresExpr(const RequiresExpr *S) {
  1336. VisitExpr(S);
  1337. ID.AddInteger(S->getLocalParameters().size());
  1338. for (ParmVarDecl *LocalParam : S->getLocalParameters())
  1339. VisitDecl(LocalParam);
  1340. ID.AddInteger(S->getRequirements().size());
  1341. for (concepts::Requirement *Req : S->getRequirements()) {
  1342. if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
  1343. ID.AddInteger(concepts::Requirement::RK_Type);
  1344. ID.AddBoolean(TypeReq->isSubstitutionFailure());
  1345. if (!TypeReq->isSubstitutionFailure())
  1346. VisitType(TypeReq->getType()->getType());
  1347. } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
  1348. ID.AddInteger(concepts::Requirement::RK_Compound);
  1349. ID.AddBoolean(ExprReq->isExprSubstitutionFailure());
  1350. if (!ExprReq->isExprSubstitutionFailure())
  1351. Visit(ExprReq->getExpr());
  1352. // C++2a [expr.prim.req.compound]p1 Example:
  1353. // [...] The compound-requirement in C1 requires that x++ is a valid
  1354. // expression. It is equivalent to the simple-requirement x++; [...]
  1355. // We therefore do not profile isSimple() here.
  1356. ID.AddBoolean(ExprReq->getNoexceptLoc().isValid());
  1357. const concepts::ExprRequirement::ReturnTypeRequirement &RetReq =
  1358. ExprReq->getReturnTypeRequirement();
  1359. if (RetReq.isEmpty()) {
  1360. ID.AddInteger(0);
  1361. } else if (RetReq.isTypeConstraint()) {
  1362. ID.AddInteger(1);
  1363. Visit(RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint());
  1364. } else {
  1365. assert(RetReq.isSubstitutionFailure());
  1366. ID.AddInteger(2);
  1367. }
  1368. } else {
  1369. ID.AddInteger(concepts::Requirement::RK_Nested);
  1370. auto *NestedReq = cast<concepts::NestedRequirement>(Req);
  1371. ID.AddBoolean(NestedReq->hasInvalidConstraint());
  1372. if (!NestedReq->hasInvalidConstraint())
  1373. Visit(NestedReq->getConstraintExpr());
  1374. }
  1375. }
  1376. }
  1377. static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
  1378. UnaryOperatorKind &UnaryOp,
  1379. BinaryOperatorKind &BinaryOp) {
  1380. switch (S->getOperator()) {
  1381. case OO_None:
  1382. case OO_New:
  1383. case OO_Delete:
  1384. case OO_Array_New:
  1385. case OO_Array_Delete:
  1386. case OO_Arrow:
  1387. case OO_Conditional:
  1388. case NUM_OVERLOADED_OPERATORS:
  1389. llvm_unreachable("Invalid operator call kind");
  1390. case OO_Plus:
  1391. if (S->getNumArgs() == 1) {
  1392. UnaryOp = UO_Plus;
  1393. return Stmt::UnaryOperatorClass;
  1394. }
  1395. BinaryOp = BO_Add;
  1396. return Stmt::BinaryOperatorClass;
  1397. case OO_Minus:
  1398. if (S->getNumArgs() == 1) {
  1399. UnaryOp = UO_Minus;
  1400. return Stmt::UnaryOperatorClass;
  1401. }
  1402. BinaryOp = BO_Sub;
  1403. return Stmt::BinaryOperatorClass;
  1404. case OO_Star:
  1405. if (S->getNumArgs() == 1) {
  1406. UnaryOp = UO_Deref;
  1407. return Stmt::UnaryOperatorClass;
  1408. }
  1409. BinaryOp = BO_Mul;
  1410. return Stmt::BinaryOperatorClass;
  1411. case OO_Slash:
  1412. BinaryOp = BO_Div;
  1413. return Stmt::BinaryOperatorClass;
  1414. case OO_Percent:
  1415. BinaryOp = BO_Rem;
  1416. return Stmt::BinaryOperatorClass;
  1417. case OO_Caret:
  1418. BinaryOp = BO_Xor;
  1419. return Stmt::BinaryOperatorClass;
  1420. case OO_Amp:
  1421. if (S->getNumArgs() == 1) {
  1422. UnaryOp = UO_AddrOf;
  1423. return Stmt::UnaryOperatorClass;
  1424. }
  1425. BinaryOp = BO_And;
  1426. return Stmt::BinaryOperatorClass;
  1427. case OO_Pipe:
  1428. BinaryOp = BO_Or;
  1429. return Stmt::BinaryOperatorClass;
  1430. case OO_Tilde:
  1431. UnaryOp = UO_Not;
  1432. return Stmt::UnaryOperatorClass;
  1433. case OO_Exclaim:
  1434. UnaryOp = UO_LNot;
  1435. return Stmt::UnaryOperatorClass;
  1436. case OO_Equal:
  1437. BinaryOp = BO_Assign;
  1438. return Stmt::BinaryOperatorClass;
  1439. case OO_Less:
  1440. BinaryOp = BO_LT;
  1441. return Stmt::BinaryOperatorClass;
  1442. case OO_Greater:
  1443. BinaryOp = BO_GT;
  1444. return Stmt::BinaryOperatorClass;
  1445. case OO_PlusEqual:
  1446. BinaryOp = BO_AddAssign;
  1447. return Stmt::CompoundAssignOperatorClass;
  1448. case OO_MinusEqual:
  1449. BinaryOp = BO_SubAssign;
  1450. return Stmt::CompoundAssignOperatorClass;
  1451. case OO_StarEqual:
  1452. BinaryOp = BO_MulAssign;
  1453. return Stmt::CompoundAssignOperatorClass;
  1454. case OO_SlashEqual:
  1455. BinaryOp = BO_DivAssign;
  1456. return Stmt::CompoundAssignOperatorClass;
  1457. case OO_PercentEqual:
  1458. BinaryOp = BO_RemAssign;
  1459. return Stmt::CompoundAssignOperatorClass;
  1460. case OO_CaretEqual:
  1461. BinaryOp = BO_XorAssign;
  1462. return Stmt::CompoundAssignOperatorClass;
  1463. case OO_AmpEqual:
  1464. BinaryOp = BO_AndAssign;
  1465. return Stmt::CompoundAssignOperatorClass;
  1466. case OO_PipeEqual:
  1467. BinaryOp = BO_OrAssign;
  1468. return Stmt::CompoundAssignOperatorClass;
  1469. case OO_LessLess:
  1470. BinaryOp = BO_Shl;
  1471. return Stmt::BinaryOperatorClass;
  1472. case OO_GreaterGreater:
  1473. BinaryOp = BO_Shr;
  1474. return Stmt::BinaryOperatorClass;
  1475. case OO_LessLessEqual:
  1476. BinaryOp = BO_ShlAssign;
  1477. return Stmt::CompoundAssignOperatorClass;
  1478. case OO_GreaterGreaterEqual:
  1479. BinaryOp = BO_ShrAssign;
  1480. return Stmt::CompoundAssignOperatorClass;
  1481. case OO_EqualEqual:
  1482. BinaryOp = BO_EQ;
  1483. return Stmt::BinaryOperatorClass;
  1484. case OO_ExclaimEqual:
  1485. BinaryOp = BO_NE;
  1486. return Stmt::BinaryOperatorClass;
  1487. case OO_LessEqual:
  1488. BinaryOp = BO_LE;
  1489. return Stmt::BinaryOperatorClass;
  1490. case OO_GreaterEqual:
  1491. BinaryOp = BO_GE;
  1492. return Stmt::BinaryOperatorClass;
  1493. case OO_Spaceship:
  1494. BinaryOp = BO_Cmp;
  1495. return Stmt::BinaryOperatorClass;
  1496. case OO_AmpAmp:
  1497. BinaryOp = BO_LAnd;
  1498. return Stmt::BinaryOperatorClass;
  1499. case OO_PipePipe:
  1500. BinaryOp = BO_LOr;
  1501. return Stmt::BinaryOperatorClass;
  1502. case OO_PlusPlus:
  1503. UnaryOp = S->getNumArgs() == 1? UO_PreInc
  1504. : UO_PostInc;
  1505. return Stmt::UnaryOperatorClass;
  1506. case OO_MinusMinus:
  1507. UnaryOp = S->getNumArgs() == 1? UO_PreDec
  1508. : UO_PostDec;
  1509. return Stmt::UnaryOperatorClass;
  1510. case OO_Comma:
  1511. BinaryOp = BO_Comma;
  1512. return Stmt::BinaryOperatorClass;
  1513. case OO_ArrowStar:
  1514. BinaryOp = BO_PtrMemI;
  1515. return Stmt::BinaryOperatorClass;
  1516. case OO_Subscript:
  1517. return Stmt::ArraySubscriptExprClass;
  1518. case OO_Call:
  1519. return Stmt::CallExprClass;
  1520. case OO_Coawait:
  1521. UnaryOp = UO_Coawait;
  1522. return Stmt::UnaryOperatorClass;
  1523. }
  1524. llvm_unreachable("Invalid overloaded operator expression");
  1525. }
  1526. #if defined(_MSC_VER) && !defined(__clang__)
  1527. #if _MSC_VER == 1911
  1528. // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
  1529. // MSVC 2017 update 3 miscompiles this function, and a clang built with it
  1530. // will crash in stage 2 of a bootstrap build.
  1531. #pragma optimize("", off)
  1532. #endif
  1533. #endif
  1534. void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
  1535. if (S->isTypeDependent()) {
  1536. // Type-dependent operator calls are profiled like their underlying
  1537. // syntactic operator.
  1538. //
  1539. // An operator call to operator-> is always implicit, so just skip it. The
  1540. // enclosing MemberExpr will profile the actual member access.
  1541. if (S->getOperator() == OO_Arrow)
  1542. return Visit(S->getArg(0));
  1543. UnaryOperatorKind UnaryOp = UO_Extension;
  1544. BinaryOperatorKind BinaryOp = BO_Comma;
  1545. Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
  1546. ID.AddInteger(SC);
  1547. for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
  1548. Visit(S->getArg(I));
  1549. if (SC == Stmt::UnaryOperatorClass)
  1550. ID.AddInteger(UnaryOp);
  1551. else if (SC == Stmt::BinaryOperatorClass ||
  1552. SC == Stmt::CompoundAssignOperatorClass)
  1553. ID.AddInteger(BinaryOp);
  1554. else
  1555. assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass);
  1556. return;
  1557. }
  1558. VisitCallExpr(S);
  1559. ID.AddInteger(S->getOperator());
  1560. }
  1561. void StmtProfiler::VisitCXXRewrittenBinaryOperator(
  1562. const CXXRewrittenBinaryOperator *S) {
  1563. // If a rewritten operator were ever to be type-dependent, we should profile
  1564. // it following its syntactic operator.
  1565. assert(!S->isTypeDependent() &&
  1566. "resolved rewritten operator should never be type-dependent");
  1567. ID.AddBoolean(S->isReversed());
  1568. VisitExpr(S->getSemanticForm());
  1569. }
  1570. #if defined(_MSC_VER) && !defined(__clang__)
  1571. #if _MSC_VER == 1911
  1572. #pragma optimize("", on)
  1573. #endif
  1574. #endif
  1575. void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
  1576. VisitCallExpr(S);
  1577. }
  1578. void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
  1579. VisitCallExpr(S);
  1580. }
  1581. void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
  1582. VisitExpr(S);
  1583. }
  1584. void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
  1585. VisitExplicitCastExpr(S);
  1586. }
  1587. void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
  1588. VisitCXXNamedCastExpr(S);
  1589. }
  1590. void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
  1591. VisitCXXNamedCastExpr(S);
  1592. }
  1593. void
  1594. StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
  1595. VisitCXXNamedCastExpr(S);
  1596. }
  1597. void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
  1598. VisitCXXNamedCastExpr(S);
  1599. }
  1600. void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
  1601. VisitExpr(S);
  1602. VisitType(S->getTypeInfoAsWritten()->getType());
  1603. }
  1604. void StmtProfiler::VisitCXXAddrspaceCastExpr(const CXXAddrspaceCastExpr *S) {
  1605. VisitCXXNamedCastExpr(S);
  1606. }
  1607. void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
  1608. VisitCallExpr(S);
  1609. }
  1610. void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
  1611. VisitExpr(S);
  1612. ID.AddBoolean(S->getValue());
  1613. }
  1614. void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
  1615. VisitExpr(S);
  1616. }
  1617. void StmtProfiler::VisitCXXStdInitializerListExpr(
  1618. const CXXStdInitializerListExpr *S) {
  1619. VisitExpr(S);
  1620. }
  1621. void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
  1622. VisitExpr(S);
  1623. if (S->isTypeOperand())
  1624. VisitType(S->getTypeOperandSourceInfo()->getType());
  1625. }
  1626. void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
  1627. VisitExpr(S);
  1628. if (S->isTypeOperand())
  1629. VisitType(S->getTypeOperandSourceInfo()->getType());
  1630. }
  1631. void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
  1632. VisitExpr(S);
  1633. VisitDecl(S->getPropertyDecl());
  1634. }
  1635. void StmtProfiler::VisitMSPropertySubscriptExpr(
  1636. const MSPropertySubscriptExpr *S) {
  1637. VisitExpr(S);
  1638. }
  1639. void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
  1640. VisitExpr(S);
  1641. ID.AddBoolean(S->isImplicit());
  1642. }
  1643. void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
  1644. VisitExpr(S);
  1645. }
  1646. void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
  1647. VisitExpr(S);
  1648. VisitDecl(S->getParam());
  1649. }
  1650. void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
  1651. VisitExpr(S);
  1652. VisitDecl(S->getField());
  1653. }
  1654. void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
  1655. VisitExpr(S);
  1656. VisitDecl(
  1657. const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
  1658. }
  1659. void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
  1660. VisitExpr(S);
  1661. VisitDecl(S->getConstructor());
  1662. ID.AddBoolean(S->isElidable());
  1663. }
  1664. void StmtProfiler::VisitCXXInheritedCtorInitExpr(
  1665. const CXXInheritedCtorInitExpr *S) {
  1666. VisitExpr(S);
  1667. VisitDecl(S->getConstructor());
  1668. }
  1669. void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
  1670. VisitExplicitCastExpr(S);
  1671. }
  1672. void
  1673. StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
  1674. VisitCXXConstructExpr(S);
  1675. }
  1676. void
  1677. StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
  1678. // Do not recursively visit the children of this expression. Profiling the
  1679. // body would result in unnecessary work, and is not safe to do during
  1680. // deserialization.
  1681. VisitStmtNoChildren(S);
  1682. // C++20 [temp.over.link]p5:
  1683. // Two lambda-expressions are never considered equivalent.
  1684. VisitDecl(S->getLambdaClass());
  1685. }
  1686. void
  1687. StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
  1688. VisitExpr(S);
  1689. }
  1690. void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
  1691. VisitExpr(S);
  1692. ID.AddBoolean(S->isGlobalDelete());
  1693. ID.AddBoolean(S->isArrayForm());
  1694. VisitDecl(S->getOperatorDelete());
  1695. }
  1696. void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
  1697. VisitExpr(S);
  1698. VisitType(S->getAllocatedType());
  1699. VisitDecl(S->getOperatorNew());
  1700. VisitDecl(S->getOperatorDelete());
  1701. ID.AddBoolean(S->isArray());
  1702. ID.AddInteger(S->getNumPlacementArgs());
  1703. ID.AddBoolean(S->isGlobalNew());
  1704. ID.AddBoolean(S->isParenTypeId());
  1705. ID.AddInteger(S->getInitializationStyle());
  1706. }
  1707. void
  1708. StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
  1709. VisitExpr(S);
  1710. ID.AddBoolean(S->isArrow());
  1711. VisitNestedNameSpecifier(S->getQualifier());
  1712. ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
  1713. if (S->getScopeTypeInfo())
  1714. VisitType(S->getScopeTypeInfo()->getType());
  1715. ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
  1716. if (S->getDestroyedTypeInfo())
  1717. VisitType(S->getDestroyedType());
  1718. else
  1719. VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
  1720. }
  1721. void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
  1722. VisitExpr(S);
  1723. VisitNestedNameSpecifier(S->getQualifier());
  1724. VisitName(S->getName(), /*TreatAsDecl*/ true);
  1725. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1726. if (S->hasExplicitTemplateArgs())
  1727. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1728. }
  1729. void
  1730. StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
  1731. VisitOverloadExpr(S);
  1732. }
  1733. void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
  1734. VisitExpr(S);
  1735. ID.AddInteger(S->getTrait());
  1736. ID.AddInteger(S->getNumArgs());
  1737. for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
  1738. VisitType(S->getArg(I)->getType());
  1739. }
  1740. void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
  1741. VisitExpr(S);
  1742. ID.AddInteger(S->getTrait());
  1743. VisitType(S->getQueriedType());
  1744. }
  1745. void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
  1746. VisitExpr(S);
  1747. ID.AddInteger(S->getTrait());
  1748. VisitExpr(S->getQueriedExpression());
  1749. }
  1750. void StmtProfiler::VisitDependentScopeDeclRefExpr(
  1751. const DependentScopeDeclRefExpr *S) {
  1752. VisitExpr(S);
  1753. VisitName(S->getDeclName());
  1754. VisitNestedNameSpecifier(S->getQualifier());
  1755. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1756. if (S->hasExplicitTemplateArgs())
  1757. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1758. }
  1759. void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
  1760. VisitExpr(S);
  1761. }
  1762. void StmtProfiler::VisitCXXUnresolvedConstructExpr(
  1763. const CXXUnresolvedConstructExpr *S) {
  1764. VisitExpr(S);
  1765. VisitType(S->getTypeAsWritten());
  1766. ID.AddInteger(S->isListInitialization());
  1767. }
  1768. void StmtProfiler::VisitCXXDependentScopeMemberExpr(
  1769. const CXXDependentScopeMemberExpr *S) {
  1770. ID.AddBoolean(S->isImplicitAccess());
  1771. if (!S->isImplicitAccess()) {
  1772. VisitExpr(S);
  1773. ID.AddBoolean(S->isArrow());
  1774. }
  1775. VisitNestedNameSpecifier(S->getQualifier());
  1776. VisitName(S->getMember());
  1777. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1778. if (S->hasExplicitTemplateArgs())
  1779. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1780. }
  1781. void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
  1782. ID.AddBoolean(S->isImplicitAccess());
  1783. if (!S->isImplicitAccess()) {
  1784. VisitExpr(S);
  1785. ID.AddBoolean(S->isArrow());
  1786. }
  1787. VisitNestedNameSpecifier(S->getQualifier());
  1788. VisitName(S->getMemberName());
  1789. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1790. if (S->hasExplicitTemplateArgs())
  1791. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1792. }
  1793. void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
  1794. VisitExpr(S);
  1795. }
  1796. void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
  1797. VisitExpr(S);
  1798. }
  1799. void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
  1800. VisitExpr(S);
  1801. VisitDecl(S->getPack());
  1802. if (S->isPartiallySubstituted()) {
  1803. auto Args = S->getPartialArguments();
  1804. ID.AddInteger(Args.size());
  1805. for (const auto &TA : Args)
  1806. VisitTemplateArgument(TA);
  1807. } else {
  1808. ID.AddInteger(0);
  1809. }
  1810. }
  1811. void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
  1812. const SubstNonTypeTemplateParmPackExpr *S) {
  1813. VisitExpr(S);
  1814. VisitDecl(S->getParameterPack());
  1815. VisitTemplateArgument(S->getArgumentPack());
  1816. }
  1817. void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
  1818. const SubstNonTypeTemplateParmExpr *E) {
  1819. // Profile exactly as the replacement expression.
  1820. Visit(E->getReplacement());
  1821. }
  1822. void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
  1823. VisitExpr(S);
  1824. VisitDecl(S->getParameterPack());
  1825. ID.AddInteger(S->getNumExpansions());
  1826. for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
  1827. VisitDecl(*I);
  1828. }
  1829. void StmtProfiler::VisitMaterializeTemporaryExpr(
  1830. const MaterializeTemporaryExpr *S) {
  1831. VisitExpr(S);
  1832. }
  1833. void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
  1834. VisitExpr(S);
  1835. ID.AddInteger(S->getOperator());
  1836. }
  1837. void StmtProfiler::VisitCXXParenListInitExpr(const CXXParenListInitExpr *S) {
  1838. VisitExpr(S);
  1839. }
  1840. void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
  1841. VisitStmt(S);
  1842. }
  1843. void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
  1844. VisitStmt(S);
  1845. }
  1846. void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
  1847. VisitExpr(S);
  1848. }
  1849. void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
  1850. VisitExpr(S);
  1851. }
  1852. void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
  1853. VisitExpr(S);
  1854. }
  1855. void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
  1856. VisitExpr(E);
  1857. }
  1858. void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
  1859. VisitExpr(E);
  1860. }
  1861. void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
  1862. VisitExpr(E);
  1863. }
  1864. void StmtProfiler::VisitRecoveryExpr(const RecoveryExpr *E) { VisitExpr(E); }
  1865. void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
  1866. VisitExpr(S);
  1867. }
  1868. void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
  1869. VisitExpr(E);
  1870. }
  1871. void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
  1872. VisitExpr(E);
  1873. }
  1874. void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
  1875. VisitExpr(E);
  1876. }
  1877. void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
  1878. VisitExpr(S);
  1879. VisitType(S->getEncodedType());
  1880. }
  1881. void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
  1882. VisitExpr(S);
  1883. VisitName(S->getSelector());
  1884. }
  1885. void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
  1886. VisitExpr(S);
  1887. VisitDecl(S->getProtocol());
  1888. }
  1889. void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
  1890. VisitExpr(S);
  1891. VisitDecl(S->getDecl());
  1892. ID.AddBoolean(S->isArrow());
  1893. ID.AddBoolean(S->isFreeIvar());
  1894. }
  1895. void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
  1896. VisitExpr(S);
  1897. if (S->isImplicitProperty()) {
  1898. VisitDecl(S->getImplicitPropertyGetter());
  1899. VisitDecl(S->getImplicitPropertySetter());
  1900. } else {
  1901. VisitDecl(S->getExplicitProperty());
  1902. }
  1903. if (S->isSuperReceiver()) {
  1904. ID.AddBoolean(S->isSuperReceiver());
  1905. VisitType(S->getSuperReceiverType());
  1906. }
  1907. }
  1908. void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
  1909. VisitExpr(S);
  1910. VisitDecl(S->getAtIndexMethodDecl());
  1911. VisitDecl(S->setAtIndexMethodDecl());
  1912. }
  1913. void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
  1914. VisitExpr(S);
  1915. VisitName(S->getSelector());
  1916. VisitDecl(S->getMethodDecl());
  1917. }
  1918. void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
  1919. VisitExpr(S);
  1920. ID.AddBoolean(S->isArrow());
  1921. }
  1922. void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
  1923. VisitExpr(S);
  1924. ID.AddBoolean(S->getValue());
  1925. }
  1926. void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
  1927. const ObjCIndirectCopyRestoreExpr *S) {
  1928. VisitExpr(S);
  1929. ID.AddBoolean(S->shouldCopy());
  1930. }
  1931. void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
  1932. VisitExplicitCastExpr(S);
  1933. ID.AddBoolean(S->getBridgeKind());
  1934. }
  1935. void StmtProfiler::VisitObjCAvailabilityCheckExpr(
  1936. const ObjCAvailabilityCheckExpr *S) {
  1937. VisitExpr(S);
  1938. }
  1939. void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
  1940. unsigned NumArgs) {
  1941. ID.AddInteger(NumArgs);
  1942. for (unsigned I = 0; I != NumArgs; ++I)
  1943. VisitTemplateArgument(Args[I].getArgument());
  1944. }
  1945. void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
  1946. // Mostly repetitive with TemplateArgument::Profile!
  1947. ID.AddInteger(Arg.getKind());
  1948. switch (Arg.getKind()) {
  1949. case TemplateArgument::Null:
  1950. break;
  1951. case TemplateArgument::Type:
  1952. VisitType(Arg.getAsType());
  1953. break;
  1954. case TemplateArgument::Template:
  1955. case TemplateArgument::TemplateExpansion:
  1956. VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
  1957. break;
  1958. case TemplateArgument::Declaration:
  1959. VisitType(Arg.getParamTypeForDecl());
  1960. // FIXME: Do we need to recursively decompose template parameter objects?
  1961. VisitDecl(Arg.getAsDecl());
  1962. break;
  1963. case TemplateArgument::NullPtr:
  1964. VisitType(Arg.getNullPtrType());
  1965. break;
  1966. case TemplateArgument::Integral:
  1967. VisitType(Arg.getIntegralType());
  1968. Arg.getAsIntegral().Profile(ID);
  1969. break;
  1970. case TemplateArgument::Expression:
  1971. Visit(Arg.getAsExpr());
  1972. break;
  1973. case TemplateArgument::Pack:
  1974. for (const auto &P : Arg.pack_elements())
  1975. VisitTemplateArgument(P);
  1976. break;
  1977. }
  1978. }
  1979. void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
  1980. bool Canonical) const {
  1981. StmtProfilerWithPointers Profiler(ID, Context, Canonical);
  1982. Profiler.Visit(this);
  1983. }
  1984. void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
  1985. class ODRHash &Hash) const {
  1986. StmtProfilerWithoutPointers Profiler(ID, Hash);
  1987. Profiler.Visit(this);
  1988. }