7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " Mapper.h"
10
- #include " BitcodeWriter.h"
11
10
#include " Serialize.h"
12
11
#include " clang/AST/Comment.h"
13
12
#include " clang/Index/USRGeneration.h"
14
13
#include " llvm/ADT/StringExtras.h"
15
14
#include " llvm/ADT/StringSet.h"
16
15
#include " llvm/Support/Mutex.h"
16
+ #include " llvm/Support/TimeProfiler.h"
17
17
18
18
namespace clang {
19
19
namespace doc {
@@ -40,48 +40,66 @@ Location MapASTVisitor::getDeclLocation(const NamedDecl *D) const {
40
40
}
41
41
42
42
void MapASTVisitor::HandleTranslationUnit (ASTContext &Context) {
43
+ if (CDCtx.FTimeTrace )
44
+ llvm::timeTraceProfilerInitialize (200 , " clang-doc" );
43
45
TraverseDecl (Context.getTranslationUnitDecl ());
46
+ if (CDCtx.FTimeTrace )
47
+ llvm::timeTraceProfilerFinishThread ();
44
48
}
45
49
46
50
template <typename T>
47
51
bool 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 ;
51
59
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;
55
66
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
61
67
{
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))
65
72
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));
69
102
}
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));
85
103
return true ;
86
104
}
87
105
0 commit comments