StmtProfile.cpp 54 KB

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