Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e400230
WIP: CAS: Add Namespace and start threading through
dexonsmith Nov 2, 2021
d71e6f9
WIP: Start adding tests for Namespace and UniqueID
dexonsmith Dec 14, 2021
87d172b
WIP: Finish testing UniqueID / Namespace / FlatUniqueIDArrayRef
dexonsmith Dec 14, 2021
9055169
Test the DenseMap info
dexonsmith Dec 15, 2021
3efc3a5
CAS: Start sketching out ActionCache
dexonsmith Dec 17, 2021
abc7871
WIP: start implementing in-memory action cache
dexonsmith Dec 17, 2021
1cb2ec1
WIP: Mostly finish in-memory, and start on-disk action cache
dexonsmith Dec 18, 2021
3dd4122
WIP: Mostly finish on-disk action cache
dexonsmith Dec 20, 2021
47727b1
Update header docs
dexonsmith Dec 20, 2021
f8a7f42
WIP: Get most of LLVMCAS compiling
dexonsmith Dec 20, 2021
5900137
WIP: LLVMCAS and CASTests compile
dexonsmith Dec 21, 2021
c7f4be1
fixup: temporarily revert readNativeFileToLimit to split out and test it
dexonsmith Dec 21, 2021
1a231ad
Support: Add sys::fs::readNativeFileToLimit()
dexonsmith Dec 21, 2021
245f8d8
Test ActionDescription
dexonsmith Dec 21, 2021
1970a6e
Test ActionCache
dexonsmith Dec 21, 2021
9aaf46c
add missing final
dexonsmith Dec 21, 2021
4859af2
WIP: Remove result cache support from CASDB
dexonsmith Dec 21, 2021
6df65af
TableGen: Convert to new ActionCache APIs
dexonsmith Dec 21, 2021
1cecc05
CAS: Factor out unnecessary calls to getCASID()
dexonsmith Dec 21, 2021
c830d92
BuiltinCAS: Push UniqueIDRef through a bit further
dexonsmith Dec 21, 2021
34c2a68
WIP: Maybe add conversions to UniqueIDRef?
dexonsmith Dec 22, 2021
4b1f6ee
Handle most of the complications for CompilerInvocation
dexonsmith Dec 23, 2021
5618305
Fix clang build
cachemeifyoucan Jan 5, 2022
a5e35d6
[CASDB] Fix a lifetime issue of `parseCASID`
cachemeifyoucan Jan 6, 2022
3c34d2a
Revert "[CASDB] Fix a lifetime issue of `parseCASID`"
dexonsmith Jan 21, 2022
3d94e5c
CAS: Fix lifetime issue in CASDB::parseCASID
dexonsmith Jan 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions clang/include/clang/Basic/CASOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,74 @@
#ifndef LLVM_CLANG_BASIC_CASOPTIONS_H
#define LLVM_CLANG_BASIC_CASOPTIONS_H

#include "llvm/ADT/AtomicSharedPtr.h"
#include <string>
#include <vector>

namespace llvm {
namespace cas {

class ActionCache;
class CASDB;
class Namespace;

} // end namespace cas
} // end namespace llvm

