LLVM 22.0.0git
VirtualOutputBackends.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file contains the declarations of the concrete VirtualOutputBackend
11/// classes, which are the implementation for different output style and
12/// functions. This file contains:
13/// * NullOutputBackend: discard all outputs written.
14/// * OnDiskOutputBackend: write output to disk, with support for common output
15/// types, like append, or atomic update.
16/// * FilteringOutputBackend: filer some output paths to underlying output
17/// backend.
18/// * MirrorOutputBackend: mirror output to two output backends.
19///
20//===----------------------------------------------------------------------===//
21
22#ifndef LLVM_SUPPORT_VIRTUALOUTPUTBACKENDS_H
23#define LLVM_SUPPORT_VIRTUALOUTPUTBACKENDS_H
24
28
29namespace llvm::vfs {
30
31/// Create a backend that ignores all output.
32IntrusiveRefCntPtr<OutputBackend> makeNullOutputBackend();
33
34/// Make a backend where \a OutputBackend::createFile() forwards to
35/// \p UnderlyingBackend when \p Filter is true, and otherwise returns a
36/// \a NullOutput.
37IntrusiveRefCntPtr<OutputBackend> makeFilteringOutputBackend(
38 IntrusiveRefCntPtr<OutputBackend> UnderlyingBackend,
39 std::function<bool(StringRef, std::optional<OutputConfig>)> Filter);
40
41/// Create a backend that forwards \a OutputBackend::createFile() to both \p
42/// Backend1 and \p Backend2. Writing to such backend will create identical
43/// outputs using two different backends.
44IntrusiveRefCntPtr<OutputBackend>
45makeMirroringOutputBackend(IntrusiveRefCntPtr<OutputBackend> Backend1,
46 IntrusiveRefCntPtr<OutputBackend> Backend2);
47
48/// A helper class for proxying another backend, with the default
49/// implementation to forward to the underlying backend.
51 void anchor() override;
52
53protected:
54 // Require subclass to implement cloneImpl().
55 //
56 // IntrusiveRefCntPtr<OutputBackend> cloneImpl() const override;
57
59 createFileImpl(StringRef Path, std::optional<OutputConfig> Config) override {
61 if (Error E = UnderlyingBackend->createFile(Path, Config).moveInto(File))
62 return std::move(E);
63 return File.takeImpl();
64 }
65
66 OutputBackend &getUnderlyingBackend() const { return *UnderlyingBackend; }
67
68public:
70 : UnderlyingBackend(std::move(UnderlyingBackend)) {
71 assert(this->UnderlyingBackend && "Expected non-null backend");
72 }
73
74private:
75 IntrusiveRefCntPtr<OutputBackend> UnderlyingBackend;
76};
77
78/// An output backend that creates files on disk, wrapping APIs in sys::fs.
80 void anchor() override;
81
82protected:
84 return clone();
85 }
86
88 createFileImpl(StringRef Path, std::optional<OutputConfig> Config) override;
89
90public:
91 /// Resolve an absolute path.
93
94 /// On disk output settings.
96 /// Register output files to be deleted if a signal is received. Also
97 /// enabled for outputs with \a OutputConfig::getDiscardOnSignal().
98 bool RemoveOnSignal = true;
99
100 /// Use temporary files. Also enabled for outputs with \a
101 /// OutputConfig::getAtomicWrite().
102 bool UseTemporaries = true;
103
104 // Default configuration for this backend.
106 };
107
110 Clone->Settings = Settings;
111 return Clone;
112 }
113
115
116 /// Settings for this backend.
117 ///
118 /// Access is not thread-safe.
120};
121
122} // namespace llvm::vfs
123
124#endif // LLVM_SUPPORT_VIRTUALOUTPUTBACKENDS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
This file contains the declarations of the VirtualOutputBackend class, which can be used to virtualiz...
This file contains the declarations of the OutputConfig class.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Represents an open file.
IntrusiveRefCntPtr< OnDiskOutputBackend > clone() const
Expected< std::unique_ptr< OutputFileImpl > > createFileImpl(StringRef Path, std::optional< OutputConfig > Config) override
Create a file for Path.
IntrusiveRefCntPtr< OutputBackend > cloneImpl() const override
Must be thread-safe.
OutputSettings Settings
Settings for this backend.
Error makeAbsolute(SmallVectorImpl< char > &Path) const
Resolve an absolute path.
A virtualized output file that writes to a specific backend.
OutputBackend & getUnderlyingBackend() const
ProxyOutputBackend(IntrusiveRefCntPtr< OutputBackend > UnderlyingBackend)
Expected< std::unique_ptr< OutputFileImpl > > createFileImpl(StringRef Path, std::optional< OutputConfig > Config) override
Create a file for Path.
IntrusiveRefCntPtr< OutputBackend > makeNullOutputBackend()
Create a backend that ignores all output.
IntrusiveRefCntPtr< OutputBackend > makeFilteringOutputBackend(IntrusiveRefCntPtr< OutputBackend > UnderlyingBackend, std::function< bool(StringRef, std::optional< OutputConfig >)> Filter)
Make a backend where OutputBackend::createFile() forwards to UnderlyingBackend when Filter is true,...
IntrusiveRefCntPtr< OutputBackend > makeMirroringOutputBackend(IntrusiveRefCntPtr< OutputBackend > Backend1, IntrusiveRefCntPtr< OutputBackend > Backend2)
Create a backend that forwards OutputBackend::createFile() to both Backend1 and Backend2.
IntrusiveRefCntPtr< T > makeIntrusiveRefCnt(Args &&...A)
Factory function for creating intrusive ref counted pointers.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1869
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
bool RemoveOnSignal
Register output files to be deleted if a signal is received.
Full configuration for an output for use by the OutputBackend.