StmtProfile.cpp 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071
  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. VistOMPClauseWithPreInit(C);
  367. if (C->getCondition())
  368. Profiler->VisitStmt(C->getCondition());
  369. }
  370. void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
  371. VistOMPClauseWithPreInit(C);
  372. if (C->getNumThreads())
  373. Profiler->VisitStmt(C->getNumThreads());
  374. }
  375. void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
  376. if (C->getSafelen())
  377. Profiler->VisitStmt(C->getSafelen());
  378. }
  379. void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
  380. if (C->getSimdlen())
  381. Profiler->VisitStmt(C->getSimdlen());
  382. }
  383. void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
  384. if (C->getAllocator())
  385. Profiler->VisitStmt(C->getAllocator());
  386. }
  387. void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
  388. if (C->getNumForLoops())
  389. Profiler->VisitStmt(C->getNumForLoops());
  390. }
  391. void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
  392. void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
  393. void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
  394. const OMPUnifiedAddressClause *C) {}
  395. void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
  396. const OMPUnifiedSharedMemoryClause *C) {}
  397. void OMPClauseProfiler::VisitOMPReverseOffloadClause(
  398. const OMPReverseOffloadClause *C) {}
  399. void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
  400. const OMPDynamicAllocatorsClause *C) {}
  401. void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
  402. const OMPAtomicDefaultMemOrderClause *C) {}
  403. void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
  404. VistOMPClauseWithPreInit(C);
  405. if (auto *S = C->getChunkSize())
  406. Profiler->VisitStmt(S);
  407. }
  408. void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
  409. if (auto *Num = C->getNumForLoops())
  410. Profiler->VisitStmt(Num);
  411. }
  412. void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
  413. void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
  414. void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
  415. void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
  416. void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
  417. void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
  418. void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
  419. void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
  420. void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
  421. void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
  422. void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
  423. template<typename T>
  424. void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
  425. for (auto *E : Node->varlists()) {
  426. if (E)
  427. Profiler->VisitStmt(E);
  428. }
  429. }
  430. void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
  431. VisitOMPClauseList(C);
  432. for (auto *E : C->private_copies()) {
  433. if (E)
  434. Profiler->VisitStmt(E);
  435. }
  436. }
  437. void
  438. OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
  439. VisitOMPClauseList(C);
  440. VistOMPClauseWithPreInit(C);
  441. for (auto *E : C->private_copies()) {
  442. if (E)
  443. Profiler->VisitStmt(E);
  444. }
  445. for (auto *E : C->inits()) {
  446. if (E)
  447. Profiler->VisitStmt(E);
  448. }
  449. }
  450. void
  451. OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
  452. VisitOMPClauseList(C);
  453. VistOMPClauseWithPostUpdate(C);
  454. for (auto *E : C->source_exprs()) {
  455. if (E)
  456. Profiler->VisitStmt(E);
  457. }
  458. for (auto *E : C->destination_exprs()) {
  459. if (E)
  460. Profiler->VisitStmt(E);
  461. }
  462. for (auto *E : C->assignment_ops()) {
  463. if (E)
  464. Profiler->VisitStmt(E);
  465. }
  466. }
  467. void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
  468. VisitOMPClauseList(C);
  469. }
  470. void OMPClauseProfiler::VisitOMPReductionClause(
  471. const OMPReductionClause *C) {
  472. Profiler->VisitNestedNameSpecifier(
  473. C->getQualifierLoc().getNestedNameSpecifier());
  474. Profiler->VisitName(C->getNameInfo().getName());
  475. VisitOMPClauseList(C);
  476. VistOMPClauseWithPostUpdate(C);
  477. for (auto *E : C->privates()) {
  478. if (E)
  479. Profiler->VisitStmt(E);
  480. }
  481. for (auto *E : C->lhs_exprs()) {
  482. if (E)
  483. Profiler->VisitStmt(E);
  484. }
  485. for (auto *E : C->rhs_exprs()) {
  486. if (E)
  487. Profiler->VisitStmt(E);
  488. }
  489. for (auto *E : C->reduction_ops()) {
  490. if (E)
  491. Profiler->VisitStmt(E);
  492. }
  493. }
  494. void OMPClauseProfiler::VisitOMPTaskReductionClause(
  495. const OMPTaskReductionClause *C) {
  496. Profiler->VisitNestedNameSpecifier(
  497. C->getQualifierLoc().getNestedNameSpecifier());
  498. Profiler->VisitName(C->getNameInfo().getName());
  499. VisitOMPClauseList(C);
  500. VistOMPClauseWithPostUpdate(C);
  501. for (auto *E : C->privates()) {
  502. if (E)
  503. Profiler->VisitStmt(E);
  504. }
  505. for (auto *E : C->lhs_exprs()) {
  506. if (E)
  507. Profiler->VisitStmt(E);
  508. }
  509. for (auto *E : C->rhs_exprs()) {
  510. if (E)
  511. Profiler->VisitStmt(E);
  512. }
  513. for (auto *E : C->reduction_ops()) {
  514. if (E)
  515. Profiler->VisitStmt(E);
  516. }
  517. }
  518. void OMPClauseProfiler::VisitOMPInReductionClause(
  519. const OMPInReductionClause *C) {
  520. Profiler->VisitNestedNameSpecifier(
  521. C->getQualifierLoc().getNestedNameSpecifier());
  522. Profiler->VisitName(C->getNameInfo().getName());
  523. VisitOMPClauseList(C);
  524. VistOMPClauseWithPostUpdate(C);
  525. for (auto *E : C->privates()) {
  526. if (E)
  527. Profiler->VisitStmt(E);
  528. }
  529. for (auto *E : C->lhs_exprs()) {
  530. if (E)
  531. Profiler->VisitStmt(E);
  532. }
  533. for (auto *E : C->rhs_exprs()) {
  534. if (E)
  535. Profiler->VisitStmt(E);
  536. }
  537. for (auto *E : C->reduction_ops()) {
  538. if (E)
  539. Profiler->VisitStmt(E);
  540. }
  541. for (auto *E : C->taskgroup_descriptors()) {
  542. if (E)
  543. Profiler->VisitStmt(E);
  544. }
  545. }
  546. void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
  547. VisitOMPClauseList(C);
  548. VistOMPClauseWithPostUpdate(C);
  549. for (auto *E : C->privates()) {
  550. if (E)
  551. Profiler->VisitStmt(E);
  552. }
  553. for (auto *E : C->inits()) {
  554. if (E)
  555. Profiler->VisitStmt(E);
  556. }
  557. for (auto *E : C->updates()) {
  558. if (E)
  559. Profiler->VisitStmt(E);
  560. }
  561. for (auto *E : C->finals()) {
  562. if (E)
  563. Profiler->VisitStmt(E);
  564. }
  565. if (C->getStep())
  566. Profiler->VisitStmt(C->getStep());
  567. if (C->getCalcStep())
  568. Profiler->VisitStmt(C->getCalcStep());
  569. }
  570. void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
  571. VisitOMPClauseList(C);
  572. if (C->getAlignment())
  573. Profiler->VisitStmt(C->getAlignment());
  574. }
  575. void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
  576. VisitOMPClauseList(C);
  577. for (auto *E : C->source_exprs()) {
  578. if (E)
  579. Profiler->VisitStmt(E);
  580. }
  581. for (auto *E : C->destination_exprs()) {
  582. if (E)
  583. Profiler->VisitStmt(E);
  584. }
  585. for (auto *E : C->assignment_ops()) {
  586. if (E)
  587. Profiler->VisitStmt(E);
  588. }
  589. }
  590. void
  591. OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
  592. VisitOMPClauseList(C);
  593. for (auto *E : C->source_exprs()) {
  594. if (E)
  595. Profiler->VisitStmt(E);
  596. }
  597. for (auto *E : C->destination_exprs()) {
  598. if (E)
  599. Profiler->VisitStmt(E);
  600. }
  601. for (auto *E : C->assignment_ops()) {
  602. if (E)
  603. Profiler->VisitStmt(E);
  604. }
  605. }
  606. void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
  607. VisitOMPClauseList(C);
  608. }
  609. void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
  610. VisitOMPClauseList(C);
  611. }
  612. void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
  613. if (C->getDevice())
  614. Profiler->VisitStmt(C->getDevice());
  615. }
  616. void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
  617. VisitOMPClauseList(C);
  618. }
  619. void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
  620. if (Expr *Allocator = C->getAllocator())
  621. Profiler->VisitStmt(Allocator);
  622. VisitOMPClauseList(C);
  623. }
  624. void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
  625. VistOMPClauseWithPreInit(C);
  626. if (C->getNumTeams())
  627. Profiler->VisitStmt(C->getNumTeams());
  628. }
  629. void OMPClauseProfiler::VisitOMPThreadLimitClause(
  630. const OMPThreadLimitClause *C) {
  631. VistOMPClauseWithPreInit(C);
  632. if (C->getThreadLimit())
  633. Profiler->VisitStmt(C->getThreadLimit());
  634. }
  635. void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
  636. VistOMPClauseWithPreInit(C);
  637. if (C->getPriority())
  638. Profiler->VisitStmt(C->getPriority());
  639. }
  640. void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
  641. VistOMPClauseWithPreInit(C);
  642. if (C->getGrainsize())
  643. Profiler->VisitStmt(C->getGrainsize());
  644. }
  645. void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
  646. VistOMPClauseWithPreInit(C);
  647. if (C->getNumTasks())
  648. Profiler->VisitStmt(C->getNumTasks());
  649. }
  650. void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
  651. if (C->getHint())
  652. Profiler->VisitStmt(C->getHint());
  653. }
  654. void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
  655. VisitOMPClauseList(C);
  656. }
  657. void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
  658. VisitOMPClauseList(C);
  659. }
  660. void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
  661. const OMPUseDevicePtrClause *C) {
  662. VisitOMPClauseList(C);
  663. }
  664. void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
  665. const OMPIsDevicePtrClause *C) {
  666. VisitOMPClauseList(C);
  667. }
  668. }
  669. void
  670. StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
  671. VisitStmt(S);
  672. OMPClauseProfiler P(this);
  673. ArrayRef<OMPClause *> Clauses = S->clauses();
  674. for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
  675. I != E; ++I)
  676. if (*I)
  677. P.Visit(*I);
  678. }
  679. void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
  680. VisitOMPExecutableDirective(S);
  681. }
  682. void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
  683. VisitOMPExecutableDirective(S);
  684. }
  685. void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
  686. VisitOMPLoopDirective(S);
  687. }
  688. void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
  689. VisitOMPLoopDirective(S);
  690. }
  691. void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
  692. VisitOMPLoopDirective(S);
  693. }
  694. void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
  695. VisitOMPExecutableDirective(S);
  696. }
  697. void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
  698. VisitOMPExecutableDirective(S);
  699. }
  700. void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
  701. VisitOMPExecutableDirective(S);
  702. }
  703. void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
  704. VisitOMPExecutableDirective(S);
  705. }
  706. void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
  707. VisitOMPExecutableDirective(S);
  708. VisitName(S->getDirectiveName().getName());
  709. }
  710. void
  711. StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
  712. VisitOMPLoopDirective(S);
  713. }
  714. void StmtProfiler::VisitOMPParallelForSimdDirective(
  715. const OMPParallelForSimdDirective *S) {
  716. VisitOMPLoopDirective(S);
  717. }
  718. void StmtProfiler::VisitOMPParallelSectionsDirective(
  719. const OMPParallelSectionsDirective *S) {
  720. VisitOMPExecutableDirective(S);
  721. }
  722. void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
  723. VisitOMPExecutableDirective(S);
  724. }
  725. void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
  726. VisitOMPExecutableDirective(S);
  727. }
  728. void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
  729. VisitOMPExecutableDirective(S);
  730. }
  731. void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
  732. VisitOMPExecutableDirective(S);
  733. }
  734. void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
  735. VisitOMPExecutableDirective(S);
  736. if (const Expr *E = S->getReductionRef())
  737. VisitStmt(E);
  738. }
  739. void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
  740. VisitOMPExecutableDirective(S);
  741. }
  742. void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
  743. VisitOMPExecutableDirective(S);
  744. }
  745. void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
  746. VisitOMPExecutableDirective(S);
  747. }
  748. void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
  749. VisitOMPExecutableDirective(S);
  750. }
  751. void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
  752. VisitOMPExecutableDirective(S);
  753. }
  754. void StmtProfiler::VisitOMPTargetEnterDataDirective(
  755. const OMPTargetEnterDataDirective *S) {
  756. VisitOMPExecutableDirective(S);
  757. }
  758. void StmtProfiler::VisitOMPTargetExitDataDirective(
  759. const OMPTargetExitDataDirective *S) {
  760. VisitOMPExecutableDirective(S);
  761. }
  762. void StmtProfiler::VisitOMPTargetParallelDirective(
  763. const OMPTargetParallelDirective *S) {
  764. VisitOMPExecutableDirective(S);
  765. }
  766. void StmtProfiler::VisitOMPTargetParallelForDirective(
  767. const OMPTargetParallelForDirective *S) {
  768. VisitOMPExecutableDirective(S);
  769. }
  770. void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
  771. VisitOMPExecutableDirective(S);
  772. }
  773. void StmtProfiler::VisitOMPCancellationPointDirective(
  774. const OMPCancellationPointDirective *S) {
  775. VisitOMPExecutableDirective(S);
  776. }
  777. void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
  778. VisitOMPExecutableDirective(S);
  779. }
  780. void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
  781. VisitOMPLoopDirective(S);
  782. }
  783. void StmtProfiler::VisitOMPTaskLoopSimdDirective(
  784. const OMPTaskLoopSimdDirective *S) {
  785. VisitOMPLoopDirective(S);
  786. }
  787. void StmtProfiler::VisitOMPMasterTaskLoopDirective(
  788. const OMPMasterTaskLoopDirective *S) {
  789. VisitOMPLoopDirective(S);
  790. }
  791. void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
  792. const OMPMasterTaskLoopSimdDirective *S) {
  793. VisitOMPLoopDirective(S);
  794. }
  795. void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
  796. const OMPParallelMasterTaskLoopDirective *S) {
  797. VisitOMPLoopDirective(S);
  798. }
  799. void StmtProfiler::VisitOMPDistributeDirective(
  800. const OMPDistributeDirective *S) {
  801. VisitOMPLoopDirective(S);
  802. }
  803. void OMPClauseProfiler::VisitOMPDistScheduleClause(
  804. const OMPDistScheduleClause *C) {
  805. VistOMPClauseWithPreInit(C);
  806. if (auto *S = C->getChunkSize())
  807. Profiler->VisitStmt(S);
  808. }
  809. void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
  810. void StmtProfiler::VisitOMPTargetUpdateDirective(
  811. const OMPTargetUpdateDirective *S) {
  812. VisitOMPExecutableDirective(S);
  813. }
  814. void StmtProfiler::VisitOMPDistributeParallelForDirective(
  815. const OMPDistributeParallelForDirective *S) {
  816. VisitOMPLoopDirective(S);
  817. }
  818. void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
  819. const OMPDistributeParallelForSimdDirective *S) {
  820. VisitOMPLoopDirective(S);
  821. }
  822. void StmtProfiler::VisitOMPDistributeSimdDirective(
  823. const OMPDistributeSimdDirective *S) {
  824. VisitOMPLoopDirective(S);
  825. }
  826. void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
  827. const OMPTargetParallelForSimdDirective *S) {
  828. VisitOMPLoopDirective(S);
  829. }
  830. void StmtProfiler::VisitOMPTargetSimdDirective(
  831. const OMPTargetSimdDirective *S) {
  832. VisitOMPLoopDirective(S);
  833. }
  834. void StmtProfiler::VisitOMPTeamsDistributeDirective(
  835. const OMPTeamsDistributeDirective *S) {
  836. VisitOMPLoopDirective(S);
  837. }
  838. void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
  839. const OMPTeamsDistributeSimdDirective *S) {
  840. VisitOMPLoopDirective(S);
  841. }
  842. void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
  843. const OMPTeamsDistributeParallelForSimdDirective *S) {
  844. VisitOMPLoopDirective(S);
  845. }
  846. void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
  847. const OMPTeamsDistributeParallelForDirective *S) {
  848. VisitOMPLoopDirective(S);
  849. }
  850. void StmtProfiler::VisitOMPTargetTeamsDirective(
  851. const OMPTargetTeamsDirective *S) {
  852. VisitOMPExecutableDirective(S);
  853. }
  854. void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
  855. const OMPTargetTeamsDistributeDirective *S) {
  856. VisitOMPLoopDirective(S);
  857. }
  858. void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
  859. const OMPTargetTeamsDistributeParallelForDirective *S) {
  860. VisitOMPLoopDirective(S);
  861. }
  862. void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
  863. const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
  864. VisitOMPLoopDirective(S);
  865. }
  866. void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
  867. const OMPTargetTeamsDistributeSimdDirective *S) {
  868. VisitOMPLoopDirective(S);
  869. }
  870. void StmtProfiler::VisitExpr(const Expr *S) {
  871. VisitStmt(S);
  872. }
  873. void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
  874. VisitExpr(S);
  875. }
  876. void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
  877. VisitExpr(S);
  878. if (!Canonical)
  879. VisitNestedNameSpecifier(S->getQualifier());
  880. VisitDecl(S->getDecl());
  881. if (!Canonical) {
  882. ID.AddBoolean(S->hasExplicitTemplateArgs());
  883. if (S->hasExplicitTemplateArgs())
  884. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  885. }
  886. }
  887. void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
  888. VisitExpr(S);
  889. ID.AddInteger(S->getIdentKind());
  890. }
  891. void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
  892. VisitExpr(S);
  893. S->getValue().Profile(ID);
  894. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  895. }
  896. void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
  897. VisitExpr(S);
  898. S->getValue().Profile(ID);
  899. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  900. }
  901. void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
  902. VisitExpr(S);
  903. ID.AddInteger(S->getKind());
  904. ID.AddInteger(S->getValue());
  905. }
  906. void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
  907. VisitExpr(S);
  908. S->getValue().Profile(ID);
  909. ID.AddBoolean(S->isExact());
  910. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  911. }
  912. void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
  913. VisitExpr(S);
  914. }
  915. void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
  916. VisitExpr(S);
  917. ID.AddString(S->getBytes());
  918. ID.AddInteger(S->getKind());
  919. }
  920. void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
  921. VisitExpr(S);
  922. }
  923. void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
  924. VisitExpr(S);
  925. }
  926. void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
  927. VisitExpr(S);
  928. ID.AddInteger(S->getOpcode());
  929. }
  930. void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
  931. VisitType(S->getTypeSourceInfo()->getType());
  932. unsigned n = S->getNumComponents();
  933. for (unsigned i = 0; i < n; ++i) {
  934. const OffsetOfNode &ON = S->getComponent(i);
  935. ID.AddInteger(ON.getKind());
  936. switch (ON.getKind()) {
  937. case OffsetOfNode::Array:
  938. // Expressions handled below.
  939. break;
  940. case OffsetOfNode::Field:
  941. VisitDecl(ON.getField());
  942. break;
  943. case OffsetOfNode::Identifier:
  944. VisitIdentifierInfo(ON.getFieldName());
  945. break;
  946. case OffsetOfNode::Base:
  947. // These nodes are implicit, and therefore don't need profiling.
  948. break;
  949. }
  950. }
  951. VisitExpr(S);
  952. }
  953. void
  954. StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
  955. VisitExpr(S);
  956. ID.AddInteger(S->getKind());
  957. if (S->isArgumentType())
  958. VisitType(S->getArgumentType());
  959. }
  960. void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
  961. VisitExpr(S);
  962. }
  963. void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
  964. VisitExpr(S);
  965. }
  966. void StmtProfiler::VisitCallExpr(const CallExpr *S) {
  967. VisitExpr(S);
  968. }
  969. void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
  970. VisitExpr(S);
  971. VisitDecl(S->getMemberDecl());
  972. if (!Canonical)
  973. VisitNestedNameSpecifier(S->getQualifier());
  974. ID.AddBoolean(S->isArrow());
  975. }
  976. void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
  977. VisitExpr(S);
  978. ID.AddBoolean(S->isFileScope());
  979. }
  980. void StmtProfiler::VisitCastExpr(const CastExpr *S) {
  981. VisitExpr(S);
  982. }
  983. void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
  984. VisitCastExpr(S);
  985. ID.AddInteger(S->getValueKind());
  986. }
  987. void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
  988. VisitCastExpr(S);
  989. VisitType(S->getTypeAsWritten());
  990. }
  991. void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
  992. VisitExplicitCastExpr(S);
  993. }
  994. void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
  995. VisitExpr(S);
  996. ID.AddInteger(S->getOpcode());
  997. }
  998. void
  999. StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
  1000. VisitBinaryOperator(S);
  1001. }
  1002. void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
  1003. VisitExpr(S);
  1004. }
  1005. void StmtProfiler::VisitBinaryConditionalOperator(
  1006. const BinaryConditionalOperator *S) {
  1007. VisitExpr(S);
  1008. }
  1009. void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
  1010. VisitExpr(S);
  1011. VisitDecl(S->getLabel());
  1012. }
  1013. void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
  1014. VisitExpr(S);
  1015. }
  1016. void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
  1017. VisitExpr(S);
  1018. }
  1019. void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
  1020. VisitExpr(S);
  1021. }
  1022. void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
  1023. VisitExpr(S);
  1024. }
  1025. void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
  1026. VisitExpr(S);
  1027. }
  1028. void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
  1029. VisitExpr(S);
  1030. }
  1031. void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
  1032. if (S->getSyntacticForm()) {
  1033. VisitInitListExpr(S->getSyntacticForm());
  1034. return;
  1035. }
  1036. VisitExpr(S);
  1037. }
  1038. void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
  1039. VisitExpr(S);
  1040. ID.AddBoolean(S->usesGNUSyntax());
  1041. for (const DesignatedInitExpr::Designator &D : S->designators()) {
  1042. if (D.isFieldDesignator()) {
  1043. ID.AddInteger(0);
  1044. VisitName(D.getFieldName());
  1045. continue;
  1046. }
  1047. if (D.isArrayDesignator()) {
  1048. ID.AddInteger(1);
  1049. } else {
  1050. assert(D.isArrayRangeDesignator());
  1051. ID.AddInteger(2);
  1052. }
  1053. ID.AddInteger(D.getFirstExprIndex());
  1054. }
  1055. }
  1056. // Seems that if VisitInitListExpr() only works on the syntactic form of an
  1057. // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
  1058. void StmtProfiler::VisitDesignatedInitUpdateExpr(
  1059. const DesignatedInitUpdateExpr *S) {
  1060. llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
  1061. "initializer");
  1062. }
  1063. void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
  1064. VisitExpr(S);
  1065. }
  1066. void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
  1067. VisitExpr(S);
  1068. }
  1069. void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
  1070. llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
  1071. }
  1072. void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
  1073. VisitExpr(S);
  1074. }
  1075. void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
  1076. VisitExpr(S);
  1077. VisitName(&S->getAccessor());
  1078. }
  1079. void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
  1080. VisitExpr(S);
  1081. VisitDecl(S->getBlockDecl());
  1082. }
  1083. void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
  1084. VisitExpr(S);
  1085. for (const GenericSelectionExpr::ConstAssociation &Assoc :
  1086. S->associations()) {
  1087. QualType T = Assoc.getType();
  1088. if (T.isNull())
  1089. ID.AddPointer(nullptr);
  1090. else
  1091. VisitType(T);
  1092. VisitExpr(Assoc.getAssociationExpr());
  1093. }
  1094. }
  1095. void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
  1096. VisitExpr(S);
  1097. for (PseudoObjectExpr::const_semantics_iterator
  1098. i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
  1099. // Normally, we would not profile the source expressions of OVEs.
  1100. if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
  1101. Visit(OVE->getSourceExpr());
  1102. }
  1103. void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
  1104. VisitExpr(S);
  1105. ID.AddInteger(S->getOp());
  1106. }
  1107. void StmtProfiler::VisitConceptSpecializationExpr(
  1108. const ConceptSpecializationExpr *S) {
  1109. VisitExpr(S);
  1110. VisitDecl(S->getFoundDecl());
  1111. VisitTemplateArguments(S->getTemplateArgsAsWritten()->getTemplateArgs(),
  1112. S->getTemplateArgsAsWritten()->NumTemplateArgs);
  1113. }
  1114. static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
  1115. UnaryOperatorKind &UnaryOp,
  1116. BinaryOperatorKind &BinaryOp) {
  1117. switch (S->getOperator()) {
  1118. case OO_None:
  1119. case OO_New:
  1120. case OO_Delete:
  1121. case OO_Array_New:
  1122. case OO_Array_Delete:
  1123. case OO_Arrow:
  1124. case OO_Call:
  1125. case OO_Conditional:
  1126. case NUM_OVERLOADED_OPERATORS:
  1127. llvm_unreachable("Invalid operator call kind");
  1128. case OO_Plus:
  1129. if (S->getNumArgs() == 1) {
  1130. UnaryOp = UO_Plus;
  1131. return Stmt::UnaryOperatorClass;
  1132. }
  1133. BinaryOp = BO_Add;
  1134. return Stmt::BinaryOperatorClass;
  1135. case OO_Minus:
  1136. if (S->getNumArgs() == 1) {
  1137. UnaryOp = UO_Minus;
  1138. return Stmt::UnaryOperatorClass;
  1139. }
  1140. BinaryOp = BO_Sub;
  1141. return Stmt::BinaryOperatorClass;
  1142. case OO_Star:
  1143. if (S->getNumArgs() == 1) {
  1144. UnaryOp = UO_Deref;
  1145. return Stmt::UnaryOperatorClass;
  1146. }
  1147. BinaryOp = BO_Mul;
  1148. return Stmt::BinaryOperatorClass;
  1149. case OO_Slash:
  1150. BinaryOp = BO_Div;
  1151. return Stmt::BinaryOperatorClass;
  1152. case OO_Percent:
  1153. BinaryOp = BO_Rem;
  1154. return Stmt::BinaryOperatorClass;
  1155. case OO_Caret:
  1156. BinaryOp = BO_Xor;
  1157. return Stmt::BinaryOperatorClass;
  1158. case OO_Amp:
  1159. if (S->getNumArgs() == 1) {
  1160. UnaryOp = UO_AddrOf;
  1161. return Stmt::UnaryOperatorClass;
  1162. }
  1163. BinaryOp = BO_And;
  1164. return Stmt::BinaryOperatorClass;
  1165. case OO_Pipe:
  1166. BinaryOp = BO_Or;
  1167. return Stmt::BinaryOperatorClass;
  1168. case OO_Tilde:
  1169. UnaryOp = UO_Not;
  1170. return Stmt::UnaryOperatorClass;
  1171. case OO_Exclaim:
  1172. UnaryOp = UO_LNot;
  1173. return Stmt::UnaryOperatorClass;
  1174. case OO_Equal:
  1175. BinaryOp = BO_Assign;
  1176. return Stmt::BinaryOperatorClass;
  1177. case OO_Less:
  1178. BinaryOp = BO_LT;
  1179. return Stmt::BinaryOperatorClass;
  1180. case OO_Greater:
  1181. BinaryOp = BO_GT;
  1182. return Stmt::BinaryOperatorClass;
  1183. case OO_PlusEqual:
  1184. BinaryOp = BO_AddAssign;
  1185. return Stmt::CompoundAssignOperatorClass;
  1186. case OO_MinusEqual:
  1187. BinaryOp = BO_SubAssign;
  1188. return Stmt::CompoundAssignOperatorClass;
  1189. case OO_StarEqual:
  1190. BinaryOp = BO_MulAssign;
  1191. return Stmt::CompoundAssignOperatorClass;
  1192. case OO_SlashEqual:
  1193. BinaryOp = BO_DivAssign;
  1194. return Stmt::CompoundAssignOperatorClass;
  1195. case OO_PercentEqual:
  1196. BinaryOp = BO_RemAssign;
  1197. return Stmt::CompoundAssignOperatorClass;
  1198. case OO_CaretEqual:
  1199. BinaryOp = BO_XorAssign;
  1200. return Stmt::CompoundAssignOperatorClass;
  1201. case OO_AmpEqual:
  1202. BinaryOp = BO_AndAssign;
  1203. return Stmt::CompoundAssignOperatorClass;
  1204. case OO_PipeEqual:
  1205. BinaryOp = BO_OrAssign;
  1206. return Stmt::CompoundAssignOperatorClass;
  1207. case OO_LessLess:
  1208. BinaryOp = BO_Shl;
  1209. return Stmt::BinaryOperatorClass;
  1210. case OO_GreaterGreater:
  1211. BinaryOp = BO_Shr;
  1212. return Stmt::BinaryOperatorClass;
  1213. case OO_LessLessEqual:
  1214. BinaryOp = BO_ShlAssign;
  1215. return Stmt::CompoundAssignOperatorClass;
  1216. case OO_GreaterGreaterEqual:
  1217. BinaryOp = BO_ShrAssign;
  1218. return Stmt::CompoundAssignOperatorClass;
  1219. case OO_EqualEqual:
  1220. BinaryOp = BO_EQ;
  1221. return Stmt::BinaryOperatorClass;
  1222. case OO_ExclaimEqual:
  1223. BinaryOp = BO_NE;
  1224. return Stmt::BinaryOperatorClass;
  1225. case OO_LessEqual:
  1226. BinaryOp = BO_LE;
  1227. return Stmt::BinaryOperatorClass;
  1228. case OO_GreaterEqual:
  1229. BinaryOp = BO_GE;
  1230. return Stmt::BinaryOperatorClass;
  1231. case OO_Spaceship:
  1232. // FIXME: Update this once we support <=> expressions.
  1233. llvm_unreachable("<=> expressions not supported yet");
  1234. case OO_AmpAmp:
  1235. BinaryOp = BO_LAnd;
  1236. return Stmt::BinaryOperatorClass;
  1237. case OO_PipePipe:
  1238. BinaryOp = BO_LOr;
  1239. return Stmt::BinaryOperatorClass;
  1240. case OO_PlusPlus:
  1241. UnaryOp = S->getNumArgs() == 1? UO_PreInc
  1242. : UO_PostInc;
  1243. return Stmt::UnaryOperatorClass;
  1244. case OO_MinusMinus:
  1245. UnaryOp = S->getNumArgs() == 1? UO_PreDec
  1246. : UO_PostDec;
  1247. return Stmt::UnaryOperatorClass;
  1248. case OO_Comma:
  1249. BinaryOp = BO_Comma;
  1250. return Stmt::BinaryOperatorClass;
  1251. case OO_ArrowStar:
  1252. BinaryOp = BO_PtrMemI;
  1253. return Stmt::BinaryOperatorClass;
  1254. case OO_Subscript:
  1255. return Stmt::ArraySubscriptExprClass;
  1256. case OO_Coawait:
  1257. UnaryOp = UO_Coawait;
  1258. return Stmt::UnaryOperatorClass;
  1259. }
  1260. llvm_unreachable("Invalid overloaded operator expression");
  1261. }
  1262. #if defined(_MSC_VER) && !defined(__clang__)
  1263. #if _MSC_VER == 1911
  1264. // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
  1265. // MSVC 2017 update 3 miscompiles this function, and a clang built with it
  1266. // will crash in stage 2 of a bootstrap build.
  1267. #pragma optimize("", off)
  1268. #endif
  1269. #endif
  1270. void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
  1271. if (S->isTypeDependent()) {
  1272. // Type-dependent operator calls are profiled like their underlying
  1273. // syntactic operator.
  1274. //
  1275. // An operator call to operator-> is always implicit, so just skip it. The
  1276. // enclosing MemberExpr will profile the actual member access.
  1277. if (S->getOperator() == OO_Arrow)
  1278. return Visit(S->getArg(0));
  1279. UnaryOperatorKind UnaryOp = UO_Extension;
  1280. BinaryOperatorKind BinaryOp = BO_Comma;
  1281. Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
  1282. ID.AddInteger(SC);
  1283. for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
  1284. Visit(S->getArg(I));
  1285. if (SC == Stmt::UnaryOperatorClass)
  1286. ID.AddInteger(UnaryOp);
  1287. else if (SC == Stmt::BinaryOperatorClass ||
  1288. SC == Stmt::CompoundAssignOperatorClass)
  1289. ID.AddInteger(BinaryOp);
  1290. else
  1291. assert(SC == Stmt::ArraySubscriptExprClass);
  1292. return;
  1293. }
  1294. VisitCallExpr(S);
  1295. ID.AddInteger(S->getOperator());
  1296. }
  1297. #if defined(_MSC_VER) && !defined(__clang__)
  1298. #if _MSC_VER == 1911
  1299. #pragma optimize("", on)
  1300. #endif
  1301. #endif
  1302. void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
  1303. VisitCallExpr(S);
  1304. }
  1305. void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
  1306. VisitCallExpr(S);
  1307. }
  1308. void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
  1309. VisitExpr(S);
  1310. }
  1311. void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
  1312. VisitExplicitCastExpr(S);
  1313. }
  1314. void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
  1315. VisitCXXNamedCastExpr(S);
  1316. }
  1317. void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
  1318. VisitCXXNamedCastExpr(S);
  1319. }
  1320. void
  1321. StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
  1322. VisitCXXNamedCastExpr(S);
  1323. }
  1324. void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
  1325. VisitCXXNamedCastExpr(S);
  1326. }
  1327. void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
  1328. VisitExpr(S);
  1329. VisitType(S->getTypeInfoAsWritten()->getType());
  1330. }
  1331. void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
  1332. VisitCallExpr(S);
  1333. }
  1334. void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
  1335. VisitExpr(S);
  1336. ID.AddBoolean(S->getValue());
  1337. }
  1338. void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
  1339. VisitExpr(S);
  1340. }
  1341. void StmtProfiler::VisitCXXStdInitializerListExpr(
  1342. const CXXStdInitializerListExpr *S) {
  1343. VisitExpr(S);
  1344. }
  1345. void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
  1346. VisitExpr(S);
  1347. if (S->isTypeOperand())
  1348. VisitType(S->getTypeOperandSourceInfo()->getType());
  1349. }
  1350. void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
  1351. VisitExpr(S);
  1352. if (S->isTypeOperand())
  1353. VisitType(S->getTypeOperandSourceInfo()->getType());
  1354. }
  1355. void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
  1356. VisitExpr(S);
  1357. VisitDecl(S->getPropertyDecl());
  1358. }
  1359. void StmtProfiler::VisitMSPropertySubscriptExpr(
  1360. const MSPropertySubscriptExpr *S) {
  1361. VisitExpr(S);
  1362. }
  1363. void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
  1364. VisitExpr(S);
  1365. ID.AddBoolean(S->isImplicit());
  1366. }
  1367. void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
  1368. VisitExpr(S);
  1369. }
  1370. void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
  1371. VisitExpr(S);
  1372. VisitDecl(S->getParam());
  1373. }
  1374. void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
  1375. VisitExpr(S);
  1376. VisitDecl(S->getField());
  1377. }
  1378. void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
  1379. VisitExpr(S);
  1380. VisitDecl(
  1381. const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
  1382. }
  1383. void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
  1384. VisitExpr(S);
  1385. VisitDecl(S->getConstructor());
  1386. ID.AddBoolean(S->isElidable());
  1387. }
  1388. void StmtProfiler::VisitCXXInheritedCtorInitExpr(
  1389. const CXXInheritedCtorInitExpr *S) {
  1390. VisitExpr(S);
  1391. VisitDecl(S->getConstructor());
  1392. }
  1393. void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
  1394. VisitExplicitCastExpr(S);
  1395. }
  1396. void
  1397. StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
  1398. VisitCXXConstructExpr(S);
  1399. }
  1400. void
  1401. StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
  1402. VisitExpr(S);
  1403. for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
  1404. CEnd = S->explicit_capture_end();
  1405. C != CEnd; ++C) {
  1406. if (C->capturesVLAType())
  1407. continue;
  1408. ID.AddInteger(C->getCaptureKind());
  1409. switch (C->getCaptureKind()) {
  1410. case LCK_StarThis:
  1411. case LCK_This:
  1412. break;
  1413. case LCK_ByRef:
  1414. case LCK_ByCopy:
  1415. VisitDecl(C->getCapturedVar());
  1416. ID.AddBoolean(C->isPackExpansion());
  1417. break;
  1418. case LCK_VLAType:
  1419. llvm_unreachable("VLA type in explicit captures.");
  1420. }
  1421. }
  1422. // Note: If we actually needed to be able to match lambda
  1423. // expressions, we would have to consider parameters and return type
  1424. // here, among other things.
  1425. VisitStmt(S->getBody());
  1426. }
  1427. void
  1428. StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
  1429. VisitExpr(S);
  1430. }
  1431. void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
  1432. VisitExpr(S);
  1433. ID.AddBoolean(S->isGlobalDelete());
  1434. ID.AddBoolean(S->isArrayForm());
  1435. VisitDecl(S->getOperatorDelete());
  1436. }
  1437. void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
  1438. VisitExpr(S);
  1439. VisitType(S->getAllocatedType());
  1440. VisitDecl(S->getOperatorNew());
  1441. VisitDecl(S->getOperatorDelete());
  1442. ID.AddBoolean(S->isArray());
  1443. ID.AddInteger(S->getNumPlacementArgs());
  1444. ID.AddBoolean(S->isGlobalNew());
  1445. ID.AddBoolean(S->isParenTypeId());
  1446. ID.AddInteger(S->getInitializationStyle());
  1447. }
  1448. void
  1449. StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
  1450. VisitExpr(S);
  1451. ID.AddBoolean(S->isArrow());
  1452. VisitNestedNameSpecifier(S->getQualifier());
  1453. ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
  1454. if (S->getScopeTypeInfo())
  1455. VisitType(S->getScopeTypeInfo()->getType());
  1456. ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
  1457. if (S->getDestroyedTypeInfo())
  1458. VisitType(S->getDestroyedType());
  1459. else
  1460. VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
  1461. }
  1462. void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
  1463. VisitExpr(S);
  1464. VisitNestedNameSpecifier(S->getQualifier());
  1465. VisitName(S->getName(), /*TreatAsDecl*/ true);
  1466. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1467. if (S->hasExplicitTemplateArgs())
  1468. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1469. }
  1470. void
  1471. StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
  1472. VisitOverloadExpr(S);
  1473. }
  1474. void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
  1475. VisitExpr(S);
  1476. ID.AddInteger(S->getTrait());
  1477. ID.AddInteger(S->getNumArgs());
  1478. for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
  1479. VisitType(S->getArg(I)->getType());
  1480. }
  1481. void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
  1482. VisitExpr(S);
  1483. ID.AddInteger(S->getTrait());
  1484. VisitType(S->getQueriedType());
  1485. }
  1486. void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
  1487. VisitExpr(S);
  1488. ID.AddInteger(S->getTrait());
  1489. VisitExpr(S->getQueriedExpression());
  1490. }
  1491. void StmtProfiler::VisitDependentScopeDeclRefExpr(
  1492. const DependentScopeDeclRefExpr *S) {
  1493. VisitExpr(S);
  1494. VisitName(S->getDeclName());
  1495. VisitNestedNameSpecifier(S->getQualifier());
  1496. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1497. if (S->hasExplicitTemplateArgs())
  1498. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1499. }
  1500. void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
  1501. VisitExpr(S);
  1502. }
  1503. void StmtProfiler::VisitCXXUnresolvedConstructExpr(
  1504. const CXXUnresolvedConstructExpr *S) {
  1505. VisitExpr(S);
  1506. VisitType(S->getTypeAsWritten());
  1507. ID.AddInteger(S->isListInitialization());
  1508. }
  1509. void StmtProfiler::VisitCXXDependentScopeMemberExpr(
  1510. const CXXDependentScopeMemberExpr *S) {
  1511. ID.AddBoolean(S->isImplicitAccess());
  1512. if (!S->isImplicitAccess()) {
  1513. VisitExpr(S);
  1514. ID.AddBoolean(S->isArrow());
  1515. }
  1516. VisitNestedNameSpecifier(S->getQualifier());
  1517. VisitName(S->getMember());
  1518. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1519. if (S->hasExplicitTemplateArgs())
  1520. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1521. }
  1522. void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
  1523. ID.AddBoolean(S->isImplicitAccess());
  1524. if (!S->isImplicitAccess()) {
  1525. VisitExpr(S);
  1526. ID.AddBoolean(S->isArrow());
  1527. }
  1528. VisitNestedNameSpecifier(S->getQualifier());
  1529. VisitName(S->getMemberName());
  1530. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1531. if (S->hasExplicitTemplateArgs())
  1532. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1533. }
  1534. void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
  1535. VisitExpr(S);
  1536. }
  1537. void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
  1538. VisitExpr(S);
  1539. }
  1540. void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
  1541. VisitExpr(S);
  1542. VisitDecl(S->getPack());
  1543. if (S->isPartiallySubstituted()) {
  1544. auto Args = S->getPartialArguments();
  1545. ID.AddInteger(Args.size());
  1546. for (const auto &TA : Args)
  1547. VisitTemplateArgument(TA);
  1548. } else {
  1549. ID.AddInteger(0);
  1550. }
  1551. }
  1552. void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
  1553. const SubstNonTypeTemplateParmPackExpr *S) {
  1554. VisitExpr(S);
  1555. VisitDecl(S->getParameterPack());
  1556. VisitTemplateArgument(S->getArgumentPack());
  1557. }
  1558. void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
  1559. const SubstNonTypeTemplateParmExpr *E) {
  1560. // Profile exactly as the replacement expression.
  1561. Visit(E->getReplacement());
  1562. }
  1563. void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
  1564. VisitExpr(S);
  1565. VisitDecl(S->getParameterPack());
  1566. ID.AddInteger(S->getNumExpansions());
  1567. for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
  1568. VisitDecl(*I);
  1569. }
  1570. void StmtProfiler::VisitMaterializeTemporaryExpr(
  1571. const MaterializeTemporaryExpr *S) {
  1572. VisitExpr(S);
  1573. }
  1574. void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
  1575. VisitExpr(S);
  1576. ID.AddInteger(S->getOperator());
  1577. }
  1578. void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
  1579. VisitStmt(S);
  1580. }
  1581. void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
  1582. VisitStmt(S);
  1583. }
  1584. void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
  1585. VisitExpr(S);
  1586. }
  1587. void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
  1588. VisitExpr(S);
  1589. }
  1590. void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
  1591. VisitExpr(S);
  1592. }
  1593. void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
  1594. VisitExpr(E);
  1595. }
  1596. void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
  1597. VisitExpr(E);
  1598. }
  1599. void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
  1600. VisitExpr(E);
  1601. }
  1602. void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
  1603. VisitExpr(S);
  1604. }
  1605. void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
  1606. VisitExpr(E);
  1607. }
  1608. void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
  1609. VisitExpr(E);
  1610. }
  1611. void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
  1612. VisitExpr(E);
  1613. }
  1614. void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
  1615. VisitExpr(S);
  1616. VisitType(S->getEncodedType());
  1617. }
  1618. void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
  1619. VisitExpr(S);
  1620. VisitName(S->getSelector());
  1621. }
  1622. void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
  1623. VisitExpr(S);
  1624. VisitDecl(S->getProtocol());
  1625. }
  1626. void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
  1627. VisitExpr(S);
  1628. VisitDecl(S->getDecl());
  1629. ID.AddBoolean(S->isArrow());
  1630. ID.AddBoolean(S->isFreeIvar());
  1631. }
  1632. void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
  1633. VisitExpr(S);
  1634. if (S->isImplicitProperty()) {
  1635. VisitDecl(S->getImplicitPropertyGetter());
  1636. VisitDecl(S->getImplicitPropertySetter());
  1637. } else {
  1638. VisitDecl(S->getExplicitProperty());
  1639. }
  1640. if (S->isSuperReceiver()) {
  1641. ID.AddBoolean(S->isSuperReceiver());
  1642. VisitType(S->getSuperReceiverType());
  1643. }
  1644. }
  1645. void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
  1646. VisitExpr(S);
  1647. VisitDecl(S->getAtIndexMethodDecl());
  1648. VisitDecl(S->setAtIndexMethodDecl());
  1649. }
  1650. void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
  1651. VisitExpr(S);
  1652. VisitName(S->getSelector());
  1653. VisitDecl(S->getMethodDecl());
  1654. }
  1655. void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
  1656. VisitExpr(S);
  1657. ID.AddBoolean(S->isArrow());
  1658. }
  1659. void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
  1660. VisitExpr(S);
  1661. ID.AddBoolean(S->getValue());
  1662. }
  1663. void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
  1664. const ObjCIndirectCopyRestoreExpr *S) {
  1665. VisitExpr(S);
  1666. ID.AddBoolean(S->shouldCopy());
  1667. }
  1668. void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
  1669. VisitExplicitCastExpr(S);
  1670. ID.AddBoolean(S->getBridgeKind());
  1671. }
  1672. void StmtProfiler::VisitObjCAvailabilityCheckExpr(
  1673. const ObjCAvailabilityCheckExpr *S) {
  1674. VisitExpr(S);
  1675. }
  1676. void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
  1677. unsigned NumArgs) {
  1678. ID.AddInteger(NumArgs);
  1679. for (unsigned I = 0; I != NumArgs; ++I)
  1680. VisitTemplateArgument(Args[I].getArgument());
  1681. }
  1682. void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
  1683. // Mostly repetitive with TemplateArgument::Profile!
  1684. ID.AddInteger(Arg.getKind());
  1685. switch (Arg.getKind()) {
  1686. case TemplateArgument::Null:
  1687. break;
  1688. case TemplateArgument::Type:
  1689. VisitType(Arg.getAsType());
  1690. break;
  1691. case TemplateArgument::Template:
  1692. case TemplateArgument::TemplateExpansion:
  1693. VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
  1694. break;
  1695. case TemplateArgument::Declaration:
  1696. VisitDecl(Arg.getAsDecl());
  1697. break;
  1698. case TemplateArgument::NullPtr:
  1699. VisitType(Arg.getNullPtrType());
  1700. break;
  1701. case TemplateArgument::Integral:
  1702. Arg.getAsIntegral().Profile(ID);
  1703. VisitType(Arg.getIntegralType());
  1704. break;
  1705. case TemplateArgument::Expression:
  1706. Visit(Arg.getAsExpr());
  1707. break;
  1708. case TemplateArgument::Pack:
  1709. for (const auto &P : Arg.pack_elements())
  1710. VisitTemplateArgument(P);
  1711. break;
  1712. }
  1713. }
  1714. void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
  1715. bool Canonical) const {
  1716. StmtProfilerWithPointers Profiler(ID, Context, Canonical);
  1717. Profiler.Visit(this);
  1718. }
  1719. void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
  1720. class ODRHash &Hash) const {
  1721. StmtProfilerWithoutPointers Profiler(ID, Hash);
  1722. Profiler.Visit(this);
  1723. }