namespace clang {

/// Keeps track of options that affect how file operations are performed.
class DiagnosticsEngine;

/// Configures the CAS.
///
/// FIXME: Currently includes any option slightly related to the CAS, but
/// options that affect compilation should be moved out. This should only
/// be configuring:
///
/// - What CAS is being used?
/// - What ActionCache is being used?
///
/// It should not affect *how* the CAS or action cache are being used, just
/// where to find them / how to connect to them / etc..
class CASOptions {
public:
enum CASKind {
NoCAS, // FIXME: Should we delete this, and always use a CAS?
InMemoryCAS,
BuiltinCAS,
PluginCAS,
};

CASKind Kind = NoCAS; // FIXME: Should this be \a InMemoryCAS?
CASKind Kind = BuiltinCAS;

/// If set, path to an on-disk action cache.
std::string ActionCachePath;

/// If set, uses this root ID with \a CASFileSystem.
///
/// FIXME: Move to \a FileSystemOptions.
std::string CASFileSystemRootID;

/// If set, used as the working directory for -fcas-fs.
///
/// FIXME: Move to \a FileSystemOptions.
std::string CASFileSystemWorkingDirectory;

/// Use a result cache when possible, using CASFileSystemRootID.
///
/// FIXME: Move to \a FrontendOptions.
/// FIXME: Rename to "-fcached-cc1" or something. While it depends on
/// "-fcas-fs" it's not strongly related.
bool CASFileSystemResultCache = false;

/// Transparently enable pre-tokenized files with -fcas.
///
/// FIXME: Move to \a PreprocessorOptions.
/// FIXME: Rename to "-fpretokenize" (or something), reflecting the semantic
/// change rather than whether things are being cached.
bool CASTokenCache = false;

/// When using -fcas-fs-result-cache, write a CASID for the output file.
///
/// FIXME: Move to \a CodeGenOptions.
/// FIXME: Add clang tests for this functionality.
bool WriteOutputAsCASID = false;

Expand All @@ -56,6 +94,15 @@ class CASOptions {

/// For \a PluginCAS, the arguments to initialize the plugin.
std::vector<std::string> PluginArgs;

std::shared_ptr<llvm::cas::CASDB>
getOrCreateCAS(DiagnosticsEngine &Diags) const;
std::shared_ptr<llvm::cas::ActionCache>
getOrCreateActionCache(const llvm::cas::Namespace &NS,
DiagnosticsEngine &Diags) const;

mutable llvm::AtomicSharedPtr<llvm::cas::CASDB> CachedCAS;
mutable llvm::AtomicSharedPtr<llvm::cas::ActionCache> CachedActionCache;
};

} // end namespace clang
Expand Down
7 changes: 4 additions & 3 deletions clang/include/clang/Basic/DiagnosticCASKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ let Component = "CAS" in {
def err_cas_plugin_cannot_be_loaded : Error<
"CAS plugin '%0' cannot be loaded (check -fcas-plugin-path and"
" -fcas-plugin-args)">, DefaultFatal;
def err_builtin_cas_cannot_be_initialized : Error<
"Builtin CAS cannot be initialized from '%0' on disk"
" (check -fcas-builtin-path)">, DefaultFatal;
def err_cannot_initialize_action_cache : Error<
"cannot initialize action cache: %0">, DefaultFatal;
def err_cannot_initialize_builtin_cas : Error<
"cannot initialize builtin CAS: %0">, DefaultFatal;
def err_cas_builtin_path : Error<
"Builtin CAS cannot be initialized from '%0' on disk"
" (check -fcas-builtin-path)">, DefaultFatal;
Expand Down
14 changes: 9 additions & 5 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5926,11 +5926,11 @@ def dump_depscan_tree_EQ : Option<["-"], "dump-depscan-tree=", KIND_JOINED>,
let Flags = [CC1Option, NoDriverOption] in {

def fcas : Separate<["-"], "fcas">,
Group<f_Group>, MetaVarName<"<none|builtin|plugin>">,
Group<f_Group>, MetaVarName<"<builtin|plugin>">,
HelpText<"Kind of CAS to use during compilation.">,
Values<"none,builtin,plugin">, NormalizedValuesScope<"CASOptions">,
NormalizedValues<["NoCAS", "BuiltinCAS", "PluginCAS"]>,
MarshallingInfoEnum<CASOpts<"Kind">, "NoCAS">;
Values<"builtin,plugin">, NormalizedValuesScope<"CASOptions">,
NormalizedValues<["BuiltinCAS", "PluginCAS"]>,
MarshallingInfoEnum<CASOpts<"Kind">, "BuiltinCAS">;

def fcas_builtin_path : Separate<["-"], "fcas-builtin-path">,
Group<f_Group>, MetaVarName<"<dir>">,
Expand All @@ -5950,10 +5950,14 @@ def fcas_plugin_arg : Joined<["-"], "fcas-plugin-arg">,
ShouldParseIf<!strconcat(fcas.KeyPath," == CASOptions::PluginCAS")>,
MarshallingInfoStringVector<CASOpts<"PluginArgs">>;

def fcas_action_cache : Separate<["-"], "faction-cache">,
Group<f_Group>, MetaVarName<"<dir>">,
HelpText<"An on-disk action cache to use with the CAS.">,
MarshallingInfoString<CASOpts<"ActionCachePath">>;

def fcas_fs : Separate<["-"], "fcas-fs">,
Group<f_Group>, MetaVarName<"<tree>">,
HelpText<"Configure the filesystem to read from the provided CAS tree.">,
ShouldParseIf<!strconcat(fcas.KeyPath, " != CASOptions::NoCAS")>,
MarshallingInfoString<CASOpts<"CASFileSystemRootID">>;

def fcas_fs_working_directory : Separate<["-"], "fcas-fs-working-directory">,
Expand Down
17 changes: 17 additions & 0 deletions clang/include/clang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace llvm {
class raw_fd_ostream;
class Timer;
class TimerGroup;

namespace cas {
class CASDB;
class ActionCache;
} // end namespace cas
}

namespace clang {
Expand Down Expand Up @@ -76,6 +81,9 @@ class CompilerInstance : public ModuleLoader {
/// The options used in this compiler instance.
std::shared_ptr<CompilerInvocation> Invocation;

std::shared_ptr<llvm::cas::CASDB> CAS;
std::shared_ptr<llvm::cas::ActionCache> ActionCache;

/// The diagnostics engine instance.
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;

Expand Down Expand Up @@ -233,6 +241,15 @@ class CompilerInstance : public ModuleLoader {
BuildGlobalModuleIndex = Build;
}

llvm::cas::CASDB &getCAS() const { return *CAS; }
llvm::cas::CASDB &getOrCreateCAS();
std::shared_ptr<llvm::cas::CASDB> getCASPtr() const { return CAS; }

llvm::cas::ActionCache &getOrCreateActionCache();
llvm::cas::ActionCache &getActionCache() const { return *ActionCache; }
std::shared_ptr<llvm::cas::ActionCache> getActionCachePtr() const {
return ActionCache;
}
/// }
/// @name Forwarding Methods
/// {
Expand Down
7 changes: 2 additions & 5 deletions clang/include/clang/Frontend/CompilerInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class FileSystem;

namespace cas {

class ActionCache;
class CASDB;

class Namespace;
}

} // namespace llvm
Expand Down Expand Up @@ -342,10 +343,6 @@ IntrusiveRefCntPtr<llvm::vfs::FileSystem> createVFSFromCompilerInvocation(
const CompilerInvocation &CI, DiagnosticsEngine &Diags,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS);

std::shared_ptr<llvm::cas::CASDB>
createCASFromCompilerInvocation(const CompilerInvocation &CI,
DiagnosticsEngine &Diags);

} // namespace clang

#endif // LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
17 changes: 11 additions & 6 deletions clang/include/clang/Lex/PTHManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace llvm {

class MemoryBuffer;

namespace cas {
class ActionCache;
} // end namespace cas

} // namespace llvm

namespace clang {
Expand Down Expand Up @@ -96,18 +100,18 @@ class PTHManager {
llvm::SpecificBumpPtrAllocator<IdentifierInfo *> IdentifierInfoCacheAlloc;

llvm::cas::CASDB &CAS;
llvm::cas::ActionCache &Cache;
IntrusiveRefCntPtr<llvm::cas::CASFileSystemBase> FS;
LangOptions CanonicalLangOpts;
Optional<llvm::cas::CASID> SerializedLangOpts;
Optional<llvm::cas::CASID> ClangVersion;
Optional<llvm::cas::CASID> Operation;
Optional<llvm::cas::UniqueIDRef> SerializedLangOpts;
Optional<llvm::cas::UniqueIDRef> ClangVersion;

/// PP - The Preprocessor object that will use this PTHManager to create
/// PTHLexer objects.
Preprocessor *PP = nullptr;

PTHHandler *createHandler(StringRef Filename, llvm::cas::CASID PTH);
Expected<llvm::cas::CASID> computePTH(llvm::cas::CASID InputFile);
PTHHandler *createHandler(StringRef Filename, StringRef PTH);
Expected<StringRef> computePTH(llvm::cas::CASID InputFile);

public:
// The current PTH version.
Expand All @@ -118,7 +122,8 @@ class PTHManager {
~PTHManager();
PTHManager() = delete;

PTHManager(IntrusiveRefCntPtr<llvm::cas::CASFileSystemBase> FS,
PTHManager(llvm::cas::ActionCache &Cache,
IntrusiveRefCntPtr<llvm::cas::CASFileSystemBase> FS,
Preprocessor &PP);

void setPreprocessor(Preprocessor *pp) { PP = pp; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace llvm {
namespace cas {
class CachingOnDiskFileSystem;
class ActionCache;
} // namespace cas
} // namespace llvm

Expand All @@ -42,6 +43,7 @@ namespace dependencies {
class DependencyScanningWorkerFilesystem : public llvm::cas::CASFileSystemBase {
public:
DependencyScanningWorkerFilesystem(
llvm::cas::ActionCache &ActionCache,
IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> WorkerFS,
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings);

Expand Down Expand Up @@ -101,11 +103,11 @@ class DependencyScanningWorkerFilesystem : public llvm::cas::CASFileSystemBase {
};
Expected<StringRef>
computeMinimized(llvm::cas::CASID InputDataID, StringRef Identifier,
Optional<llvm::cas::CASID> &MinimizedDataID);
Optional<llvm::cas::UniqueIDRef> &MinimizedDataID);

Expected<StringRef> getMinimized(llvm::cas::CASID OutputID,
StringRef Identifier,
Optional<llvm::cas::CASID> &MinimizedDataID);
Expected<StringRef>
getMinimized(llvm::cas::UniqueIDRef OutputID, StringRef Identifier,
Optional<llvm::cas::UniqueIDRef> &MinimizedDataID);

Expected<StringRef> getOriginal(llvm::cas::CASID InputDataID);

Expand All @@ -114,6 +116,7 @@ class DependencyScanningWorkerFilesystem : public llvm::cas::CASFileSystemBase {
llvm::cas::CachingOnDiskFileSystem &getCachingFS();

llvm::cas::CASDB &CAS;
llvm::cas::ActionCache &Cache;
Optional<llvm::cas::CASID> ClangFullVersionID;
Optional<llvm::cas::CASID> MinimizeID;
Optional<llvm::cas::CASID> EmptyBlobID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_SERVICE_H

#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
#include "llvm/CAS/ActionCache.h"

namespace clang {
namespace tooling {
Expand Down Expand Up @@ -52,8 +53,8 @@ class DependencyScanningService {
DependencyScanningService(
ScanningMode Mode, ScanningOutputFormat Format,
IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> SharedFS,
bool ReuseFileManager = true, bool SkipExcludedPPRanges = true,
bool OverrideCASTokenCache = false);
llvm::cas::ActionCache &Cache, bool ReuseFileManager = true,
bool SkipExcludedPPRanges = true, bool OverrideCASTokenCache = false);

~DependencyScanningService();

Expand All @@ -69,6 +70,8 @@ class DependencyScanningService {

llvm::cas::CachingOnDiskFileSystem &getSharedFS() { return *SharedFS; }

llvm::cas::ActionCache &getActionCache() { return Cache; }

private:
const ScanningMode Mode;
const ScanningOutputFormat Format;
Expand All @@ -80,6 +83,7 @@ class DependencyScanningService {
const bool OverrideCASTokenCache;
/// The global file system cache.
IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> SharedFS;
llvm::cas::ActionCache &Cache;
};

} // end namespace dependencies
Expand Down
Loading