class PrecompiledPreamble

Declaration

class PrecompiledPreamble { /* full declaration omitted */ };

Description

A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subsequent runs. Use BuildPreamble to create PCH and CanReusePreamble + AddImplicitPreamble to make use of it.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:51

Member Variables

private std::unique_ptr<PCHStorage> Storage
Manages the memory buffer or temporary file that stores the PCH.
private llvm::StringMap<PreambleFileHash> FilesInPreamble
If any of the files have changed from one compile to the next, the preamble must be thrown away.
private llvm::StringSet<> MissingFiles
Storing *all* the missing files that could invalidate the preamble would make it too expensive to revalidate (when the include path has many entries, each #include will miss half of them on average). Instead, we track only files that could have satisfied an #include that was ultimately not found.
private std::vector<char> PreambleBytes
The contents of the file that was used to precompile the preamble. Only contains first PreambleBounds::Size bytes. Used to compare if the relevant part of the file has not changed, so that preamble can be reused.
private bool PreambleEndsAtStartOfLine
See PreambleBounds::PreambleEndsAtStartOfLine

Method Overview

  • public void AddImplicitPreamble(clang::CompilerInvocation & CI, IntrusiveRefCntPtr<llvm::vfs::FileSystem> & VFS, llvm::MemoryBuffer * MainFileBuffer) const
  • public static llvm::ErrorOr<PrecompiledPreamble> Build(const clang::CompilerInvocation & Invocation, const llvm::MemoryBuffer * MainFileBuffer, clang::PreambleBounds Bounds, clang::DiagnosticsEngine & Diagnostics, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, std::shared_ptr<PCHContainerOperations> PCHContainerOps, bool StoreInMemory, clang::PreambleCallbacks & Callbacks)
  • public bool CanReuse(const clang::CompilerInvocation & Invocation, const llvm::MemoryBufferRef & MainFileBuffer, clang::PreambleBounds Bounds, llvm::vfs::FileSystem & VFS) const
  • public void OverridePreamble(clang::CompilerInvocation & CI, IntrusiveRefCntPtr<llvm::vfs::FileSystem> & VFS, llvm::MemoryBuffer * MainFileBuffer) const
  • public PrecompiledPreamble(clang::PrecompiledPreamble &&)
  • private PrecompiledPreamble(std::unique_ptr<PCHStorage> Storage, std::vector<char> PreambleBytes, bool PreambleEndsAtStartOfLine, llvm::StringMap<PreambleFileHash> FilesInPreamble, llvm::StringSet<> MissingFiles)
  • private void configurePreamble(clang::PreambleBounds Bounds, clang::CompilerInvocation & CI, IntrusiveRefCntPtr<llvm::vfs::FileSystem> & VFS, llvm::MemoryBuffer * MainFileBuffer) const
  • public clang::PreambleBounds getBounds() const
  • public llvm::StringRef getContents() const
  • public std::size_t getSize() const
  • private static void setupPreambleStorage(const clang::PrecompiledPreamble::PCHStorage & Storage, clang::PreprocessorOptions & PreprocessorOpts, IntrusiveRefCntPtr<llvm::vfs::FileSystem> & VFS)
  • public ~PrecompiledPreamble()

Methods

void AddImplicitPreamble(
    clang::CompilerInvocation& CI,
    IntrusiveRefCntPtr<llvm::vfs::FileSystem>&
        VFS,
    llvm::MemoryBuffer* MainFileBuffer) const

Description

Changes options inside \p CI to use PCH from this preamble. Also remaps main file to \p MainFileBuffer and updates \p VFS to ensure the preamble is accessible. Requires that CanReuse() is true. For in-memory preambles, PrecompiledPreamble instance continues to own the MemoryBuffer with the Preamble after this method returns. The caller is responsible for making sure the PrecompiledPreamble instance outlives the compiler run and the AST that will be using the PCH.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:119

Parameters

clang::CompilerInvocation& CI
IntrusiveRefCntPtr<llvm::vfs::FileSystem>& VFS
llvm::MemoryBuffer* MainFileBuffer

static llvm::ErrorOr<PrecompiledPreamble> Build(
    const clang::CompilerInvocation& Invocation,
    const llvm::MemoryBuffer* MainFileBuffer,
    clang::PreambleBounds Bounds,
    clang::DiagnosticsEngine& Diagnostics,
    IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
    std::shared_ptr<PCHContainerOperations>
        PCHContainerOps,
    bool StoreInMemory,
    clang::PreambleCallbacks& Callbacks)

Description

Try to build PrecompiledPreamble for \p Invocation. See BuildPreambleError for possible error codes.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:81

Parameters

const clang::CompilerInvocation& Invocation
Original CompilerInvocation with options to compile the file.
const llvm::MemoryBuffer* MainFileBuffer
Buffer with the contents of the main file.
clang::PreambleBounds Bounds
Bounds of the preamble, result of calling ComputePreambleBounds.
clang::DiagnosticsEngine& Diagnostics
Diagnostics engine to be used while building the preamble.
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS
An instance of vfs::FileSystem to be used for file accesses.
std::shared_ptr<PCHContainerOperations> PCHContainerOps
An instance of PCHContainerOperations.
bool StoreInMemory
Store PCH in memory. If false, PCH will be stored in a temporary file.
clang::PreambleCallbacks& Callbacks
A set of callbacks to be executed when building the preamble.

bool CanReuse(
    const clang::CompilerInvocation& Invocation,
    const llvm::MemoryBufferRef& MainFileBuffer,
    clang::PreambleBounds Bounds,
    llvm::vfs::FileSystem& VFS) const

Description

Check whether PrecompiledPreamble can be reused for the new contents(\p MainFileBuffer) of the main file.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:107

Parameters

const clang::CompilerInvocation& Invocation
const llvm::MemoryBufferRef& MainFileBuffer
clang::PreambleBounds Bounds
llvm::vfs::FileSystem& VFS

void OverridePreamble(
    clang::CompilerInvocation& CI,
    IntrusiveRefCntPtr<llvm::vfs::FileSystem>&
        VFS,
    llvm::MemoryBuffer* MainFileBuffer) const

Description

Configure \p CI to use this preamble. Like AddImplicitPreamble, but doesn't assume CanReuse() is true. If this preamble does not match the file, it may parse differently.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:126

Parameters

clang::CompilerInvocation& CI
IntrusiveRefCntPtr<llvm::vfs::FileSystem>& VFS
llvm::MemoryBuffer* MainFileBuffer

PrecompiledPreamble(clang::PrecompiledPreamble&&)

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:88

Parameters

clang::PrecompiledPreamble&&

PrecompiledPreamble(
    std::unique_ptr<PCHStorage> Storage,
    std::vector<char> PreambleBytes,
    bool PreambleEndsAtStartOfLine,
    llvm::StringMap<PreambleFileHash>
        FilesInPreamble,
    llvm::StringSet<> MissingFiles)

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:131

Parameters

std::unique_ptr<PCHStorage> Storage
std::vector<char> PreambleBytes
bool PreambleEndsAtStartOfLine
llvm::StringMap<PreambleFileHash> FilesInPreamble
llvm::StringSet<> MissingFiles

void configurePreamble(
    clang::PreambleBounds Bounds,
    clang::CompilerInvocation& CI,
    IntrusiveRefCntPtr<llvm::vfs::FileSystem>&
        VFS,
    llvm::MemoryBuffer* MainFileBuffer) const

Description

Helper function to set up PCH for the preamble into \p CI and \p VFS to with the specified \p Bounds.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:168

Parameters

clang::PreambleBounds Bounds
clang::CompilerInvocation& CI
IntrusiveRefCntPtr<llvm::vfs::FileSystem>& VFS
llvm::MemoryBuffer* MainFileBuffer

clang::PreambleBounds getBounds() const

Description

PreambleBounds used to build the preamble.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:93

llvm::StringRef getContents() const

Description

Returned string is not null-terminated.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:101

std::size_t getSize() const

Description

Returns the size, in bytes, that preamble takes on disk or in memory. For on-disk preambles returns 0 if filesystem operations fail. Intended to be used for logging and debugging purposes only.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:98

static void setupPreambleStorage(
    const clang::PrecompiledPreamble::PCHStorage&
        Storage,
    clang::PreprocessorOptions& PreprocessorOpts,
    IntrusiveRefCntPtr<llvm::vfs::FileSystem>&
        VFS)

Description

Sets up the PreprocessorOptions and changes VFS, so that PCH stored in \p Storage is accessible to clang. This method is an implementation detail of AddImplicitPreamble.

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:176

Parameters

const clang::PrecompiledPreamble::PCHStorage& Storage
clang::PreprocessorOptions& PreprocessorOpts
IntrusiveRefCntPtr<llvm::vfs::FileSystem>& VFS

~PrecompiledPreamble()

Declared at: clang/include/clang/Frontend/PrecompiledPreamble.h:90