MLIR
20.0.0git
|
Utility base class for transforming operations into binary objects, by default it returns the serialized LLVM bitcode for the module. More...
#include "mlir/Target/LLVM/ModuleToObject.h"
Public Member Functions | |
ModuleToObject (Operation &module, StringRef triple, StringRef chip, StringRef features={}, int optLevel=3, function_ref< void(llvm::Module &)> initialLlvmIRCallback={}, function_ref< void(llvm::Module &)> linkedLlvmIRCallback={}, function_ref< void(llvm::Module &)> optimizedLlvmIRCallback={}, function_ref< void(StringRef)> isaCallback={}) | |
virtual | ~ModuleToObject () |
Operation & | getOperation () |
Returns the operation being serialized. More... | |
virtual std::optional< SmallVector< char, 0 > > | run () |
Runs the serialization pipeline, returning std::nullopt on error. More... | |
Protected Member Functions | |
virtual void | setDataLayoutAndTriple (llvm::Module &module) |
Hook for computing the Datalayout. More... | |
virtual std::optional< SmallVector< std::unique_ptr< llvm::Module > > > | loadBitcodeFiles (llvm::Module &module) |
Hook for loading bitcode files, returns std::nullopt on failure. More... | |
virtual LogicalResult | handleBitcodeFile (llvm::Module &module) |
Hook for performing additional actions on a loaded bitcode file. More... | |
virtual void | handleModulePreLink (llvm::Module &module) |
Hook for performing additional actions on the llvmModule pre linking. More... | |
virtual void | handleModulePostLink (llvm::Module &module) |
Hook for performing additional actions on the llvmModule post linking. More... | |
virtual std::optional< SmallVector< char, 0 > > | moduleToObject (llvm::Module &llvmModule) |
Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode. More... | |
std::optional< llvm::TargetMachine * > | getOrCreateTargetMachine () |
Create the target machine based on the target triple and chip. More... | |
std::unique_ptr< llvm::Module > | loadBitcodeFile (llvm::LLVMContext &context, StringRef path) |
Loads a bitcode file from path. More... | |
LogicalResult | loadBitcodeFilesFromList (llvm::LLVMContext &context, ArrayRef< Attribute > librariesToLink, SmallVector< std::unique_ptr< llvm::Module >> &llvmModules, bool failureOnError=true) |
Loads multiple bitcode files. More... | |
std::unique_ptr< llvm::Module > | translateToLLVMIR (llvm::LLVMContext &llvmContext) |
Translates the operation to LLVM IR. More... | |
LogicalResult | linkFiles (llvm::Module &module, SmallVector< std::unique_ptr< llvm::Module >> &&libs) |
Link the llvmModule to other bitcode file. More... | |
virtual LogicalResult | optimizeModule (llvm::Module &module, int optL) |
Optimize the module. More... | |
Static Protected Member Functions | |
static std::optional< std::string > | translateToISA (llvm::Module &llvmModule, llvm::TargetMachine &targetMachine) |
Utility function for translating to ISA, returns std::nullopt on failure. More... | |
Protected Attributes | |
Operation & | module |
Module to transform to a binary object. More... | |
StringRef | triple |
Target triple. More... | |
StringRef | chip |
Target chip. More... | |
StringRef | features |
Target features. More... | |
int | optLevel |
Optimization level. More... | |
function_ref< void(llvm::Module &)> | initialLlvmIRCallback |
Callback invoked with the initial LLVM IR for the device module. More... | |
function_ref< void(llvm::Module &)> | linkedLlvmIRCallback |
Callback invoked with LLVM IR for the device module after linking the device libraries. More... | |
function_ref< void(llvm::Module &)> | optimizedLlvmIRCallback |
Callback invoked with LLVM IR for the device module after LLVM optimizations but before codegen. More... | |
function_ref< void(StringRef)> | isaCallback |
Callback invoked with the target ISA for the device, for example PTX assembly. More... | |
Utility base class for transforming operations into binary objects, by default it returns the serialized LLVM bitcode for the module.
The operations being transformed must be translatable into LLVM IR.
Definition at line 30 of file ModuleToObject.h.
ModuleToObject::ModuleToObject | ( | Operation & | module, |
StringRef | triple, | ||
StringRef | chip, | ||
StringRef | features = {} , |
||
int | optLevel = 3 , |
||
function_ref< void(llvm::Module &)> | initialLlvmIRCallback = {} , |
||
function_ref< void(llvm::Module &)> | linkedLlvmIRCallback = {} , |
||
function_ref< void(llvm::Module &)> | optimizedLlvmIRCallback = {} , |
||
function_ref< void(StringRef)> | isaCallback = {} |
||
) |
Definition at line 40 of file ModuleToObject.cpp.
|
virtualdefault |
Operation & ModuleToObject::getOperation | ( | ) |
Returns the operation being serialized.
Definition at line 54 of file ModuleToObject.cpp.
References module.
Referenced by mlir::NVVM::SerializeGPUModuleBase::appendStandardLibs(), mlir::ROCDL::SerializeGPUModuleBase::appendStandardLibs(), mlir::ROCDL::SerializeGPUModuleBase::assembleIsa(), mlir::ROCDL::SerializeGPUModuleBase::compileToBinary(), getOrCreateTargetMachine(), loadBitcodeFile(), loadBitcodeFilesFromList(), mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), optimizeModule(), run(), and translateToLLVMIR().
|
protected |
Create the target machine based on the target triple and chip.
This can fail if the target is not available.
Definition at line 57 of file ModuleToObject.cpp.
References chip, mlir::Operation::emitError(), features, getOperation(), and triple.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), optimizeModule(), and setDataLayoutAndTriple().
|
inlineprotectedvirtual |
Hook for performing additional actions on a loaded bitcode file.
Reimplemented in mlir::ROCDL::SerializeGPUModuleBase.
Definition at line 60 of file ModuleToObject.h.
Referenced by loadBitcodeFile(), and loadBitcodeFilesFromList().
|
inlineprotectedvirtual |
Hook for performing additional actions on the llvmModule post linking.
Definition at line 68 of file ModuleToObject.h.
Referenced by run().
|
inlineprotectedvirtual |
Hook for performing additional actions on the llvmModule pre linking.
Reimplemented in mlir::ROCDL::SerializeGPUModuleBase.
Definition at line 65 of file ModuleToObject.h.
Referenced by run().
|
protected |
Link the llvmModule to other bitcode file.
Definition at line 152 of file ModuleToObject.cpp.
References module.
Referenced by run().
|
protected |
Loads a bitcode file from path.
Definition at line 79 of file ModuleToObject.cpp.
References mlir::Operation::emitError(), getOperation(), and handleBitcodeFile().
Referenced by loadBitcodeFilesFromList().
|
inlineprotectedvirtual |
Hook for loading bitcode files, returns std::nullopt on failure.
Reimplemented in mlir::ROCDL::SerializeGPUModuleBase, and mlir::NVVM::SerializeGPUModuleBase.
Definition at line 55 of file ModuleToObject.h.
Referenced by run().
|
protected |
Loads multiple bitcode files.
Definition at line 94 of file ModuleToObject.cpp.
References mlir::Operation::emitError(), getOperation(), handleBitcodeFile(), and loadBitcodeFile().
Referenced by mlir::NVVM::SerializeGPUModuleBase::loadBitcodeFiles(), and mlir::ROCDL::SerializeGPUModuleBase::loadBitcodeFiles().
|
protectedvirtual |
Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode.
Definition at line 241 of file ModuleToObject.cpp.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), and run().
|
protectedvirtual |
Optimize the module.
Definition at line 181 of file ModuleToObject.cpp.
References mlir::Operation::emitError(), getOperation(), getOrCreateTargetMachine(), mlir::makeOptimizingTransformer(), module, optLevel, and triple.
Referenced by run().
|
virtual |
Runs the serialization pipeline, returning std::nullopt
on error.
Definition at line 249 of file ModuleToObject.cpp.
References mlir::Operation::emitError(), getOperation(), handleModulePostLink(), handleModulePreLink(), initialLlvmIRCallback, linkedLlvmIRCallback, linkFiles(), loadBitcodeFiles(), moduleToObject(), optimizedLlvmIRCallback, optimizeModule(), optLevel, setDataLayoutAndTriple(), and translateToLLVMIR().
|
protectedvirtual |
Hook for computing the Datalayout.
Definition at line 229 of file ModuleToObject.cpp.
References getOrCreateTargetMachine(), and module.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::handleBitcodeFile(), and run().
|
staticprotected |
Utility function for translating to ISA, returns std::nullopt
on failure.
Definition at line 211 of file ModuleToObject.cpp.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl().
|
protected |
Translates the operation to LLVM IR.
Definition at line 147 of file ModuleToObject.cpp.
References getOperation(), and mlir::translateModuleToLLVMIR().
Referenced by run().
|
protected |
Target chip.
Definition at line 114 of file ModuleToObject.h.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::addControlVariables(), mlir::ROCDL::SerializeGPUModuleBase::assembleIsa(), and getOrCreateTargetMachine().
|
protected |
Target features.
Definition at line 117 of file ModuleToObject.h.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::assembleIsa(), and getOrCreateTargetMachine().
|
protected |
Callback invoked with the initial LLVM IR for the device module.
Definition at line 123 of file ModuleToObject.h.
Referenced by run().
|
protected |
Callback invoked with the target ISA for the device, for example PTX assembly.
Definition at line 135 of file ModuleToObject.h.
|
protected |
Callback invoked with LLVM IR for the device module after linking the device libraries.
Definition at line 127 of file ModuleToObject.h.
Referenced by run().
|
protected |
Module to transform to a binary object.
Definition at line 108 of file ModuleToObject.h.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::addControlVariables(), getOperation(), mlir::ROCDL::SerializeGPUModuleBase::handleBitcodeFile(), mlir::ROCDL::SerializeGPUModuleBase::handleModulePreLink(), linkFiles(), mlir::NVVM::SerializeGPUModuleBase::loadBitcodeFiles(), mlir::ROCDL::SerializeGPUModuleBase::loadBitcodeFiles(), optimizeModule(), and setDataLayoutAndTriple().
|
protected |
Callback invoked with LLVM IR for the device module after LLVM optimizations but before codegen.
Definition at line 131 of file ModuleToObject.h.
Referenced by run().
|
protected |
Optimization level.
Definition at line 120 of file ModuleToObject.h.
Referenced by optimizeModule(), and run().
|
protected |
Target triple.
Definition at line 111 of file ModuleToObject.h.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::assembleIsa(), getOrCreateTargetMachine(), mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), and optimizeModule().