21#if !defined(_MSC_VER) && !defined(__MINGW32__)
31 const Twine &TempFilePrefixRef,
32 const Twine &CacheDirectoryPathRef,
38 TempFilePrefixRef.
toVector(TempFilePrefix);
39 CacheDirectoryPathRef.
toVector(CacheDirectoryPath);
59 AddBuffer(Task,
ModuleName, std::move(*MBOrErr));
75 EntryPath +
": " + EC.message() +
"\n");
85 CacheStream(std::unique_ptr<raw_pwrite_stream> OS,
AddBufferFn AddBuffer,
89 AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
106 std::error_code EC = MBOrErr.
getError();
108 TempFile.TmpName +
": " +
109 EC.message() +
"\n");
121 E = TempFile.keep(ObjectPathName);
123 std::error_code EC = E.convertToErrorCode();
126 EC,
Twine(
"Failed to rename temporary file ") +
127 TempFile.TmpName +
" to " + ObjectPathName +
": " +
128 EC.message() +
"\n");
132 MBOrErr = std::move(MBCopy);
143 AddBuffer(Task,
ModuleName, std::move(*MBOrErr));
157 MoveFileToCache(
AddBufferFn AddBuffer, std::string EntryPath,
158 std::string ModuleID,
size_t Task)
160 AddBuffer(std::move(AddBuffer)),
ModuleName(ModuleID), Task(Task) {}
161 virtual ~MoveFileToCache() =
default;
163 virtual Error commit(std::unique_ptr<MemoryBuffer> MemBuf)
override {
168 FilePath = MemBuf->getBufferIdentifier();
169 assert(!FilePath.
empty() &&
"File path is empty.");
176 std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category()))
178 if (EC == std::make_error_code(std::errc::cross_device_link))
183 FilePath +
" to " + ObjectPathName +
184 ": " + EC.message() +
"\n");
186 AddBuffer(Task,
ModuleName, std::move(MemBuf));
193 ->
Expected<std::unique_ptr<CachedFileStream>> {
197 CacheDirectoryPath,
true))
199 CacheDirectoryPath +
": " +
204 return std::make_unique<MoveFileToCache>(
205 AddBuffer, std::string(EntryPath.
str()),
ModuleName.str(), Task);
211 TempFilePrefix +
"-%%%%%%.tmp.o");
217 ": Can't get a temporary file");
220 return std::make_unique<CacheStream>(
221 std::make_unique<raw_fd_ostream>(Temp->FD,
false),
222 AddBuffer, std::move(*Temp), std::string(EntryPath),
ModuleName.str(),
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This class wraps an output stream for a file.
CachedFileStream(std::unique_ptr< raw_pwrite_stream > OS, std::string OSPath="")
virtual Error commit()
Must be called exactly once after the writes to OS have been completed but before the CachedFileStrea...
This class wraps a std::error_code in a Error.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
LLVM_ABI void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Represents a temporary file.
static LLVM_ABI Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
LLVM_ABI std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
@ OF_UpdateAtime
Force files Atime to be updated on access.
LLVM_ABI Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
LLVM_ABI file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
@ no_such_file_or_directory
std::function< void(unsigned Task, const Twine &ModuleName, std::unique_ptr< MemoryBuffer > MB)> AddBufferFn
This type defines the callback to add a pre-existing file (e.g.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI Expected< FileCache > localCache(const Twine &CacheNameRef, const Twine &TempFilePrefixRef, const Twine &CacheDirectoryPathRef, AddBufferFn AddBuffer=[](size_t Task, const Twine &ModuleName, std::unique_ptr< MemoryBuffer > MB) {}, bool CacheFileRename=false)
Create a local file system cache which uses the given cache name, temporary file prefix,...
std::function< Expected< std::unique_ptr< CachedFileStream > >( unsigned Task, const Twine &ModuleName)> AddStreamFn
This type defines the callback to add a file that is generated on the fly.
LLVM_ABI std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
void consumeError(Error Err)
Consume a Error without doing anything.
This type represents a file cache system that manages caching of files.