Skip to content

Commit aa23c92

Browse files
committed
[clang-doc] fix merge conflict
2 parents cbe1802 + 7868c04 commit aa23c92

File tree

17 files changed

+1321
-79
lines changed

17 files changed

+1321
-79
lines changed

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "BitcodeReader.h"
1010
#include "llvm/ADT/IndexedMap.h"
1111
#include "llvm/Support/Error.h"
12+
#include "llvm/Support/TimeProfiler.h"
1213
#include "llvm/Support/raw_ostream.h"
1314
#include <optional>
1415

@@ -670,6 +671,7 @@ llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) {
670671

671672
template <>
672673
llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
674+
llvm::TimeTraceScope("Reducing infos", "readRecord");
673675
Record R;
674676
llvm::StringRef Blob;
675677
llvm::Expected<unsigned> MaybeRecID = Stream.readRecord(ID, R, &Blob);
@@ -681,6 +683,7 @@ llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
681683
// Read a block of records into a single info.
682684
template <typename T>
683685
llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
686+
llvm::TimeTraceScope("Reducing infos", "readBlock");
684687
if (llvm::Error Err = Stream.EnterSubBlock(ID))
685688
return Err;
686689

@@ -711,6 +714,7 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
711714

712715
template <typename T>
713716
llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
717+
llvm::TimeTraceScope("Reducing infos", "readSubBlock");
714718
switch (ID) {
715719
// Blocks can only have certain types of sub blocks.
716720
case BI_COMMENT_BLOCK_ID: {
@@ -817,6 +821,7 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
817821

818822
ClangDocBitcodeReader::Cursor
819823
ClangDocBitcodeReader::skipUntilRecordOrBlock(unsigned &BlockOrRecordID) {
824+
llvm::TimeTraceScope("Reducing infos", "skipUntilRecordOrBlock");
820825
BlockOrRecordID = 0;
821826

822827
while (!Stream.AtEndOfStream()) {
@@ -878,6 +883,7 @@ llvm::Error ClangDocBitcodeReader::validateStream() {
878883
}
879884

880885
llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
886+
llvm::TimeTraceScope("Reducing infos", "readBlockInfoBlock");
881887
Expected<std::optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
882888
Stream.ReadBlockInfoBlock();
883889
if (!MaybeBlockInfo)
@@ -894,6 +900,7 @@ llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
894900
template <typename T>
895901
llvm::Expected<std::unique_ptr<Info>>
896902
ClangDocBitcodeReader::createInfo(unsigned ID) {
903+
llvm::TimeTraceScope("Reducing infos", "createInfo");
897904
std::unique_ptr<Info> I = std::make_unique<T>();
898905
if (auto Err = readBlock(ID, static_cast<T *>(I.get())))
899906
return std::move(Err);
@@ -902,6 +909,7 @@ ClangDocBitcodeReader::createInfo(unsigned ID) {
902909

903910
llvm::Expected<std::unique_ptr<Info>>
904911
ClangDocBitcodeReader::readBlockToInfo(unsigned ID) {
912+
llvm::TimeTraceScope("Reducing infos", "readBlockToInfo");
905913
switch (ID) {
906914
case BI_NAMESPACE_BLOCK_ID:
907915
return createInfo<NamespaceInfo>(ID);

clang-tools-extra/clang-doc/Mapper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
#include "clang/Index/USRGeneration.h"
1414
#include "llvm/ADT/StringExtras.h"
1515
#include "llvm/Support/Error.h"
16+
#include "llvm/Support/TimeProfiler.h"
1617

1718
namespace clang {
1819
namespace doc {
1920

2021
void MapASTVisitor::HandleTranslationUnit(ASTContext &Context) {
22+
if (CDCtx.FTimeTrace)
23+
llvm::timeTraceProfilerInitialize(200, "clang-doc");
2124
TraverseDecl(Context.getTranslationUnitDecl());
25+
if (CDCtx.FTimeTrace)
26+
llvm::timeTraceProfilerFinishThread();
2227
}
2328

2429
template <typename T> bool MapASTVisitor::mapDecl(const T *D) {
@@ -30,6 +35,7 @@ template <typename T> bool MapASTVisitor::mapDecl(const T *D) {
3035
if (D->getParentFunctionOrMethod())
3136
return true;
3237

38+
llvm::timeTraceProfilerBegin("Mapping declaration", "emit info from astnode");
3339
llvm::SmallString<128> USR;
3440
// If there is an error generating a USR for the decl, skip this decl.
3541
if (index::generateUSRForDecl(D, USR))
@@ -40,7 +46,10 @@ template <typename T> bool MapASTVisitor::mapDecl(const T *D) {
4046
auto I = serialize::emitInfo(D, getComment(D, D->getASTContext()),
4147
getLine(D, D->getASTContext()), File,
4248
IsFileInRootDir, CDCtx.PublicOnly);
49+
llvm::timeTraceProfilerEnd();
4350

51+
llvm::timeTraceProfilerBegin("Mapping declaration",
52+
"serialized info into bitcode");
4453
// A null in place of I indicates that the serializer is skipping this decl
4554
// for some reason (e.g. we're only reporting public decls).
4655
if (I.first)
@@ -49,6 +58,7 @@ template <typename T> bool MapASTVisitor::mapDecl(const T *D) {
4958
if (I.second)
5059
CDCtx.ECtx->reportResult(llvm::toHex(llvm::toStringRef(I.second->USR)),
5160
serialize::serialize(I.second));
61+
llvm::timeTraceProfilerEnd();
5262
return true;
5363
}
5464

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,11 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
368368
StringRef ProjectName, bool PublicOnly,
369369
StringRef OutDirectory, StringRef SourceRoot,
370370
StringRef RepositoryUrl,
371-
std::vector<std::string> UserStylesheets)
371+
std::vector<std::string> UserStylesheets,
372+
bool FTimeTrace)
372373
: ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly),
373-
OutDirectory(OutDirectory), UserStylesheets(UserStylesheets) {
374+
OutDirectory(OutDirectory), UserStylesheets(UserStylesheets),
375+
FTimeTrace(FTimeTrace) {
374376
llvm::SmallString<128> SourceRootDir(SourceRoot);
375377
if (SourceRoot.empty())
376378
// If no SourceRoot was provided the current path is used as the default

clang-tools-extra/clang-doc/Representation.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,13 @@ struct ClangDocContext {
482482
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName,
483483
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
484484
StringRef RepositoryUrl,
485-
std::vector<std::string> UserStylesheets);
485+
std::vector<std::string> UserStylesheets,
486+
bool FTimeTrace = false);
486487
tooling::ExecutionContext *ECtx;
487488
std::string ProjectName; // Name of project clang-doc is documenting.
488489
bool PublicOnly; // Indicates if only public declarations are documented.
490+
bool FTimeTrace; // Indicates if ftime trace is turned on
491+
int Granularity; // Granularity of ftime trace
489492
std::string OutDirectory; // Directory for outputting generated files.
490493
std::string SourceRoot; // Directory where processed files are stored. Links
491494
// to definition locations will only be generated if

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 68 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,11 @@
4141
#include "llvm/Support/Process.h"
4242
#include "llvm/Support/Signals.h"
4343
#include "llvm/Support/ThreadPool.h"
44+
#include "llvm/Support/TimeProfiler.h"
4445
#include "llvm/Support/raw_ostream.h"
4546
#include <atomic>
4647
#include <mutex>
4748
#include <string>
48-
#include <exception>
49-
#include <typeinfo>
50-
#include <stdexcept>
51-
5249

5350
using namespace clang::ast_matchers;
5451
using namespace clang::tooling;
@@ -103,6 +100,11 @@ URL of repository that hosts code.
103100
Used for links to definition locations.)"),
104101
llvm::cl::cat(ClangDocCategory));
105102

103+
static llvm::cl::opt<bool> FTimeTrace("ftime-trace", llvm::cl::desc(R"(
104+
Turn on time profiler. Generates clang-doc-tracing.json)"),
105+
llvm::cl::init(false),
106+
llvm::cl::cat(ClangDocCategory));
107+
106108
enum OutputFormatTy {
107109
md,
108110
yaml,
@@ -209,19 +211,6 @@ llvm::Error getHtmlAssetFiles(const char *Argv0,
209211
return getDefaultAssetFiles(Argv0, CDCtx);
210212
}
211213

212-
void handle_eptr(std::exception_ptr eptr) // passing by value is OK
213-
{
214-
try
215-
{
216-
if (eptr)
217-
std::rethrow_exception(eptr);
218-
}
219-
catch(const std::exception& e)
220-
{
221-
llvm::outs() << "Caught exception: '" << e.what() << "'\n";
222-
}
223-
}
224-
225214
int main(int argc, const char **argv) {
226215
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
227216
std::error_code OK;
@@ -246,9 +235,14 @@ Example usage for a project using a compile commands database:
246235
return 1;
247236
}
248237

238+
// turns on ftime trace profiling
239+
if (FTimeTrace)
240+
llvm::timeTraceProfilerInitialize(200, "clang-doc");
241+
242+
llvm::TimeTraceScope("main");
243+
249244
// Fail early if an invalid format was provided.
250245
std::string Format = getFormatString();
251-
llvm::outs() << "Unoptimized\n";
252246
llvm::outs() << "Emiting docs in " << Format << " format.\n";
253247
auto G = doc::findGeneratorByName(Format);
254248
if (!G) {
@@ -270,8 +264,8 @@ Example usage for a project using a compile commands database:
270264
OutDirectory,
271265
SourceRoot,
272266
RepositoryUrl,
273-
{UserStylesheets.begin(), UserStylesheets.end()}
274-
};
267+
{UserStylesheets.begin(), UserStylesheets.end()},
268+
FTimeTrace};
275269

276270
if (Format == "html") {
277271
if (auto Err = getHtmlAssetFiles(argv[0], CDCtx)) {
@@ -280,6 +274,7 @@ Example usage for a project using a compile commands database:
280274
}
281275
}
282276

277+
llvm::timeTraceProfilerBegin("Mapping declaration", "total runtime");
283278
// Mapping phase
284279
llvm::outs() << "Mapping decls...\n";
285280
auto Err =
@@ -294,24 +289,28 @@ Example usage for a project using a compile commands database:
294289
return 1;
295290
}
296291
}
292+
llvm::timeTraceProfilerEnd();
297293

298294
// Collect values into output by key.
299295
// In ToolResults, the Key is the hashed USR and the value is the
300296
// bitcode-encoded representation of the Info object.
297+
llvm::timeTraceProfilerBegin("Collect Info", "total runtime");
301298
llvm::outs() << "Collecting infos...\n";
302299
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
303300
Executor->get()->getToolResults()->forEachResult(
304301
[&](StringRef Key, StringRef Value) {
305302
auto R = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
306303
R.first->second.emplace_back(Value);
307304
});
305+
llvm::timeTraceProfilerEnd();
308306

309307
// Collects all Infos according to their unique USR value. This map is added
310308
// to from the thread pool below and is protected by the USRToInfoMutex.
311309
llvm::sys::Mutex USRToInfoMutex;
312310
llvm::StringMap<std::unique_ptr<doc::Info>> USRToInfo;
313311

314312
// First reducing phase (reduce all decls into one info per decl).
313+
llvm::timeTraceProfilerBegin("Reducing infos", "total runtime");
315314
llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
316315
std::atomic<bool> Error;
317316
Error = false;
@@ -320,50 +319,57 @@ Example usage for a project using a compile commands database:
320319
llvm::DefaultThreadPool Pool(llvm::hardware_concurrency(ExecutorConcurrency));
321320
for (auto &Group : USRToBitcode) {
322321
Pool.async([&]() {
323-
try {
324-
std::vector<std::unique_ptr<doc::Info>> Infos;
325-
for (auto &Bitcode : Group.getValue()) {
326-
llvm::BitstreamCursor Stream(Bitcode);
327-
doc::ClangDocBitcodeReader Reader(Stream);
328-
auto ReadInfos = Reader.readBitcode();
329-
if (!ReadInfos) {
330-
llvm::errs() << toString(ReadInfos.takeError()) << "\n";
331-
Error = true;
332-
return;
333-
}
334-
std::move(ReadInfos->begin(), ReadInfos->end(),
335-
std::back_inserter(Infos));
336-
}
337-
338-
auto Reduced = doc::mergeInfos(Infos);
339-
if (!Reduced) {
340-
llvm::errs() << llvm::toString(Reduced.takeError());
322+
if (FTimeTrace)
323+
llvm::timeTraceProfilerInitialize(200, "clang-doc");
324+
325+
llvm::timeTraceProfilerBegin("Reducing infos", "decoding bitcode");
326+
std::vector<std::unique_ptr<doc::Info>> Infos;
327+
for (auto &Bitcode : Group.getValue()) {
328+
llvm::BitstreamCursor Stream(Bitcode);
329+
doc::ClangDocBitcodeReader Reader(Stream);
330+
auto ReadInfos = Reader.readBitcode();
331+
if (!ReadInfos) {
332+
llvm::errs() << toString(ReadInfos.takeError()) << "\n";
333+
Error = true;
341334
return;
342335
}
336+
std::move(ReadInfos->begin(), ReadInfos->end(),
337+
std::back_inserter(Infos));
338+
}
339+
llvm::timeTraceProfilerEnd();
343340

344-
// Add a reference to this Info in the Index
345-
{
346-
std::lock_guard<llvm::sys::Mutex> Guard(IndexMutex);
347-
clang::doc::Generator::addInfoToIndex(CDCtx.Idx, Reduced.get().get());
348-
}
341+
llvm::timeTraceProfilerBegin("Reducing infos", "merging bitcode");
342+
auto Reduced = doc::mergeInfos(Infos);
343+
if (!Reduced) {
344+
llvm::errs() << llvm::toString(Reduced.takeError());
345+
return;
346+
}
347+
llvm::timeTraceProfilerEnd();
349348

350-
// Save in the result map (needs a lock due to threaded access).
351-
{
352-
std::lock_guard<llvm::sys::Mutex> Guard(USRToInfoMutex);
353-
USRToInfo[Group.getKey()] = std::move(Reduced.get());
354-
}
355-
} catch (...) {
356-
std::exception_ptr P = std::current_exception();
357-
handle_eptr(P);
349+
// Add a reference to this Info in the Index
350+
{
351+
std::lock_guard<llvm::sys::Mutex> Guard(IndexMutex);
352+
clang::doc::Generator::addInfoToIndex(CDCtx.Idx, Reduced.get().get());
353+
}
354+
// Save in the result map (needs a lock due to threaded access).
355+
356+
{
357+
std::lock_guard<llvm::sys::Mutex> Guard(USRToInfoMutex);
358+
USRToInfo[Group.getKey()] = std::move(Reduced.get());
358359
}
360+
361+
if (CDCtx.FTimeTrace)
362+
llvm::timeTraceProfilerFinishThread();
359363
});
360364
}
365+
llvm::timeTraceProfilerEnd();
361366

362367
Pool.wait();
363368

364369
if (Error)
365370
return 1;
366371

372+
llvm::timeTraceProfilerBegin("Writing output", "total runtime");
367373
// Ensure the root output directory exists.
368374
if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory);
369375
Err != std::error_code()) {
@@ -384,6 +390,16 @@ Example usage for a project using a compile commands database:
384390
if (Err) {
385391
llvm::outs() << "warning: " << toString(std::move(Err)) << "\n";
386392
}
387-
393+
llvm::timeTraceProfilerEnd();
394+
395+
if (FTimeTrace) {
396+
std::error_code EC;
397+
llvm::raw_fd_ostream OS("clang-doc-tracing.json", EC,
398+
llvm::sys::fs::OF_Text);
399+
if (!EC)
400+
llvm::timeTraceProfilerWrite(OS);
401+
else
402+
return 1;
403+
}
388404
return 0;
389405
}

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,10 @@ def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, Group<f_Group
32323232
Visibility<[ClangOption, CC1Option, CLOption]>,
32333233
HelpText<"Implicitly search the file system for module map files.">,
32343234
MarshallingInfoFlag<HeaderSearchOpts<"ImplicitModuleMaps">>;
3235+
defm modulemap_allow_subdirectory_search : BoolFOption <"modulemap-allow-subdirectory-search",
3236+
HeaderSearchOpts<"AllowModuleMapSubdirectorySearch">, DefaultTrue,
3237+
PosFlag<SetTrue, [], [], "Allow to search for module maps in subdirectories of search paths">,
3238+
NegFlag<SetFalse>, BothFlags<[NoXarchOption], [ClangOption, CC1Option]>>;
32353239
defm modules : BoolFOption<"modules",
32363240
LangOpts<"Modules">, Default<fcxx_modules.KeyPath>,
32373241
PosFlag<SetTrue, [], [ClangOption, CC1Option],

clang/include/clang/Lex/HeaderSearchOptions.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ class HeaderSearchOptions {
270270
LLVM_PREFERRED_TYPE(bool)
271271
unsigned ModulesIncludeVFSUsage : 1;
272272

273+
/// Whether we should look for a module in module maps only in provided
274+
/// header search paths or if we are allowed to look for module maps in
275+
/// subdirectories of provided paths too.
276+
LLVM_PREFERRED_TYPE(bool)
277+
unsigned AllowModuleMapSubdirectorySearch : 1;
278+
273279
HeaderSearchOptions(StringRef _Sysroot = "/")
274280
: Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
275281
ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
@@ -285,7 +291,8 @@ class HeaderSearchOptions {
285291
ModulesSkipHeaderSearchPaths(false),
286292
ModulesSkipPragmaDiagnosticMappings(false),
287293
ModulesPruneNonAffectingModuleMaps(true), ModulesHashContent(false),
288-
ModulesStrictContextHash(false), ModulesIncludeVFSUsage(false) {}
294+
ModulesStrictContextHash(false), ModulesIncludeVFSUsage(false),
295+
AllowModuleMapSubdirectorySearch(true) {}
289296

290297
/// AddPath - Add the \p Path path to the specified \p Group list.
291298
void AddPath(StringRef Path, frontend::IncludeDirGroup Group,

0 commit comments

Comments
 (0)