StmtProfile.cpp 55 KB

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