1313#include  " clang/Index/USRGeneration.h" 
1414#include  " llvm/ADT/StringExtras.h" 
1515#include  " llvm/ADT/StringSet.h" 
16+ #include  " llvm/Support/Error.h" 
1617#include  " llvm/Support/Mutex.h" 
18+ #include  " llvm/Support/TimeProfiler.h" 
1719
1820namespace  clang  {
1921namespace  doc  {
@@ -40,48 +42,66 @@ Location MapASTVisitor::getDeclLocation(const NamedDecl *D) const {
4042}
4143
4244void  MapASTVisitor::HandleTranslationUnit (ASTContext &Context) {
45+   if  (CDCtx.FTimeTrace )
46+     llvm::timeTraceProfilerInitialize (200 , " clang-doc"  );
4347  TraverseDecl (Context.getTranslationUnitDecl ());
48+   if  (CDCtx.FTimeTrace )
49+     llvm::timeTraceProfilerFinishThread ();
4450}
4551
4652template  <typename  T>
4753bool  MapASTVisitor::mapDecl (const  T *D, bool  IsDefinition) {
48-   //  If we're looking a decl not in user files, skip this decl.
49-   if  (D->getASTContext ().getSourceManager ().isInSystemHeader (D->getLocation ()))
50-     return  true ;
54+   llvm::TimeTraceScope TS (" Mapping declaration"  );
55+   {
56+     llvm::TimeTraceScope TS (" Preamble"  );
57+     //  If we're looking a decl not in user files, skip this decl.
58+     if  (D->getASTContext ().getSourceManager ().isInSystemHeader (
59+             D->getLocation ()))
60+       return  true ;
5161
52-   //  Skip function-internal decls.
53-   if  (D->getParentFunctionOrMethod ())
54-     return  true ;
62+     //  Skip function-internal decls.
63+     if  (D->getParentFunctionOrMethod ())
64+       return  true ;
65+   }
66+ 
67+   std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> CP;
5568
56-   llvm::SmallString<128 > USR;
57-   //  If there is an error generating a USR for the decl, skip this decl.
58-   if  (index::generateUSRForDecl (D, USR))
59-     return  true ;
60-   //  Prevent Visiting USR twice
6169  {
62-     llvm::sys::SmartScopedLock<true > Guard (USRVisitedGuard);
63-     StringRef Visited = USR.str ();
64-     if  (USRVisited.count (Visited) && !isTypedefAnonRecord<T>(D))
70+     llvm::TimeTraceScope TS (" emit info from astnode"  );
71+     llvm::SmallString<128 > USR;
72+     //  If there is an error generating a USR for the decl, skip this decl.
73+     if  (index::generateUSRForDecl (D, USR))
6574      return  true ;
66-     //  We considered a USR to be visited only when its defined
67-     if  (IsDefinition)
68-       USRVisited.insert (Visited);
75+     //  Prevent Visiting USR twice
76+     {
77+       llvm::sys::SmartScopedLock<true > Guard (USRVisitedGuard);
78+       StringRef Visited = USR.str ();
79+       if  (USRVisited.count (Visited) && !isTypedefAnonRecord<T>(D))
80+         return  true ;
81+       //  We considered a USR to be visited only when its defined
82+       if  (IsDefinition)
83+         USRVisited.insert (Visited);
84+     }
85+     bool  IsFileInRootDir;
86+     llvm::SmallString<128 > File =
87+         getFile (D, D->getASTContext (), CDCtx.SourceRoot , IsFileInRootDir);
88+     CP = serialize::emitInfo (D, getComment (D, D->getASTContext ()),
89+                              getDeclLocation (D), CDCtx.PublicOnly );
90+   }
91+ 
92+   auto  &[Child, Parent] = CP;
93+ 
94+   {
95+     llvm::TimeTraceScope TS (" serialized info into bitcode"  );
96+     //  A null in place of a valid Info indicates that the serializer is skipping
97+     //  this decl for some reason (e.g. we're only reporting public decls).
98+     if  (Child)
99+       CDCtx.ECtx ->reportResult (llvm::toHex (llvm::toStringRef (Child->USR )),
100+                                serialize::serialize (Child));
101+     if  (Parent)
102+       CDCtx.ECtx ->reportResult (llvm::toHex (llvm::toStringRef (Parent->USR )),
103+                                serialize::serialize (Parent));
69104  }
70-   bool  IsFileInRootDir;
71-   llvm::SmallString<128 > File =
72-       getFile (D, D->getASTContext (), CDCtx.SourceRoot , IsFileInRootDir);
73-   auto  [Child, Parent] =
74-       serialize::emitInfo (D, getComment (D, D->getASTContext ()),
75-                           getDeclLocation (D), CDCtx.PublicOnly );
76- 
77-   //  A null in place of a valid Info indicates that the serializer is skipping
78-   //  this decl for some reason (e.g. we're only reporting public decls).
79-   if  (Child)
80-     CDCtx.ECtx ->reportResult (llvm::toHex (llvm::toStringRef (Child->USR )),
81-                              serialize::serialize (Child));
82-   if  (Parent)
83-     CDCtx.ECtx ->reportResult (llvm::toHex (llvm::toStringRef (Parent->USR )),
84-                              serialize::serialize (Parent));
85105  return  true ;
86106}
87107
0 commit comments