Store rdict files as module file extensions.

This patch moves the ROOT-specific rdict.pcm optimization in the EXTENSION_BLOCK
of a C++ module file.

This reduces the generated artifacts and simplifies the loading of a rdict pcm
file as it is now part of the C++ module file. This patch paves our way to
using the global module indexing.
This commit is contained in:
Vassil Vassilev 2019-05-24 10:41:17 +03:00 committed by SFT Nightlies
parent ddffe49bea
commit 74685d3725
6 changed files with 59 additions and 24 deletions

View File

@ -20,8 +20,9 @@ namespace llvm {
}
namespace clang {
class DiagnosticsEngine;
class ASTConsumer;
class DiagnosticsEngine;
class ModuleFileExtension;
}
namespace cling {
@ -29,16 +30,20 @@ namespace cling {
namespace CIFactory {
typedef std::unique_ptr<llvm::MemoryBuffer> MemBufPtr_t;
using ModuleFileExtensions =
std::vector<std::shared_ptr<clang::ModuleFileExtension>>;
// TODO: Add overload that takes file not MemoryBuffer
clang::CompilerInstance*
createCI(llvm::StringRef Code, const InvocationOptions& Opts,
const char* LLVMDir, std::unique_ptr<clang::ASTConsumer> consumer);
const char* LLVMDir, std::unique_ptr<clang::ASTConsumer> consumer,
const ModuleFileExtensions& moduleExtensions);
clang::CompilerInstance*
createCI(MemBufPtr_t Buffer, int Argc, const char* const* Argv,
const char* LLVMDir, std::unique_ptr<clang::ASTConsumer> consumer,
const ModuleFileExtensions& moduleExtensions,
bool OnlyLex = false);
} // namespace CIFactory
} // namespace cling

View File

