14 #ifndef MLIR_TARGET_LLVM_MODULETOOBJECT_H
15 #define MLIR_TARGET_LLVM_MODULETOOBJECT_H
18 #include "llvm/IR/Module.h"
26 class ModuleTranslation;
40 virtual std::optional<SmallVector<char, 0>>
run();
49 virtual std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
67 virtual std::optional<SmallVector<char, 0>>
76 std::unique_ptr<llvm::Module>
loadBitcodeFile(llvm::LLVMContext &context,
82 SmallVector<std::unique_ptr<llvm::Module>> &llvmModules,
83 bool failureOnError =
true);
86 std::unique_ptr<llvm::Module>
98 static std::optional<std::string>
99 translateToISA(llvm::Module &llvmModule, llvm::TargetMachine &targetMachine);
120 std::unique_ptr<llvm::TargetMachine> targetMachine;
Utility base class for transforming operations into binary objects, by default it returns the seriali...
StringRef features
Target features.
std::unique_ptr< llvm::Module > translateToLLVMIR(llvm::LLVMContext &llvmContext)
Translates the operation to LLVM IR.
virtual std::optional< SmallVector< char, 0 > > run()
Runs the serialization pipeline, returning std::nullopt on error.
static std::optional< std::string > translateToISA(llvm::Module &llvmModule, llvm::TargetMachine &targetMachine)
Utility function for translating to ISA, returns std::nullopt on failure.
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.
virtual void setDataLayoutAndTriple(llvm::Module &module)
Hook for computing the Datalayout.
virtual void handleModulePreLink(llvm::Module &module)
Hook for performing additional actions on the llvmModule pre linking.
StringRef triple
Target triple.
int optLevel
Optimization level.
ModuleToObject(Operation &module, StringRef triple, StringRef chip, StringRef features={}, int optLevel=3)
virtual LogicalResult handleBitcodeFile(llvm::Module &module)
Hook for performing additional actions on a loaded bitcode file.
std::optional< llvm::TargetMachine * > getOrCreateTargetMachine()
Create the target machine based on the target triple and chip.
Operation & getOperation()
Returns the operation being serialized.
LogicalResult loadBitcodeFilesFromList(llvm::LLVMContext &context, ArrayRef< std::string > fileList, SmallVector< std::unique_ptr< llvm::Module >> &llvmModules, bool failureOnError=true)
Loads multiple bitcode files.
virtual LogicalResult optimizeModule(llvm::Module &module, int optL)
Optimize the module.
LogicalResult linkFiles(llvm::Module &module, SmallVector< std::unique_ptr< llvm::Module >> &&libs)
Link the llvmModule to other bitcode file.
virtual ~ModuleToObject()
StringRef chip
Target chip.
std::unique_ptr< llvm::Module > loadBitcodeFile(llvm::LLVMContext &context, StringRef path)
Loads a bitcode file from path.
virtual std::optional< SmallVector< std::unique_ptr< llvm::Module > > > loadBitcodeFiles(llvm::Module &module)
Hook for loading bitcode files, returns std::nullopt on failure.
virtual void handleModulePostLink(llvm::Module &module)
Hook for performing additional actions on the llvmModule post linking.
Operation & module
Module to transform to a binary object.
Operation is the basic unit of execution within MLIR.
Include the generated interface declarations.
Include the generated interface declarations.