Skip to content

Commit a98c539

Browse files
committed
[cxxmodules] Make the global module index opt-in.
By setting the ROOT_EXPERIMENTAL_GMI env variable. This is useful for comparing performance results from both implementations. ROOT_EXPERIMENTAL_GMI is temporary and will go away as soon as we switch to the GMI by default.
1 parent ab2bbbd commit a98c539

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

core/metacling/src/TCling.cxx

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,10 @@ static bool LoadModule(const std::string &ModuleName, cling::Interpreter &interp
10571057
std::string currentDir = gSystem->WorkingDirectory();
10581058
assert(!currentDir.empty());
10591059
gCling->RegisterPrebuiltModulePath(currentDir);
1060+
if (gDebug > 2)
1061+
::Info("TCling::__LoadModule", "Preloading module %s. \n",
1062+
ModuleName.c_str());
1063+
10601064
return interp.loadModule(ModuleName, /*Complain=*/true);
10611065
}
10621066

@@ -1132,7 +1136,7 @@ static GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc, cling
11321136
return GlobalIndex;
11331137
}
11341138

1135-
static void RegisterCommonCxxModules(cling::Interpreter &clingInterp)
1139+
static void RegisterCxxModules(cling::Interpreter &clingInterp)
11361140
{
11371141
if (!clingInterp.getCI()->getLangOpts().Modules)
11381142
return;
@@ -1160,8 +1164,8 @@ static void RegisterCommonCxxModules(cling::Interpreter &clingInterp)
11601164
LoadModules(CoreModules, clingInterp);
11611165

11621166
// FIXME: Reducing those will let us be less dependent on rootmap files
1163-
// static constexpr std::array<const char *, 3> ExcludeModules = {
1164-
// {"Rtools", "RSQLite", "RInterface"}};
1167+
static constexpr std::array<const char *, 3> ExcludeModules = {
1168+
{"Rtools", "RSQLite", "RInterface"}};
11651169

11661170
// Take this branch only from ROOT because we don't need to preload modules in rootcling
11671171
if (!IsFromRootCling()) {
@@ -1175,35 +1179,55 @@ static void RegisterCommonCxxModules(cling::Interpreter &clingInterp)
11751179
"Proof", "Geom"};
11761180
LoadModules(FIXMEModules, clingInterp);
11771181

1178-
loadGlobalModuleIndex(SourceLocation(), clingInterp);
11791182
clang::CompilerInstance &CI = *clingInterp.getCI();
1180-
if (GlobalModuleIndex *GlobalIndex = CI.getModuleManager()->getGlobalIndex()) {
1181-
llvm::StringSet<> KnownModuleFileNames;
1183+
GlobalModuleIndex *GlobalIndex = nullptr;
1184+
if (gSystem->Getenv("ROOT_EXPERIMENTAL_GMI")) {
1185+
loadGlobalModuleIndex(SourceLocation(), clingInterp);
1186+
GlobalIndex = CI.getModuleManager()->getGlobalIndex();
1187+
}
1188+
llvm::StringSet<> KnownModuleFileNames;
1189+
if (GlobalIndex)
11821190
GlobalIndex->getKnownModuleFileNames(KnownModuleFileNames);
11831191

1184-
clang::Preprocessor &PP = CI.getPreprocessor();
1185-
ModuleMap &MMap = PP.getHeaderSearchInfo().getModuleMap();
1186-
for (auto I = MMap.module_begin(), E = MMap.module_end(); I != E; ++I) {
1187-
clang::Module *M = I->second;
1188-
assert(M);
1192+
clang::Preprocessor &PP = CI.getPreprocessor();
1193+
std::vector<std::string> PendingModules;
1194+
PendingModules.reserve(256);
1195+
ModuleMap &MMap = PP.getHeaderSearchInfo().getModuleMap();
1196+
for (auto I = MMap.module_begin(), E = MMap.module_end(); I != E; ++I) {
1197+
clang::Module *M = I->second;
1198+
assert(M);
11891199

1190-
// We want to load only already created modules.
1191-
std::string FullASTFilePath;
1192-
if (!HasASTFileOnDisk(M, PP, &FullASTFilePath))
1193-
continue;
1200+
// We want to load only already created modules.
1201+
std::string FullASTFilePath;
1202+
if (!HasASTFileOnDisk(M, PP, &FullASTFilePath))
1203+
continue;
11941204

1195-
if (KnownModuleFileNames.count(FullASTFilePath))
1196-
continue;
1205+
if (GlobalIndex && KnownModuleFileNames.count(FullASTFilePath))
1206+
continue;
11971207

1198-
if (!M->IsMissingRequirement) {
1199-
if (gDebug > 2)
1200-
::Info("TCling::__RegisterCommonCxxModules", "Preloading %s because it is not in GMI. \n",
1201-
M->Name.data());
1208+
if (M->IsMissingRequirement)
1209+
continue;
1210+
1211+
if (GlobalIndex)
1212+
LoadModule(M->Name, clingInterp);
1213+
else {
1214+
// FIXME: We may be able to remove those checks as cling::loadModule
1215+
// checks if a module was alredy loaded.
1216+
if (std::find(CoreModules.begin(), CoreModules.end(), M->Name) != CoreModules.end())
1217+
continue; // This is a core module which was already loaded.
12021218

1219+
if (std::find(ExcludeModules.begin(), ExcludeModules.end(), M->Name) != ExcludeModules.end())
1220+
continue;
1221+
1222+
// Load system modules now and delay the other modules after we have
1223+
// loaded all system ones.
1224+
if (M->IsSystem)
12031225
LoadModule(M->Name, clingInterp);
1204-
}
1226+
else
1227+
PendingModules.push_back(M->Name);
12051228
}
12061229
}
1230+
LoadModules(PendingModules, clingInterp);
12071231
}
12081232

12091233
// Check that the gROOT macro was exported by any core module.
@@ -1464,7 +1488,7 @@ TCling::TCling(const char *name, const char *title, const char* const argv[])
14641488
static llvm::raw_fd_ostream fMPOuts (STDOUT_FILENO, /*ShouldClose*/false);
14651489
fMetaProcessor = llvm::make_unique<cling::MetaProcessor>(*fInterpreter, fMPOuts);
14661490

1467-
RegisterCommonCxxModules(*fInterpreter);
1491+
RegisterCxxModules(*fInterpreter);
14681492
RegisterPreIncludedHeaders(*fInterpreter);
14691493

14701494
// We are now ready (enough is loaded) to init the list of opaque typedefs.

0 commit comments

Comments
 (0)