14#ifndef LLVM_CGDATA_CODEGENDATA_H
15#define LLVM_CGDATA_CODEGENDATA_H
33#define CG_DATA_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) Kind,
39 bool AddSegmentInfo =
true);
69 : Err(Err), Msg(ErrStr.str()) {
73 std::string
message()
const override;
87 static std::pair<cgdata_error, std::string>
take(
Error E) {
113 std::unique_ptr<OutlinedHashTree> PublishedHashTree;
115 std::unique_ptr<StableFunctionMap> PublishedStableFunctionMap;
125 static std::unique_ptr<CodeGenData> Instance;
126 static std::once_flag OnceFlag;
137 return PublishedHashTree && !PublishedHashTree->empty();
140 return PublishedStableFunctionMap && !PublishedStableFunctionMap->empty();
146 return PublishedHashTree.get();
149 return PublishedStableFunctionMap.get();
157 PublishedHashTree = std::move(HashTree);
163 PublishedStableFunctionMap = std::move(FunctionMap);
210 const Twine &CachePrefix)
213 return std::make_unique<CachedFileStream>(
214 std::make_unique<raw_svector_ostream>(
Outputs[Task]));
221 std::unique_ptr<MemoryBuffer> MB) {
222 Files[Task] = std::move(MB);
224 if (
Error Err = CGCacheOrErr.takeError())
226 Cache = std::move(*CGCacheOrErr);
233 unsigned NumOutputs =
Outputs.size();
234 auto Result = std::make_unique<SmallVector<StringRef>>(NumOutputs);
235 for (
unsigned I = 0;
I < NumOutputs; ++
I)
237 (*Result)[
I] =
Files[
I]->getBuffer();
268void warn(
Twine Message, std::string Whence =
"", std::string Hint =
"");
272namespace IndexedCGData {
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
std::string message() const override
Return the error message as a string.
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 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.
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()
void warn(Error E, StringRef Whence="")
const OutlinedHashTree * getOutlinedHashTree()
void publishStableFunctionMap(std::unique_ptr< StableFunctionMap > FunctionMap)
void saveModuleForTwoRounds(const Module &TheModule, unsigned Task, AddStreamFn AddStream)
Save TheModule before the first codegen round.
const StableFunctionMap * getStableFunctionMap()
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.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
const std::error_category & cgdata_category()
@ LLVM_MARK_AS_BITMASK_ENUM
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,...
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)