|
MLIR 22.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. | |
| virtual std::optional< SmallVector< char, 0 > > | run () |
| Runs the serialization pipeline, returning std::nullopt on error. | |
Static Public Member Functions | |
| static FailureOr< SmallString< 0 > > | translateModuleToISA (llvm::Module &llvmModule, llvm::TargetMachine &targetMachine, function_ref< InFlightDiagnostic()> emitError) |
| Translate LLVM module to textual ISA. | |
Protected Member Functions | |
| virtual void | setDataLayoutAndTriple (llvm::Module &module) |
| Hook for computing the Datalayout. | |
| virtual std::optional< SmallVector< std::unique_ptr< llvm::Module > > > | loadBitcodeFiles (llvm::Module &module) |
| Hook for loading bitcode files, returns std::nullopt on failure. | |
| virtual LogicalResult | handleBitcodeFile (llvm::Module &module) |
| Hook for performing additional actions on a loaded bitcode file. | |
| virtual void | handleModulePreLink (llvm::Module &module) |
| Hook for performing additional actions on the llvmModule pre linking. | |
| virtual void | handleModulePostLink (llvm::Module &module) |
| Hook for performing additional actions on the llvmModule post linking. | |
| virtual FailureOr< SmallVector< char, 0 > > | moduleToObject (llvm::Module &llvmModule) |
| Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode. | |
| FailureOr< llvm::TargetMachine * > | getOrCreateTargetMachine () |
| Create the target machine based on the target triple and chip. | |
| std::unique_ptr< llvm::Module > | loadBitcodeFile (llvm::LLVMContext &context, StringRef path) |
| Loads a bitcode file from path. | |
| LogicalResult | loadBitcodeFilesFromList (llvm::LLVMContext &context, ArrayRef< Attribute > librariesToLink, SmallVector< std::unique_ptr< llvm::Module > > &llvmModules, bool failureOnError=true) |
| Loads multiple bitcode files. | |
| std::unique_ptr< llvm::Module > | translateToLLVMIR (llvm::LLVMContext &llvmContext) |
| Translates the operation to LLVM IR. | |
| LogicalResult | linkFiles (llvm::Module &module, SmallVector< std::unique_ptr< llvm::Module > > &&libs) |
| Link the llvmModule to other bitcode file. | |
| virtual LogicalResult | optimizeModule (llvm::Module &module, int optL) |
| Optimize the module. | |
Protected Attributes | |
| Operation & | module |
| Module to transform to a binary object. | |
| StringRef | triple |
| Target triple. | |
| StringRef | chip |
| Target chip. | |
| StringRef | features |
| Target features. | |
| int | optLevel |
| Optimization level. | |
| function_ref< void(llvm::Module &)> | initialLlvmIRCallback |
| Callback invoked with the initial LLVM IR for the device module. | |
| function_ref< void(llvm::Module &)> | linkedLlvmIRCallback |
| Callback invoked with LLVM IR for the device module after linking the device libraries. | |
| function_ref< void(llvm::Module &)> | optimizedLlvmIRCallback |
| Callback invoked with LLVM IR for the device module after LLVM optimizations but before codegen. | |
| function_ref< void(StringRef)> | isaCallback |
| Callback invoked with the target ISA for the device, for example PTX assembly. | |
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 37 of file ModuleToObject.cpp.
References chip, features, initialLlvmIRCallback, isaCallback, linkedLlvmIRCallback, module, optimizedLlvmIRCallback, optLevel, and triple.
Referenced by mlir::NVVM::SerializeGPUModuleBase::SerializeGPUModuleBase(), mlir::ROCDL::SerializeGPUModuleBase::SerializeGPUModuleBase(), and mlir::xevm::SerializeGPUModuleBase::SerializeGPUModuleBase().
|
virtualdefault |
References mlir::emitError(), and module.
| Operation & ModuleToObject::getOperation | ( | ) |
Returns the operation being serialized.
Definition at line 51 of file ModuleToObject.cpp.
Referenced by mlir::NVVM::SerializeGPUModuleBase::appendStandardLibs(), mlir::ROCDL::SerializeGPUModuleBase::appendStandardLibs(), mlir::ROCDL::SerializeGPUModuleBase::compileToBinary(), mlir::xevm::SerializeGPUModuleBase::getGPUModuleOp(), getOrCreateTargetMachine(), linkFiles(), 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 53 of file ModuleToObject.cpp.
References chip, mlir::Operation::emitError(), features, getOperation(), target, 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 66 of file ModuleToObject.h.
References module, and success().
Referenced by loadBitcodeFile(), and loadBitcodeFilesFromList().
|
inlineprotectedvirtual |
Hook for performing additional actions on the llvmModule post linking.
Definition at line 74 of file ModuleToObject.h.
References module.
Referenced by run().
|
inlineprotectedvirtual |
Hook for performing additional actions on the llvmModule pre linking.
Reimplemented in mlir::ROCDL::SerializeGPUModuleBase.
Definition at line 71 of file ModuleToObject.h.
References module.
Referenced by run().
|
protected |
Link the llvmModule to other bitcode file.
Definition at line 149 of file ModuleToObject.cpp.
References mlir::Operation::emitError(), getOperation(), module, and success().
Referenced by run().
|
protected |
Loads a bitcode file from path.
Definition at line 76 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::NVVM::SerializeGPUModuleBase, mlir::ROCDL::SerializeGPUModuleBase, and mlir::xevm::SerializeGPUModuleBase.
Definition at line 61 of file ModuleToObject.h.
References module.
Referenced by run().
|
protected |
Loads multiple bitcode files.
Definition at line 91 of file ModuleToObject.cpp.
References mlir::Operation::emitError(), getOperation(), handleBitcodeFile(), loadBitcodeFile(), and success().
Referenced by mlir::NVVM::SerializeGPUModuleBase::loadBitcodeFiles(), mlir::ROCDL::SerializeGPUModuleBase::loadBitcodeFiles(), and mlir::xevm::SerializeGPUModuleBase::loadBitcodeFiles().
|
protectedvirtual |
Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode.
Definition at line 237 of file ModuleToObject.cpp.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), and run().
|
protectedvirtual |
Optimize the module.
Definition at line 178 of file ModuleToObject.cpp.
References mlir::Operation::emitError(), getOperation(), getOrCreateTargetMachine(), mlir::makeOptimizingTransformer(), module, optLevel, success(), and triple.
Referenced by run().
|
virtual |
Runs the serialization pipeline, returning std::nullopt on error.
Definition at line 245 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 225 of file ModuleToObject.cpp.
References getOrCreateTargetMachine(), and module.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::handleBitcodeFile(), and run().
|
static |
Translate LLVM module to textual ISA.
Definition at line 206 of file ModuleToObject.cpp.
References mlir::emitError().
Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl().
|
protected |
Translates the operation to LLVM IR.
Definition at line 144 of file ModuleToObject.cpp.
References getOperation(), and mlir::translateModuleToLLVMIR().
Referenced by run().
|
protected |
Target chip.
Definition at line 115 of file ModuleToObject.h.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::addControlVariables(), getOrCreateTargetMachine(), and ModuleToObject().
|
protected |
Target features.
Definition at line 118 of file ModuleToObject.h.
Referenced by getOrCreateTargetMachine(), and ModuleToObject().
|
protected |
Callback invoked with the initial LLVM IR for the device module.
Definition at line 124 of file ModuleToObject.h.
Referenced by ModuleToObject(), and run().
|
protected |
Callback invoked with the target ISA for the device, for example PTX assembly.
Definition at line 136 of file ModuleToObject.h.
Referenced by ModuleToObject().
|
protected |
Callback invoked with LLVM IR for the device module after linking the device libraries.
Definition at line 128 of file ModuleToObject.h.
Referenced by ModuleToObject(), and run().
|
protected |
Module to transform to a binary object.
Definition at line 109 of file ModuleToObject.h.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::addControlVariables(), handleBitcodeFile(), mlir::ROCDL::SerializeGPUModuleBase::handleBitcodeFile(), handleModulePostLink(), handleModulePreLink(), mlir::ROCDL::SerializeGPUModuleBase::handleModulePreLink(), linkFiles(), loadBitcodeFiles(), mlir::NVVM::SerializeGPUModuleBase::loadBitcodeFiles(), mlir::ROCDL::SerializeGPUModuleBase::loadBitcodeFiles(), mlir::xevm::SerializeGPUModuleBase::loadBitcodeFiles(), ModuleToObject(), optimizeModule(), mlir::NVVM::SerializeGPUModuleBase::SerializeGPUModuleBase(), mlir::ROCDL::SerializeGPUModuleBase::SerializeGPUModuleBase(), mlir::xevm::SerializeGPUModuleBase::SerializeGPUModuleBase(), setDataLayoutAndTriple(), and ~ModuleToObject().
|
protected |
Callback invoked with LLVM IR for the device module after LLVM optimizations but before codegen.
Definition at line 132 of file ModuleToObject.h.
Referenced by ModuleToObject(), and run().
|
protected |
Optimization level.
Definition at line 121 of file ModuleToObject.h.
Referenced by ModuleToObject(), optimizeModule(), and run().
|
protected |
Target triple.
Definition at line 112 of file ModuleToObject.h.
Referenced by mlir::ROCDL::SerializeGPUModuleBase::compileToBinary(), getOrCreateTargetMachine(), ModuleToObject(), mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), and optimizeModule().