@ -41,6 +41,7 @@ namespace clang {
class GlobalDecl;
class MacroInfo;
class Module;
class ModuleFileExtension;
class NamedDecl;
class Parser;
class Preprocessor;
@ -137,6 +138,10 @@ namespace cling {
kNumExeResults
};
public:
using ModuleFileExtensions =
std::vector<std::shared_ptr<clang::ModuleFileExtension>>;
private:
///\brief Interpreter invocation options.
@ -303,8 +308,8 @@ namespace cling {
///\brief The target constructor to be called from both the delegating
/// constructors. parentInterp might be nullptr.
///
Interpreter(int argc, const char* const *argv,
const char* llvmdir, bool noRuntime,
Interpreter(int argc, const char* const* argv, const char* llvmdir,
const ModuleFileExtensions& moduleExtensions, bool noRuntime,
const Interpreter* parentInterp);
public:
@ -315,9 +320,11 @@ namespace cling {
///\param[in] llvmdir - ???
///\param[in] noRuntime - flag to control the presence of runtime universe
///
Interpreter(int argc, const char* const *argv, const char* llvmdir = 0,
bool noRuntime = false) :
Interpreter(argc, argv, llvmdir, noRuntime, nullptr) { }
Interpreter(int argc, const char* const* argv, const char* llvmdir = 0,
const ModuleFileExtensions& moduleExtensions = {},
bool noRuntime = false)
: Interpreter(argc, argv, llvmdir, moduleExtensions, noRuntime,
nullptr) {}
///\brief Constructor for child Interpreter.
///\param[in] parentInterpreter - the parent interpreter of this interpreter
@ -326,8 +333,10 @@ namespace cling {
///\param[in] llvmdir - ???
///\param[in] noRuntime - flag to control the presence of runtime universe
///
Interpreter(const Interpreter &parentInterpreter,int argc, const char* const *argv,
const char* llvmdir = 0, bool noRuntime = true);
Interpreter(const Interpreter& parentInterpreter, int argc,
const char* const* argv, const char* llvmdir = 0,
const ModuleFileExtensions& moduleExtensions = {},
bool noRuntime = true);
virtual ~Interpreter();

View File

@ -780,8 +780,9 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
static CompilerInstance*
createCIImpl(std::unique_ptr<llvm::MemoryBuffer> Buffer,
const CompilerOptions& COpts, const char* LLVMDir,
std::unique_ptr<clang::ASTConsumer> customConsumer, bool OnlyLex,
bool HasInput = false) {
std::unique_ptr<clang::ASTConsumer> customConsumer,
const CIFactory::ModuleFileExtensions& moduleExtensions,
bool OnlyLex, bool HasInput = false) {
// Follow clang -v convention of printing version on first line
if (COpts.Verbose)
cling::log() << "cling version " << ClingStringify(CLING_VERSION) << '\n';
@ -1043,6 +1044,12 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
}
FrontendOptions& FrontendOpts = Invocation.getFrontendOpts();
// Register the externally constructed extensions.
assert(FrontendOpts.ModuleFileExtensions.empty() && "Extensions exist!");
for (auto& E : moduleExtensions)
FrontendOpts.ModuleFileExtensions.push_back(E);
FrontendOpts.DisableFree = true;
// With modules, we now start adding prebuilt module paths to the CI.
@ -1240,17 +1247,20 @@ namespace cling {
CompilerInstance*
CIFactory::createCI(llvm::StringRef Code, const InvocationOptions& Opts,
const char* LLVMDir,
std::unique_ptr<clang::ASTConsumer> consumer) {
std::unique_ptr<clang::ASTConsumer> consumer,
const ModuleFileExtensions& moduleExtensions) {
return createCIImpl(llvm::MemoryBuffer::getMemBuffer(Code), Opts.CompilerOpts,
LLVMDir, std::move(consumer), false /*OnlyLex*/,
LLVMDir, std::move(consumer), moduleExtensions,
false /*OnlyLex*/,
!Opts.IsInteractive());
}
CompilerInstance* CIFactory::createCI(
MemBufPtr_t Buffer, int argc, const char* const* argv, const char* LLVMDir,
std::unique_ptr<clang::ASTConsumer> consumer, bool OnlyLex) {
std::unique_ptr<clang::ASTConsumer> consumer,
const ModuleFileExtensions& moduleExtensions, bool OnlyLex /*false*/) {
return createCIImpl(std::move(Buffer), CompilerOptions(argc, argv), LLVMDir,
std::move(consumer), OnlyLex);
std::move(consumer), moduleExtensions, OnlyLex);
}
} // namespace cling

View File

@ -234,12 +234,13 @@ static void HandlePlugins(CompilerInstance& CI,
}
namespace cling {
IncrementalParser::IncrementalParser(Interpreter* interp, const char* llvmdir)
IncrementalParser::IncrementalParser(Interpreter* interp, const char* llvmdir,
const ModuleFileExtensions& moduleExtensions)
: m_Interpreter(interp) {
std::unique_ptr<cling::DeclCollector> consumer;
consumer.reset(m_Consumer = new cling::DeclCollector());
m_CI.reset(CIFactory::createCI("", interp->getOptions(), llvmdir,
std::move(consumer)));
std::move(consumer), moduleExtensions));
if (!m_CI) {
cling::errs() << "Compiler instance could not be created.\n";

View File

@ -33,6 +33,7 @@ namespace clang {
class DiagnosticConsumer;
class Decl;
class FileID;
class ModuleFileExtension;
class Parser;
}
@ -100,6 +101,9 @@ namespace cling {
///
std::unique_ptr<IncrementalCUDADeviceCompiler> m_CUDACompiler;
using ModuleFileExtensions =
std::vector<std::shared_ptr<clang::ModuleFileExtension>>;
public:
enum EParseResult {
kSuccess,
@ -108,7 +112,8 @@ namespace cling {
};
typedef llvm::PointerIntPair<Transaction*, 2, EParseResult>
ParseResultTransaction;
IncrementalParser(Interpreter* interp, const char* llvmdir);
IncrementalParser(Interpreter* interp, const char* llvmdir,
const ModuleFileExtensions& moduleExtensions);
~IncrementalParser();
///\brief Whether the IncrementalParser is valid.

View File

@ -217,8 +217,9 @@ namespace cling {
}
Interpreter::Interpreter(int argc, const char* const *argv,
const char* llvmdir /*= 0*/, bool noRuntime,
const Interpreter* parentInterp) :
const char* llvmdir /*= 0*/,
const ModuleFileExtensions& moduleExtensions,
bool noRuntime, const Interpreter* parentInterp) :
m_Opts(argc, argv),
m_UniqueCounter(parentInterp ? parentInterp->m_UniqueCounter + 1 : 0),
m_PrintDebug(false), m_DynamicLookupDeclared(false),
@ -230,7 +231,7 @@ namespace cling {
m_LLVMContext.reset(new llvm::LLVMContext);
m_DyLibManager.reset(new DynamicLibraryManager(getOptions()));
m_IncrParser.reset(new IncrementalParser(this, llvmdir));
m_IncrParser.reset(new IncrementalParser(this, llvmdir, moduleExtensions));
if (!m_IncrParser->isValid(false))
return;
@ -399,8 +400,11 @@ namespace cling {
///
Interpreter::Interpreter(const Interpreter &parentInterpreter, int argc,
const char* const *argv,
const char* llvmdir /*= 0*/, bool noRuntime) :
Interpreter(argc, argv, llvmdir, noRuntime, &parentInterpreter) {
const char* llvmdir /*= 0*/,
const ModuleFileExtensions& moduleExtensions/*={}*/,
bool noRuntime /*= true*/) :
Interpreter(argc, argv, llvmdir, moduleExtensions, noRuntime,
&parentInterpreter) {
// Do the "setup" of the connection between this interpreter and
// its parent interpreter.
if (CompilerInstance* CI = getCIOrNull()) {
@ -1674,7 +1678,8 @@ namespace cling {
// FIXME: CIFactory appends extra 3 folders to the llvmdir.
std::string llvmdir
= getCI()->getHeaderSearchOpts().ResourceDir + "/../../../";
cling::Interpreter fwdGen(1, &dummy, llvmdir.c_str(), true);
cling::Interpreter fwdGen(1, &dummy, llvmdir.c_str(),
/*moduleExtensions*/ {}, /*noRuntime=*/true);
// Copy the same header search options to the new instance.
Preprocessor& fwdGenPP = fwdGen.getCI()->getPreprocessor();