77// ===----------------------------------------------------------------------===//
88
99#include " Mapper.h"
10- #include " BitcodeWriter.h"
1110#include " Serialize.h"
1211#include " clang/AST/Comment.h"
1312#include " clang/Index/USRGeneration.h"
1413#include " llvm/ADT/StringExtras.h"
1514#include " llvm/ADT/StringSet.h"
1615#include " llvm/Support/Mutex.h"
16+ #include " llvm/Support/TimeProfiler.h"
1717
1818namespace clang {
1919namespace doc {
@@ -40,48 +40,66 @@ Location MapASTVisitor::getDeclLocation(const NamedDecl *D) const {
4040}
4141
4242void MapASTVisitor::HandleTranslationUnit (ASTContext &Context) {
43+ if (CDCtx.FTimeTrace )
44+ llvm::timeTraceProfilerInitialize (200 , " clang-doc" );
4345 TraverseDecl (Context.getTranslationUnitDecl ());
46+ if (CDCtx.FTimeTrace )
47+ llvm::timeTraceProfilerFinishThread ();
4448}
4549
4650template <typename T>
4751bool 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 ;
52+ llvm::TimeTraceScope TS (" Mapping declaration" );
53+ {
54+ llvm::TimeTraceScope TS (" Preamble" );
55+ // If we're looking a decl not in user files, skip this decl.
56+ if (D->getASTContext ().getSourceManager ().isInSystemHeader (
57+ D->getLocation ()))
58+ return true ;
5159
52- // Skip function-internal decls.
53- if (D->getParentFunctionOrMethod ())
54- return true ;
60+ // Skip function-internal decls.
61+ if (D->getParentFunctionOrMethod ())
62+ return true ;
63+ }
64+
65+ std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> CP;
5566
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
6167 {
62- llvm::sys::SmartScopedLock<true > Guard (USRVisitedGuard);
63- StringRef Visited = USR.str ();
64- if (USRVisited.count (Visited) && !isTypedefAnonRecord<T>(D))
68+ llvm::TimeTraceScope TS (" emit info from astnode" );
69+ llvm::SmallString<128 > USR;
70+ // If there is an error generating a USR for the decl, skip this decl.
71+ if (index::generateUSRForDecl (D, USR))
6572 return true ;
66- // We considered a USR to be visited only when its defined
67- if (IsDefinition)
68- USRVisited.insert (Visited);
73+ // Prevent Visiting USR twice
74+ {
75+ llvm::sys::SmartScopedLock<true > Guard (USRVisitedGuard);
76+ StringRef Visited = USR.str ();
77+ if (USRVisited.count (Visited) && !isTypedefAnonRecord<T>(D))
78+ return true ;
79+ // We considered a USR to be visited only when its defined
80+ if (IsDefinition)
81+ USRVisited.insert (Visited);
82+ }
83+ bool IsFileInRootDir;
84+ llvm::SmallString<128 > File =
85+ getFile (D, D->getASTContext (), CDCtx.SourceRoot , IsFileInRootDir);
86+ CP = serialize::emitInfo (D, getComment (D, D->getASTContext ()),
87+ getDeclLocation (D), CDCtx.PublicOnly );
88+ }
89+
90+ auto &[Child, Parent] = CP;
91+
92+ {
93+ llvm::TimeTraceScope TS (" serialized info into bitcode" );
94+ // A null in place of a valid Info indicates that the serializer is skipping
95+ // this decl for some reason (e.g. we're only reporting public decls).
96+ if (Child)
97+ CDCtx.ECtx ->reportResult (llvm::toHex (llvm::toStringRef (Child->USR )),
98+ serialize::serialize (Child));
99+ if (Parent)
100+ CDCtx.ECtx ->reportResult (llvm::toHex (llvm::toStringRef (Parent->USR )),
101+ serialize::serialize (Parent));
69102 }
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));
85103 return true ;
86104}
87105
0 commit comments