MLIR  19.0.0git
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
mlir::LLVM::ModuleToObject Class Reference

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"

+ Inheritance diagram for mlir::LLVM::ModuleToObject:

Public Member Functions

 ModuleToObject (Operation &module, StringRef triple, StringRef chip, StringRef features={}, int optLevel=3)
 
virtual ~ModuleToObject ()
 
OperationgetOperation ()
 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< std::string > fileList, 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

Operationmodule
 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ModuleToObject()

ModuleToObject::ModuleToObject ( Operation module,
StringRef  triple,
StringRef  chip,
StringRef  features = {},
int  optLevel = 3 
)

Definition at line 37 of file ModuleToObject.cpp.

◆ ~ModuleToObject()

ModuleToObject::~ModuleToObject ( )
virtualdefault

Member Function Documentation

◆ getOperation()

Operation & ModuleToObject::getOperation ( )

◆ getOrCreateTargetMachine()

std::optional< llvm::TargetMachine * > ModuleToObject::getOrCreateTargetMachine ( )
protected

Create the target machine based on the target triple and chip.

This can fail if the target is not available.

Definition at line 47 of file ModuleToObject.cpp.

References chip, mlir::Operation::emitError(), features, getOperation(), and triple.

Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), optimizeModule(), and setDataLayoutAndTriple().

◆ handleBitcodeFile()

virtual LogicalResult mlir::LLVM::ModuleToObject::handleBitcodeFile ( llvm::Module &  module)
inlineprotectedvirtual

Hook for performing additional actions on a loaded bitcode file.

Reimplemented in mlir::ROCDL::SerializeGPUModuleBase.

Definition at line 55 of file ModuleToObject.h.

Referenced by loadBitcodeFile().

◆ handleModulePostLink()

virtual void mlir::LLVM::ModuleToObject::handleModulePostLink ( llvm::Module &  module)
inlineprotectedvirtual

Hook for performing additional actions on the llvmModule post linking.

Definition at line 63 of file ModuleToObject.h.

Referenced by run().

◆ handleModulePreLink()

virtual void mlir::LLVM::ModuleToObject::handleModulePreLink ( llvm::Module &  module)
inlineprotectedvirtual

Hook for performing additional actions on the llvmModule pre linking.

Reimplemented in mlir::ROCDL::SerializeGPUModuleBase.

Definition at line 60 of file ModuleToObject.h.

Referenced by run().

◆ linkFiles()

LogicalResult ModuleToObject::linkFiles ( llvm::Module &  module,
SmallVector< std::unique_ptr< llvm::Module >> &&  libs 
)
protected

Link the llvmModule to other bitcode file.

Definition at line 111 of file ModuleToObject.cpp.

References module.

Referenced by run().

◆ loadBitcodeFile()

std::unique_ptr< llvm::Module > ModuleToObject::loadBitcodeFile ( llvm::LLVMContext &  context,
StringRef  path 
)
protected

Loads a bitcode file from path.

Definition at line 69 of file ModuleToObject.cpp.

References mlir::Operation::emitError(), getOperation(), and handleBitcodeFile().

Referenced by loadBitcodeFilesFromList().

◆ loadBitcodeFiles()

virtual std::optional<SmallVector<std::unique_ptr<llvm::Module> > > mlir::LLVM::ModuleToObject::loadBitcodeFiles ( llvm::Module &  module)
inlineprotectedvirtual

Hook for loading bitcode files, returns std::nullopt on failure.

Reimplemented in mlir::ROCDL::SerializeGPUModuleBase, and mlir::NVVM::SerializeGPUModuleBase.

Definition at line 50 of file ModuleToObject.h.

Referenced by run().

◆ loadBitcodeFilesFromList()

LogicalResult ModuleToObject::loadBitcodeFilesFromList ( llvm::LLVMContext &  context,
ArrayRef< std::string >  fileList,
SmallVector< std::unique_ptr< llvm::Module >> &  llvmModules,
bool  failureOnError = true 
)
protected

◆ moduleToObject()

std::optional< SmallVector< char, 0 > > ModuleToObject::moduleToObject ( llvm::Module &  llvmModule)
protectedvirtual

Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode.

Definition at line 200 of file ModuleToObject.cpp.

Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl(), and run().

◆ optimizeModule()

LogicalResult ModuleToObject::optimizeModule ( llvm::Module &  module,
int  optL 
)
protectedvirtual

◆ run()

std::optional< SmallVector< char, 0 > > ModuleToObject::run ( )
virtual

◆ setDataLayoutAndTriple()

void ModuleToObject::setDataLayoutAndTriple ( llvm::Module &  module)
protectedvirtual

Hook for computing the Datalayout.

Definition at line 188 of file ModuleToObject.cpp.

References getOrCreateTargetMachine(), and module.

Referenced by mlir::ROCDL::SerializeGPUModuleBase::handleBitcodeFile(), and run().

◆ translateToISA()

std::optional< std::string > ModuleToObject::translateToISA ( llvm::Module &  llvmModule,
llvm::TargetMachine &  targetMachine 
)
staticprotected

Utility function for translating to ISA, returns std::nullopt on failure.

Definition at line 170 of file ModuleToObject.cpp.

Referenced by mlir::ROCDL::SerializeGPUModuleBase::moduleToObjectImpl().

◆ translateToLLVMIR()

std::unique_ptr< llvm::Module > ModuleToObject::translateToLLVMIR ( llvm::LLVMContext &  llvmContext)
protected

Translates the operation to LLVM IR.

Definition at line 106 of file ModuleToObject.cpp.

References getOperation(), and mlir::translateModuleToLLVMIR().

Referenced by run().

Member Data Documentation

◆ chip

StringRef mlir::LLVM::ModuleToObject::chip
protected

◆ features

StringRef mlir::LLVM::ModuleToObject::features
protected

Target features.

Definition at line 112 of file ModuleToObject.h.

Referenced by mlir::ROCDL::SerializeGPUModuleBase::assembleIsa(), and getOrCreateTargetMachine().

◆ module

Operation& mlir::LLVM::ModuleToObject::module
protected

◆ optLevel

int mlir::LLVM::ModuleToObject::optLevel
protected

Optimization level.

Definition at line 115 of file ModuleToObject.h.

Referenced by optimizeModule(), and run().

◆ triple

StringRef mlir::LLVM::ModuleToObject::triple
protected

The documentation for this class was generated from the following files: