27 function_ref<std::unique_ptr<TargetMachine>()> TMFactory,
29 std::unique_ptr<TargetMachine>
TM = TMFactory();
30 assert(
TM &&
"Failed to create target machine!");
33 if (
TM->addPassesToEmitFile(CodeGenPasses,
OS,
nullptr, FileType))
35 CodeGenPasses.
run(*M);
41 const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
45 if (OSs.
size() == 1) {
48 codegen(&M, *OSs[0], TMFactory, FileType);
60 [&](std::unique_ptr<Module> MPart) {
68 raw_svector_ostream BCOS(BC);
69 WriteBitcodeToFile(*MPart, BCOS);
72 BCOSs[ThreadCount]->write(BC.begin(), BC.size());
73 BCOSs[ThreadCount]->flush();
78 CodegenThreadPool.
async(
81 Expected<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
82 MemoryBufferRef(StringRef(BC.data(), BC.size()),
86 report_fatal_error(
"Failed to read bitcode");
87 std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
89 codegen(MPartInCtx.get(), *ThreadOS, TMFactory, FileType);
Module.h This file contains the declarations for the Module class.
static void codegen(Module *M, llvm::raw_pwrite_stream &OS, function_ref< std::unique_ptr< TargetMachine >()> TMFactory, CodeGenFileType FileType)
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
A Module instance is used to store all the information related to an LLVM module.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
A ThreadPool for asynchronous parallel execution on a defined number of threads.
auto async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
An efficient, type-erasing, non-owning reference to a callable.
PassManager manages ModulePassManagers.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
An abstract base class for streams implementations that also support a pwrite operation.
This is an optimization pass for GlobalISel generic memory operations.
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void SplitModule(Module &M, unsigned N, function_ref< void(std::unique_ptr< Module > MPart)> ModuleCallback, bool PreserveLocals=false)
Splits the module M into N linkable partitions.
void splitCodeGen(Module &M, ArrayRef< raw_pwrite_stream * > OSs, ArrayRef< llvm::raw_pwrite_stream * > BCOSs, const std::function< std::unique_ptr< TargetMachine >()> &TMFactory, CodeGenFileType FileType=CodeGenFileType::ObjectFile, bool PreserveLocals=false)
Split M into OSs.size() partitions, and generate code for each.