StmtProfile.cpp 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  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::VisitOMPMasterTaskLoopDirective(
  784. const OMPMasterTaskLoopDirective *S) {
  785. VisitOMPLoopDirective(S);
  786. }
  787. void StmtProfiler::VisitOMPDistributeDirective(
  788. const OMPDistributeDirective *S) {
  789. VisitOMPLoopDirective(S);
  790. }
  791. void OMPClauseProfiler::VisitOMPDistScheduleClause(
  792. const OMPDistScheduleClause *C) {
  793. VistOMPClauseWithPreInit(C);
  794. if (auto *S = C->getChunkSize())
  795. Profiler->VisitStmt(S);
  796. }
  797. void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
  798. void StmtProfiler::VisitOMPTargetUpdateDirective(
  799. const OMPTargetUpdateDirective *S) {
  800. VisitOMPExecutableDirective(S);
  801. }
  802. void StmtProfiler::VisitOMPDistributeParallelForDirective(
  803. const OMPDistributeParallelForDirective *S) {
  804. VisitOMPLoopDirective(S);
  805. }
  806. void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
  807. const OMPDistributeParallelForSimdDirective *S) {
  808. VisitOMPLoopDirective(S);
  809. }
  810. void StmtProfiler::VisitOMPDistributeSimdDirective(
  811. const OMPDistributeSimdDirective *S) {
  812. VisitOMPLoopDirective(S);
  813. }
  814. void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
  815. const OMPTargetParallelForSimdDirective *S) {
  816. VisitOMPLoopDirective(S);
  817. }
  818. void StmtProfiler::VisitOMPTargetSimdDirective(
  819. const OMPTargetSimdDirective *S) {
  820. VisitOMPLoopDirective(S);
  821. }
  822. void StmtProfiler::VisitOMPTeamsDistributeDirective(
  823. const OMPTeamsDistributeDirective *S) {
  824. VisitOMPLoopDirective(S);
  825. }
  826. void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
  827. const OMPTeamsDistributeSimdDirective *S) {
  828. VisitOMPLoopDirective(S);
  829. }
  830. void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
  831. const OMPTeamsDistributeParallelForSimdDirective *S) {
  832. VisitOMPLoopDirective(S);
  833. }
  834. void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
  835. const OMPTeamsDistributeParallelForDirective *S) {
  836. VisitOMPLoopDirective(S);
  837. }
  838. void StmtProfiler::VisitOMPTargetTeamsDirective(
  839. const OMPTargetTeamsDirective *S) {
  840. VisitOMPExecutableDirective(S);
  841. }
  842. void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
  843. const OMPTargetTeamsDistributeDirective *S) {
  844. VisitOMPLoopDirective(S);
  845. }
  846. void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
  847. const OMPTargetTeamsDistributeParallelForDirective *S) {
  848. VisitOMPLoopDirective(S);
  849. }
  850. void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
  851. const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
  852. VisitOMPLoopDirective(S);
  853. }
  854. void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
  855. const OMPTargetTeamsDistributeSimdDirective *S) {
  856. VisitOMPLoopDirective(S);
  857. }
  858. void StmtProfiler::VisitExpr(const Expr *S) {
  859. VisitStmt(S);
  860. }
  861. void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
  862. VisitExpr(S);
  863. }
  864. void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
  865. VisitExpr(S);
  866. if (!Canonical)
  867. VisitNestedNameSpecifier(S->getQualifier());
  868. VisitDecl(S->getDecl());
  869. if (!Canonical) {
  870. ID.AddBoolean(S->hasExplicitTemplateArgs());
  871. if (S->hasExplicitTemplateArgs())
  872. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  873. }
  874. }
  875. void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
  876. VisitExpr(S);
  877. ID.AddInteger(S->getIdentKind());
  878. }
  879. void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
  880. VisitExpr(S);
  881. S->getValue().Profile(ID);
  882. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  883. }
  884. void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
  885. VisitExpr(S);
  886. S->getValue().Profile(ID);
  887. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  888. }
  889. void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
  890. VisitExpr(S);
  891. ID.AddInteger(S->getKind());
  892. ID.AddInteger(S->getValue());
  893. }
  894. void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
  895. VisitExpr(S);
  896. S->getValue().Profile(ID);
  897. ID.AddBoolean(S->isExact());
  898. ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
  899. }
  900. void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
  901. VisitExpr(S);
  902. }
  903. void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
  904. VisitExpr(S);
  905. ID.AddString(S->getBytes());
  906. ID.AddInteger(S->getKind());
  907. }
  908. void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
  909. VisitExpr(S);
  910. }
  911. void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
  912. VisitExpr(S);
  913. }
  914. void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
  915. VisitExpr(S);
  916. ID.AddInteger(S->getOpcode());
  917. }
  918. void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
  919. VisitType(S->getTypeSourceInfo()->getType());
  920. unsigned n = S->getNumComponents();
  921. for (unsigned i = 0; i < n; ++i) {
  922. const OffsetOfNode &ON = S->getComponent(i);
  923. ID.AddInteger(ON.getKind());
  924. switch (ON.getKind()) {
  925. case OffsetOfNode::Array:
  926. // Expressions handled below.
  927. break;
  928. case OffsetOfNode::Field:
  929. VisitDecl(ON.getField());
  930. break;
  931. case OffsetOfNode::Identifier:
  932. VisitIdentifierInfo(ON.getFieldName());
  933. break;
  934. case OffsetOfNode::Base:
  935. // These nodes are implicit, and therefore don't need profiling.
  936. break;
  937. }
  938. }
  939. VisitExpr(S);
  940. }
  941. void
  942. StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
  943. VisitExpr(S);
  944. ID.AddInteger(S->getKind());
  945. if (S->isArgumentType())
  946. VisitType(S->getArgumentType());
  947. }
  948. void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
  949. VisitExpr(S);
  950. }
  951. void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
  952. VisitExpr(S);
  953. }
  954. void StmtProfiler::VisitCallExpr(const CallExpr *S) {
  955. VisitExpr(S);
  956. }
  957. void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
  958. VisitExpr(S);
  959. VisitDecl(S->getMemberDecl());
  960. if (!Canonical)
  961. VisitNestedNameSpecifier(S->getQualifier());
  962. ID.AddBoolean(S->isArrow());
  963. }
  964. void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
  965. VisitExpr(S);
  966. ID.AddBoolean(S->isFileScope());
  967. }
  968. void StmtProfiler::VisitCastExpr(const CastExpr *S) {
  969. VisitExpr(S);
  970. }
  971. void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
  972. VisitCastExpr(S);
  973. ID.AddInteger(S->getValueKind());
  974. }
  975. void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
  976. VisitCastExpr(S);
  977. VisitType(S->getTypeAsWritten());
  978. }
  979. void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
  980. VisitExplicitCastExpr(S);
  981. }
  982. void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
  983. VisitExpr(S);
  984. ID.AddInteger(S->getOpcode());
  985. }
  986. void
  987. StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
  988. VisitBinaryOperator(S);
  989. }
  990. void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
  991. VisitExpr(S);
  992. }
  993. void StmtProfiler::VisitBinaryConditionalOperator(
  994. const BinaryConditionalOperator *S) {
  995. VisitExpr(S);
  996. }
  997. void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
  998. VisitExpr(S);
  999. VisitDecl(S->getLabel());
  1000. }
  1001. void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
  1002. VisitExpr(S);
  1003. }
  1004. void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
  1005. VisitExpr(S);
  1006. }
  1007. void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
  1008. VisitExpr(S);
  1009. }
  1010. void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
  1011. VisitExpr(S);
  1012. }
  1013. void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
  1014. VisitExpr(S);
  1015. }
  1016. void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
  1017. VisitExpr(S);
  1018. }
  1019. void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
  1020. if (S->getSyntacticForm()) {
  1021. VisitInitListExpr(S->getSyntacticForm());
  1022. return;
  1023. }
  1024. VisitExpr(S);
  1025. }
  1026. void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
  1027. VisitExpr(S);
  1028. ID.AddBoolean(S->usesGNUSyntax());
  1029. for (const DesignatedInitExpr::Designator &D : S->designators()) {
  1030. if (D.isFieldDesignator()) {
  1031. ID.AddInteger(0);
  1032. VisitName(D.getFieldName());
  1033. continue;
  1034. }
  1035. if (D.isArrayDesignator()) {
  1036. ID.AddInteger(1);
  1037. } else {
  1038. assert(D.isArrayRangeDesignator());
  1039. ID.AddInteger(2);
  1040. }
  1041. ID.AddInteger(D.getFirstExprIndex());
  1042. }
  1043. }
  1044. // Seems that if VisitInitListExpr() only works on the syntactic form of an
  1045. // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
  1046. void StmtProfiler::VisitDesignatedInitUpdateExpr(
  1047. const DesignatedInitUpdateExpr *S) {
  1048. llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
  1049. "initializer");
  1050. }
  1051. void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
  1052. VisitExpr(S);
  1053. }
  1054. void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
  1055. VisitExpr(S);
  1056. }
  1057. void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
  1058. llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
  1059. }
  1060. void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
  1061. VisitExpr(S);
  1062. }
  1063. void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
  1064. VisitExpr(S);
  1065. VisitName(&S->getAccessor());
  1066. }
  1067. void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
  1068. VisitExpr(S);
  1069. VisitDecl(S->getBlockDecl());
  1070. }
  1071. void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
  1072. VisitExpr(S);
  1073. for (const GenericSelectionExpr::ConstAssociation &Assoc :
  1074. S->associations()) {
  1075. QualType T = Assoc.getType();
  1076. if (T.isNull())
  1077. ID.AddPointer(nullptr);
  1078. else
  1079. VisitType(T);
  1080. VisitExpr(Assoc.getAssociationExpr());
  1081. }
  1082. }
  1083. void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
  1084. VisitExpr(S);
  1085. for (PseudoObjectExpr::const_semantics_iterator
  1086. i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
  1087. // Normally, we would not profile the source expressions of OVEs.
  1088. if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
  1089. Visit(OVE->getSourceExpr());
  1090. }
  1091. void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
  1092. VisitExpr(S);
  1093. ID.AddInteger(S->getOp());
  1094. }
  1095. static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
  1096. UnaryOperatorKind &UnaryOp,
  1097. BinaryOperatorKind &BinaryOp) {
  1098. switch (S->getOperator()) {
  1099. case OO_None:
  1100. case OO_New:
  1101. case OO_Delete:
  1102. case OO_Array_New:
  1103. case OO_Array_Delete:
  1104. case OO_Arrow:
  1105. case OO_Call:
  1106. case OO_Conditional:
  1107. case NUM_OVERLOADED_OPERATORS:
  1108. llvm_unreachable("Invalid operator call kind");
  1109. case OO_Plus:
  1110. if (S->getNumArgs() == 1) {
  1111. UnaryOp = UO_Plus;
  1112. return Stmt::UnaryOperatorClass;
  1113. }
  1114. BinaryOp = BO_Add;
  1115. return Stmt::BinaryOperatorClass;
  1116. case OO_Minus:
  1117. if (S->getNumArgs() == 1) {
  1118. UnaryOp = UO_Minus;
  1119. return Stmt::UnaryOperatorClass;
  1120. }
  1121. BinaryOp = BO_Sub;
  1122. return Stmt::BinaryOperatorClass;
  1123. case OO_Star:
  1124. if (S->getNumArgs() == 1) {
  1125. UnaryOp = UO_Deref;
  1126. return Stmt::UnaryOperatorClass;
  1127. }
  1128. BinaryOp = BO_Mul;
  1129. return Stmt::BinaryOperatorClass;
  1130. case OO_Slash:
  1131. BinaryOp = BO_Div;
  1132. return Stmt::BinaryOperatorClass;
  1133. case OO_Percent:
  1134. BinaryOp = BO_Rem;
  1135. return Stmt::BinaryOperatorClass;
  1136. case OO_Caret:
  1137. BinaryOp = BO_Xor;
  1138. return Stmt::BinaryOperatorClass;
  1139. case OO_Amp:
  1140. if (S->getNumArgs() == 1) {
  1141. UnaryOp = UO_AddrOf;
  1142. return Stmt::UnaryOperatorClass;
  1143. }
  1144. BinaryOp = BO_And;
  1145. return Stmt::BinaryOperatorClass;
  1146. case OO_Pipe:
  1147. BinaryOp = BO_Or;
  1148. return Stmt::BinaryOperatorClass;
  1149. case OO_Tilde:
  1150. UnaryOp = UO_Not;
  1151. return Stmt::UnaryOperatorClass;
  1152. case OO_Exclaim:
  1153. UnaryOp = UO_LNot;
  1154. return Stmt::UnaryOperatorClass;
  1155. case OO_Equal:
  1156. BinaryOp = BO_Assign;
  1157. return Stmt::BinaryOperatorClass;
  1158. case OO_Less:
  1159. BinaryOp = BO_LT;
  1160. return Stmt::BinaryOperatorClass;
  1161. case OO_Greater:
  1162. BinaryOp = BO_GT;
  1163. return Stmt::BinaryOperatorClass;
  1164. case OO_PlusEqual:
  1165. BinaryOp = BO_AddAssign;
  1166. return Stmt::CompoundAssignOperatorClass;
  1167. case OO_MinusEqual:
  1168. BinaryOp = BO_SubAssign;
  1169. return Stmt::CompoundAssignOperatorClass;
  1170. case OO_StarEqual:
  1171. BinaryOp = BO_MulAssign;
  1172. return Stmt::CompoundAssignOperatorClass;
  1173. case OO_SlashEqual:
  1174. BinaryOp = BO_DivAssign;
  1175. return Stmt::CompoundAssignOperatorClass;
  1176. case OO_PercentEqual:
  1177. BinaryOp = BO_RemAssign;
  1178. return Stmt::CompoundAssignOperatorClass;
  1179. case OO_CaretEqual:
  1180. BinaryOp = BO_XorAssign;
  1181. return Stmt::CompoundAssignOperatorClass;
  1182. case OO_AmpEqual:
  1183. BinaryOp = BO_AndAssign;
  1184. return Stmt::CompoundAssignOperatorClass;
  1185. case OO_PipeEqual:
  1186. BinaryOp = BO_OrAssign;
  1187. return Stmt::CompoundAssignOperatorClass;
  1188. case OO_LessLess:
  1189. BinaryOp = BO_Shl;
  1190. return Stmt::BinaryOperatorClass;
  1191. case OO_GreaterGreater:
  1192. BinaryOp = BO_Shr;
  1193. return Stmt::BinaryOperatorClass;
  1194. case OO_LessLessEqual:
  1195. BinaryOp = BO_ShlAssign;
  1196. return Stmt::CompoundAssignOperatorClass;
  1197. case OO_GreaterGreaterEqual:
  1198. BinaryOp = BO_ShrAssign;
  1199. return Stmt::CompoundAssignOperatorClass;
  1200. case OO_EqualEqual:
  1201. BinaryOp = BO_EQ;
  1202. return Stmt::BinaryOperatorClass;
  1203. case OO_ExclaimEqual:
  1204. BinaryOp = BO_NE;
  1205. return Stmt::BinaryOperatorClass;
  1206. case OO_LessEqual:
  1207. BinaryOp = BO_LE;
  1208. return Stmt::BinaryOperatorClass;
  1209. case OO_GreaterEqual:
  1210. BinaryOp = BO_GE;
  1211. return Stmt::BinaryOperatorClass;
  1212. case OO_Spaceship:
  1213. // FIXME: Update this once we support <=> expressions.
  1214. llvm_unreachable("<=> expressions not supported yet");
  1215. case OO_AmpAmp:
  1216. BinaryOp = BO_LAnd;
  1217. return Stmt::BinaryOperatorClass;
  1218. case OO_PipePipe:
  1219. BinaryOp = BO_LOr;
  1220. return Stmt::BinaryOperatorClass;
  1221. case OO_PlusPlus:
  1222. UnaryOp = S->getNumArgs() == 1? UO_PreInc
  1223. : UO_PostInc;
  1224. return Stmt::UnaryOperatorClass;
  1225. case OO_MinusMinus:
  1226. UnaryOp = S->getNumArgs() == 1? UO_PreDec
  1227. : UO_PostDec;
  1228. return Stmt::UnaryOperatorClass;
  1229. case OO_Comma:
  1230. BinaryOp = BO_Comma;
  1231. return Stmt::BinaryOperatorClass;
  1232. case OO_ArrowStar:
  1233. BinaryOp = BO_PtrMemI;
  1234. return Stmt::BinaryOperatorClass;
  1235. case OO_Subscript:
  1236. return Stmt::ArraySubscriptExprClass;
  1237. case OO_Coawait:
  1238. UnaryOp = UO_Coawait;
  1239. return Stmt::UnaryOperatorClass;
  1240. }
  1241. llvm_unreachable("Invalid overloaded operator expression");
  1242. }
  1243. #if defined(_MSC_VER) && !defined(__clang__)
  1244. #if _MSC_VER == 1911
  1245. // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
  1246. // MSVC 2017 update 3 miscompiles this function, and a clang built with it
  1247. // will crash in stage 2 of a bootstrap build.
  1248. #pragma optimize("", off)
  1249. #endif
  1250. #endif
  1251. void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
  1252. if (S->isTypeDependent()) {
  1253. // Type-dependent operator calls are profiled like their underlying
  1254. // syntactic operator.
  1255. //
  1256. // An operator call to operator-> is always implicit, so just skip it. The
  1257. // enclosing MemberExpr will profile the actual member access.
  1258. if (S->getOperator() == OO_Arrow)
  1259. return Visit(S->getArg(0));
  1260. UnaryOperatorKind UnaryOp = UO_Extension;
  1261. BinaryOperatorKind BinaryOp = BO_Comma;
  1262. Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
  1263. ID.AddInteger(SC);
  1264. for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
  1265. Visit(S->getArg(I));
  1266. if (SC == Stmt::UnaryOperatorClass)
  1267. ID.AddInteger(UnaryOp);
  1268. else if (SC == Stmt::BinaryOperatorClass ||
  1269. SC == Stmt::CompoundAssignOperatorClass)
  1270. ID.AddInteger(BinaryOp);
  1271. else
  1272. assert(SC == Stmt::ArraySubscriptExprClass);
  1273. return;
  1274. }
  1275. VisitCallExpr(S);
  1276. ID.AddInteger(S->getOperator());
  1277. }
  1278. #if defined(_MSC_VER) && !defined(__clang__)
  1279. #if _MSC_VER == 1911
  1280. #pragma optimize("", on)
  1281. #endif
  1282. #endif
  1283. void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
  1284. VisitCallExpr(S);
  1285. }
  1286. void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
  1287. VisitCallExpr(S);
  1288. }
  1289. void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
  1290. VisitExpr(S);
  1291. }
  1292. void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
  1293. VisitExplicitCastExpr(S);
  1294. }
  1295. void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
  1296. VisitCXXNamedCastExpr(S);
  1297. }
  1298. void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
  1299. VisitCXXNamedCastExpr(S);
  1300. }
  1301. void
  1302. StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
  1303. VisitCXXNamedCastExpr(S);
  1304. }
  1305. void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
  1306. VisitCXXNamedCastExpr(S);
  1307. }
  1308. void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
  1309. VisitExpr(S);
  1310. VisitType(S->getTypeInfoAsWritten()->getType());
  1311. }
  1312. void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
  1313. VisitCallExpr(S);
  1314. }
  1315. void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
  1316. VisitExpr(S);
  1317. ID.AddBoolean(S->getValue());
  1318. }
  1319. void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
  1320. VisitExpr(S);
  1321. }
  1322. void StmtProfiler::VisitCXXStdInitializerListExpr(
  1323. const CXXStdInitializerListExpr *S) {
  1324. VisitExpr(S);
  1325. }
  1326. void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
  1327. VisitExpr(S);
  1328. if (S->isTypeOperand())
  1329. VisitType(S->getTypeOperandSourceInfo()->getType());
  1330. }
  1331. void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
  1332. VisitExpr(S);
  1333. if (S->isTypeOperand())
  1334. VisitType(S->getTypeOperandSourceInfo()->getType());
  1335. }
  1336. void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
  1337. VisitExpr(S);
  1338. VisitDecl(S->getPropertyDecl());
  1339. }
  1340. void StmtProfiler::VisitMSPropertySubscriptExpr(
  1341. const MSPropertySubscriptExpr *S) {
  1342. VisitExpr(S);
  1343. }
  1344. void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
  1345. VisitExpr(S);
  1346. ID.AddBoolean(S->isImplicit());
  1347. }
  1348. void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
  1349. VisitExpr(S);
  1350. }
  1351. void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
  1352. VisitExpr(S);
  1353. VisitDecl(S->getParam());
  1354. }
  1355. void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
  1356. VisitExpr(S);
  1357. VisitDecl(S->getField());
  1358. }
  1359. void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
  1360. VisitExpr(S);
  1361. VisitDecl(
  1362. const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
  1363. }
  1364. void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
  1365. VisitExpr(S);
  1366. VisitDecl(S->getConstructor());
  1367. ID.AddBoolean(S->isElidable());
  1368. }
  1369. void StmtProfiler::VisitCXXInheritedCtorInitExpr(
  1370. const CXXInheritedCtorInitExpr *S) {
  1371. VisitExpr(S);
  1372. VisitDecl(S->getConstructor());
  1373. }
  1374. void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
  1375. VisitExplicitCastExpr(S);
  1376. }
  1377. void
  1378. StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
  1379. VisitCXXConstructExpr(S);
  1380. }
  1381. void
  1382. StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
  1383. VisitExpr(S);
  1384. for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
  1385. CEnd = S->explicit_capture_end();
  1386. C != CEnd; ++C) {
  1387. if (C->capturesVLAType())
  1388. continue;
  1389. ID.AddInteger(C->getCaptureKind());
  1390. switch (C->getCaptureKind()) {
  1391. case LCK_StarThis:
  1392. case LCK_This:
  1393. break;
  1394. case LCK_ByRef:
  1395. case LCK_ByCopy:
  1396. VisitDecl(C->getCapturedVar());
  1397. ID.AddBoolean(C->isPackExpansion());
  1398. break;
  1399. case LCK_VLAType:
  1400. llvm_unreachable("VLA type in explicit captures.");
  1401. }
  1402. }
  1403. // Note: If we actually needed to be able to match lambda
  1404. // expressions, we would have to consider parameters and return type
  1405. // here, among other things.
  1406. VisitStmt(S->getBody());
  1407. }
  1408. void
  1409. StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
  1410. VisitExpr(S);
  1411. }
  1412. void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
  1413. VisitExpr(S);
  1414. ID.AddBoolean(S->isGlobalDelete());
  1415. ID.AddBoolean(S->isArrayForm());
  1416. VisitDecl(S->getOperatorDelete());
  1417. }
  1418. void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
  1419. VisitExpr(S);
  1420. VisitType(S->getAllocatedType());
  1421. VisitDecl(S->getOperatorNew());
  1422. VisitDecl(S->getOperatorDelete());
  1423. ID.AddBoolean(S->isArray());
  1424. ID.AddInteger(S->getNumPlacementArgs());
  1425. ID.AddBoolean(S->isGlobalNew());
  1426. ID.AddBoolean(S->isParenTypeId());
  1427. ID.AddInteger(S->getInitializationStyle());
  1428. }
  1429. void
  1430. StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
  1431. VisitExpr(S);
  1432. ID.AddBoolean(S->isArrow());
  1433. VisitNestedNameSpecifier(S->getQualifier());
  1434. ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
  1435. if (S->getScopeTypeInfo())
  1436. VisitType(S->getScopeTypeInfo()->getType());
  1437. ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
  1438. if (S->getDestroyedTypeInfo())
  1439. VisitType(S->getDestroyedType());
  1440. else
  1441. VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
  1442. }
  1443. void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
  1444. VisitExpr(S);
  1445. VisitNestedNameSpecifier(S->getQualifier());
  1446. VisitName(S->getName(), /*TreatAsDecl*/ true);
  1447. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1448. if (S->hasExplicitTemplateArgs())
  1449. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1450. }
  1451. void
  1452. StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
  1453. VisitOverloadExpr(S);
  1454. }
  1455. void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
  1456. VisitExpr(S);
  1457. ID.AddInteger(S->getTrait());
  1458. ID.AddInteger(S->getNumArgs());
  1459. for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
  1460. VisitType(S->getArg(I)->getType());
  1461. }
  1462. void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
  1463. VisitExpr(S);
  1464. ID.AddInteger(S->getTrait());
  1465. VisitType(S->getQueriedType());
  1466. }
  1467. void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
  1468. VisitExpr(S);
  1469. ID.AddInteger(S->getTrait());
  1470. VisitExpr(S->getQueriedExpression());
  1471. }
  1472. void StmtProfiler::VisitDependentScopeDeclRefExpr(
  1473. const DependentScopeDeclRefExpr *S) {
  1474. VisitExpr(S);
  1475. VisitName(S->getDeclName());
  1476. VisitNestedNameSpecifier(S->getQualifier());
  1477. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1478. if (S->hasExplicitTemplateArgs())
  1479. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1480. }
  1481. void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
  1482. VisitExpr(S);
  1483. }
  1484. void StmtProfiler::VisitCXXUnresolvedConstructExpr(
  1485. const CXXUnresolvedConstructExpr *S) {
  1486. VisitExpr(S);
  1487. VisitType(S->getTypeAsWritten());
  1488. ID.AddInteger(S->isListInitialization());
  1489. }
  1490. void StmtProfiler::VisitCXXDependentScopeMemberExpr(
  1491. const CXXDependentScopeMemberExpr *S) {
  1492. ID.AddBoolean(S->isImplicitAccess());
  1493. if (!S->isImplicitAccess()) {
  1494. VisitExpr(S);
  1495. ID.AddBoolean(S->isArrow());
  1496. }
  1497. VisitNestedNameSpecifier(S->getQualifier());
  1498. VisitName(S->getMember());
  1499. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1500. if (S->hasExplicitTemplateArgs())
  1501. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1502. }
  1503. void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
  1504. ID.AddBoolean(S->isImplicitAccess());
  1505. if (!S->isImplicitAccess()) {
  1506. VisitExpr(S);
  1507. ID.AddBoolean(S->isArrow());
  1508. }
  1509. VisitNestedNameSpecifier(S->getQualifier());
  1510. VisitName(S->getMemberName());
  1511. ID.AddBoolean(S->hasExplicitTemplateArgs());
  1512. if (S->hasExplicitTemplateArgs())
  1513. VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
  1514. }
  1515. void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
  1516. VisitExpr(S);
  1517. }
  1518. void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
  1519. VisitExpr(S);
  1520. }
  1521. void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
  1522. VisitExpr(S);
  1523. VisitDecl(S->getPack());
  1524. if (S->isPartiallySubstituted()) {
  1525. auto Args = S->getPartialArguments();
  1526. ID.AddInteger(Args.size());
  1527. for (const auto &TA : Args)
  1528. VisitTemplateArgument(TA);
  1529. } else {
  1530. ID.AddInteger(0);
  1531. }
  1532. }
  1533. void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
  1534. const SubstNonTypeTemplateParmPackExpr *S) {
  1535. VisitExpr(S);
  1536. VisitDecl(S->getParameterPack());
  1537. VisitTemplateArgument(S->getArgumentPack());
  1538. }
  1539. void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
  1540. const SubstNonTypeTemplateParmExpr *E) {
  1541. // Profile exactly as the replacement expression.
  1542. Visit(E->getReplacement());
  1543. }
  1544. void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
  1545. VisitExpr(S);
  1546. VisitDecl(S->getParameterPack());
  1547. ID.AddInteger(S->getNumExpansions());
  1548. for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
  1549. VisitDecl(*I);
  1550. }
  1551. void StmtProfiler::VisitMaterializeTemporaryExpr(
  1552. const MaterializeTemporaryExpr *S) {
  1553. VisitExpr(S);
  1554. }
  1555. void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
  1556. VisitExpr(S);
  1557. ID.AddInteger(S->getOperator());
  1558. }
  1559. void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
  1560. VisitStmt(S);
  1561. }
  1562. void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
  1563. VisitStmt(S);
  1564. }
  1565. void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
  1566. VisitExpr(S);
  1567. }
  1568. void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
  1569. VisitExpr(S);
  1570. }
  1571. void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
  1572. VisitExpr(S);
  1573. }
  1574. void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
  1575. VisitExpr(E);
  1576. }
  1577. void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
  1578. VisitExpr(E);
  1579. }
  1580. void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
  1581. VisitExpr(E);
  1582. }
  1583. void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
  1584. VisitExpr(S);
  1585. }
  1586. void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
  1587. VisitExpr(E);
  1588. }
  1589. void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
  1590. VisitExpr(E);
  1591. }
  1592. void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
  1593. VisitExpr(E);
  1594. }
  1595. void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
  1596. VisitExpr(S);
  1597. VisitType(S->getEncodedType());
  1598. }
  1599. void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
  1600. VisitExpr(S);
  1601. VisitName(S->getSelector());
  1602. }
  1603. void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
  1604. VisitExpr(S);
  1605. VisitDecl(S->getProtocol());
  1606. }
  1607. void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
  1608. VisitExpr(S);
  1609. VisitDecl(S->getDecl());
  1610. ID.AddBoolean(S->isArrow());
  1611. ID.AddBoolean(S->isFreeIvar());
  1612. }
  1613. void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
  1614. VisitExpr(S);
  1615. if (S->isImplicitProperty()) {
  1616. VisitDecl(S->getImplicitPropertyGetter());
  1617. VisitDecl(S->getImplicitPropertySetter());
  1618. } else {
  1619. VisitDecl(S->getExplicitProperty());
  1620. }
  1621. if (S->isSuperReceiver()) {
  1622. ID.AddBoolean(S->isSuperReceiver());
  1623. VisitType(S->getSuperReceiverType());
  1624. }
  1625. }
  1626. void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
  1627. VisitExpr(S);
  1628. VisitDecl(S->getAtIndexMethodDecl());
  1629. VisitDecl(S->setAtIndexMethodDecl());
  1630. }
  1631. void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
  1632. VisitExpr(S);
  1633. VisitName(S->getSelector());
  1634. VisitDecl(S->getMethodDecl());
  1635. }
  1636. void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
  1637. VisitExpr(S);
  1638. ID.AddBoolean(S->isArrow());
  1639. }
  1640. void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
  1641. VisitExpr(S);
  1642. ID.AddBoolean(S->getValue());
  1643. }
  1644. void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
  1645. const ObjCIndirectCopyRestoreExpr *S) {
  1646. VisitExpr(S);
  1647. ID.AddBoolean(S->shouldCopy());
  1648. }
  1649. void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
  1650. VisitExplicitCastExpr(S);
  1651. ID.AddBoolean(S->getBridgeKind());
  1652. }
  1653. void StmtProfiler::VisitObjCAvailabilityCheckExpr(
  1654. const ObjCAvailabilityCheckExpr *S) {
  1655. VisitExpr(S);
  1656. }
  1657. void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
  1658. unsigned NumArgs) {
  1659. ID.AddInteger(NumArgs);
  1660. for (unsigned I = 0; I != NumArgs; ++I)
  1661. VisitTemplateArgument(Args[I].getArgument());
  1662. }
  1663. void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
  1664. // Mostly repetitive with TemplateArgument::Profile!
  1665. ID.AddInteger(Arg.getKind());
  1666. switch (Arg.getKind()) {
  1667. case TemplateArgument::Null:
  1668. break;
  1669. case TemplateArgument::Type:
  1670. VisitType(Arg.getAsType());
  1671. break;
  1672. case TemplateArgument::Template:
  1673. case TemplateArgument::TemplateExpansion:
  1674. VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
  1675. break;
  1676. case TemplateArgument::Declaration:
  1677. VisitDecl(Arg.getAsDecl());
  1678. break;
  1679. case TemplateArgument::NullPtr:
  1680. VisitType(Arg.getNullPtrType());
  1681. break;
  1682. case TemplateArgument::Integral:
  1683. Arg.getAsIntegral().Profile(ID);
  1684. VisitType(Arg.getIntegralType());
  1685. break;
  1686. case TemplateArgument::Expression:
  1687. Visit(Arg.getAsExpr());
  1688. break;
  1689. case TemplateArgument::Pack:
  1690. for (const auto &P : Arg.pack_elements())
  1691. VisitTemplateArgument(P);
  1692. break;
  1693. }
  1694. }
  1695. void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
  1696. bool Canonical) const {
  1697. StmtProfilerWithPointers Profiler(ID, Context, Canonical);
  1698. Profiler.Visit(this);
  1699. }
  1700. void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
  1701. class ODRHash &Hash) const {
  1702. StmtProfilerWithoutPointers Profiler(ID, Hash);
  1703. Profiler.Visit(this);
  1704. }