StmtProfile.cpp 55 KB

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