14#ifndef LLVM_CGDATA_CODEGENDATA_H
15#define LLVM_CGDATA_CODEGENDATA_H
34#define CG_DATA_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) Kind,
40 bool AddSegmentInfo =
true);
70 : Err(Err), Msg(ErrStr.str()) {
71 assert(Err != cgdata_error::success &&
"Not an error");
74 std::string message()
const override;
88 static std::pair<cgdata_error, std::string>
take(
Error E) {
89 auto Err = cgdata_error::success;
92 assert(Err == cgdata_error::success &&
"Multiple errors encountered");
114 std::unique_ptr<OutlinedHashTree> PublishedHashTree;
116 std::unique_ptr<StableFunctionMap> PublishedStableFunctionMap;
126 static std::unique_ptr<CodeGenData> Instance;
127 static std::once_flag OnceFlag;
138 return PublishedHashTree && !PublishedHashTree->empty();
141 return PublishedStableFunctionMap && !PublishedStableFunctionMap->empty();
147 return PublishedHashTree.get();
150 return PublishedStableFunctionMap.get();
158 PublishedHashTree = std::move(HashTree);
164 PublishedStableFunctionMap = std::move(FunctionMap);
211 const Twine &CachePrefix)
214 return std::make_unique<CachedFileStream>(
215 std::make_unique<raw_svector_ostream>(
Outputs[Task]));
222 std::unique_ptr<MemoryBuffer> MB) {
223 Files[Task] = std::move(MB);
225 if (
Error Err = CGCacheOrErr.takeError())
227 Cache = std::move(*CGCacheOrErr);
234 unsigned NumOutputs =
Outputs.size();
235 auto Result = std::make_unique<SmallVector<StringRef>>(NumOutputs);
236 for (
unsigned I = 0;
I < NumOutputs; ++
I)
238 (*Result)[
I] =
Files[
I]->getBuffer();
273namespace IndexedCGData {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Module.h This file contains the declarations for the Module class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Represents a module in a bitcode file.
const std::string & getMessage() const
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
static std::pair< cgdata_error, std::string > take(Error E)
Consume an Error and return the raw enum value contained within it, and the optional error message.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
CGDataError(cgdata_error Err, const Twine &ErrStr=Twine())
bool hasStableFunctionMap()
const StableFunctionMap * getStableFunctionMap()
bool emitCGData()
Returns true if we should write codegen data.
void publishOutlinedHashTree(std::unique_ptr< OutlinedHashTree > HashTree)
Publish the (globally) merged or read outlined hash tree.
bool hasOutlinedHashTree()
Returns true if we have a valid outlined hash tree.
const OutlinedHashTree * getOutlinedHashTree()
Returns the outlined hash tree.
void publishStableFunctionMap(std::unique_ptr< StableFunctionMap > FunctionMap)
static LLVM_ABI CodeGenData & getInstance()
Base class for user error types.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI Expected< stable_hash > mergeCodeGenData(ArrayRef< StringRef > ObjectFiles)
Merge the codegen data from the scratch objects ObjectFiles from the first codegen round.
void publishOutlinedHashTree(std::unique_ptr< OutlinedHashTree > HashTree)
bool hasOutlinedHashTree()
bool hasStableFunctionMap()
LLVM_ABI void warn(Error E, StringRef Whence="")
const OutlinedHashTree * getOutlinedHashTree()
void publishStableFunctionMap(std::unique_ptr< StableFunctionMap > FunctionMap)
LLVM_ABI void saveModuleForTwoRounds(const Module &TheModule, unsigned Task, AddStreamFn AddStream)
Save TheModule before the first codegen round.
const StableFunctionMap * getStableFunctionMap()
LLVM_ABI std::unique_ptr< Module > loadModuleForTwoRounds(BitcodeModule &OrigModule, unsigned Task, LLVMContext &Context, ArrayRef< StringRef > IRFiles)
Load the optimized bitcode module for the second codegen round.
This is an optimization pass for GlobalISel generic memory operations.
@ StableFunctionMergingMap
@ FunctionOutlinedHashTree
std::error_code make_error_code(BitcodeError E)
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
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 void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI const std::error_category & cgdata_category()
@ LLVM_MARK_AS_BITMASK_ENUM
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) {})
Create a local file system cache which uses the given cache name, temporary file prefix,...
LLVM_ABI std::string getCodeGenDataSectionName(CGDataSectKind CGSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
This type represents a file cache system that manages caching of files.
const std::string & getCacheDirectoryPath() const
SmallVector< SmallString< 0 > > Outputs
Backing buffer for serialized data stream.
FileCache Cache
Cache mechanism for storing data.
SmallVector< std::unique_ptr< MemoryBuffer > > Files
Backing buffer for cached data.
std::unique_ptr< SmallVector< StringRef > > getResult()
Retrieve results from either the cache or the stream.
AddStreamFn AddStream
Callback function to add serialized data to the stream.
StreamCacheData(unsigned Size, const FileCache &OrigCache, const Twine &CachePrefix)